Graphics, Figures & Tablescolor package incompatible with figures?

Information and discussion about graphics, figures & tables in LaTeX documents.
danbaatar
Posts: 8
Joined: Mon Apr 26, 2010 11:14 pm

color package incompatible with figures?

Post by danbaatar »

As a test to verify that it is the color package and not something else in tikz that is producing the problem, I tried this example which also gave the same error when the second documentclass command is uncommented:

Code: Select all

\documentclass[10pt]{article}
%\documentclass{byuPhDprop}
\usepackage[usenames]{color}

\begin{document}
\begin{figure}
  \textcolor{red}{this is red}
\end{figure}
\end{document}
The error only occurs when the colored text is in a figure environment. If you remove the begin and end figure commands it compiles fine with either doccumentclass command uncommented.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

Re: color package incompatible with figures?

Post by josephwright »

Take a look in the class file: it refines \@xfloat (badly). So the question is "Do you need this class, as it seems to be broken?"
Joseph Wright
danbaatar
Posts: 8
Joined: Mon Apr 26, 2010 11:14 pm

Re: color package incompatible with figures?

Post by danbaatar »

Thanks for the help. I was looking for that redefinition, but I had opened a different, similarly named, style file in the same directory.

You ask a good question. The class has a lot of useful stuff in it, for the formatting of headings and signature pages and for making sure that the format matches the department guidelines.

Do you think that the problem with \@xfloat are fixable? I honestly don't even know enough about these low level commands to even know what it is doing and if there would be a way to get the same effect without re-defining \@xfloat.

Thanks again,
dan
josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

color package incompatible with figures?

Post by josephwright »

Okay, I think what is going on here is that the class is trying to have single spacing in floats, with double spacing elsewhere. There are a number of fixes, but for example:

Code: Select all

% Save LaTeX kernel version of \@xfloat
\makeatletter
\let\my@xfloat\@xfloat
\makeatother

\documentclass{byuPhDprop}
% Create a modified copy of \@xfloat using the kernel definition
\makeatletter
\def\@xfloat#1[#2]{
	\my@xfloat#1[#2]%
	\def\baselinestretch{1}%
	\@normalsize \normalsize
}
\makeatother

\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,automata,backgrounds}

\begin{document}
\begin{figure}[htb]
  \centering
    \begin{tikzpicture}[node distance=7mm, line/.style={>=latex}]
      \tikzstyle{vertex} = [circle,draw=black, fill=white, minimum size=10mm]
      \node[vertex] (x) at (0,0) {$x$};
    \end{tikzpicture}
\end{figure}
\end{document}
This approach leaves the class alone, and simply patches the appropriate bits in the document.
Joseph Wright
danbaatar
Posts: 8
Joined: Mon Apr 26, 2010 11:14 pm

Re: color package incompatible with figures?

Post by danbaatar »

Thanks a lot! It looks like this fixed my problem.
beytepeli
Posts: 1
Joined: Sun Sep 15, 2013 2:25 pm

color package incompatible with figures?

Post by beytepeli »

Hi Stefan,

I have the same problem with Terry and your suggestion works well for my thesis, too. Thank you very much for your suggestion written four years ago from now.
Unfortunately, what should I do if I really need this latex macro, definition of \@xfloat, in my thesis? :shock:
I have used latex for about one year, but I don't know much about macros. I can not understand these commands. Can you interpret for me whether to decide that this macro is really needed or not?

==================== quoted from .cls file ============================

Code: Select all

\def\@xfloat#1[#2]{\ifhmode \@bsphack\@floatpenalty -\@Mii\else
   \@floatpenalty-\@Miii\fi\def\@captype{#1}\ifinner
      \@parmoderr\@floatpenalty\z@
    \else\@next\@currbox\@freelist{\@tempcnta\csname ftype@#1\endcsname
       \multiply\@tempcnta\@xxxii\advance\@tempcnta\sixt@@n
       \@tfor \@tempa :=#2\do
                        {\if\@tempa h\advance\@tempcnta \@ne\fi
                         \if\@tempa t\advance\@tempcnta \tw@\fi
                         \if\@tempa b\advance\@tempcnta 4\relax\fi
                         \if\@tempa p\advance\@tempcnta 8\relax\fi
         }\global\count\@currbox\@tempcnta}\@fltovf\fi
    \global\setbox\@currbox\vbox\bgroup
    \def\baselinestretch{1}\@normalsize
    \boxmaxdepth\z@
    \hsize\columnwidth \@parboxrestore}

======================= quoted from .cls file ===========================

Yusuf
Last edited by cgnieder on Sun Sep 15, 2013 8:00 pm, edited 1 time in total.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

color package incompatible with figures?

Post by cgnieder »

Hi Yusuf,

Instead of asking new questions on threads that already are marked as solved is not a good idea. It would have been better to ask a new question instead where you could have referenced this thread.
beytepeli wrote:Can you interpret for me whether to decide that this macro is really needed or not?
The macro is a simpler redefinition of a LaTeX kernel command that determines how floating environments like {table} or {figure} behave. I can't say why the developers of your class decided to do so but if you don't encounter any problems with floats you should be safe to remove this part. You could make a local copy of the class supposedly under a new name (depends on the license of the class) where you just enclose the whole definition between \iffalse and \fi. The whole part in between will be ignored by LaTeX.

Regards
site moderator & package author
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

color package incompatible with figures?

Post by sommerfee »

beytepeli wrote:Can you interpret for me whether to decide that this macro is really needed or not?
When comparing this redefinition with the original definition of LaTeX 2.09 and LaTeX2e one see that this re-definition is actually based on the 2.09 definition of \@xfloat. So dropping it seems like a very good idea to me.

The only custom stuff I can find within this re-definition is

Code: Select all

\def\baselinestretch{1}
which turns on single spacing within floating environments automatically.

The same effect can be archived using the setspace package.
ElMacho
Posts: 1
Joined: Sat Dec 20, 2014 9:13 pm

Re: color package incompatible with figures?

Post by ElMacho »

I just want to share a HUGE thank you with everyone involved in this thread. This issue has caused a considerable headache for me and I'm very grateful for the solution.
sardaraqib
Posts: 1
Joined: Sun Jul 28, 2024 12:06 pm

color package incompatible with figures?

Post by sardaraqib »

I had the same issue, which was resolved by deleting the \@xfloat from my .sty file. Thank you so much.
Post Reply