GeneralIssue w/ Multiple Figures Using \minipage - Odd captioning

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
jw5801
Posts: 4
Joined: Sat Oct 04, 2008 2:25 pm

Issue w/ Multiple Figures Using \minipage - Odd captioning

Post by jw5801 »

I'm attempting to create two side-by-side figures with their own captions using:

Code: Select all

\begin{figure}[htbp]
  \begin{minipage}[b]{0.48\linewidth}
    \includegraphics[width=60mm]{images/image1.jpg}
    \caption{Image 1}
  \end{minipage}
  \hfill
  \begin{minipage}[b]{0.48\linewidth}
    \includegraphics[width=60mm]{images/image2.jpg}
    \caption{Image 2}
  \end{minipage}
\end{figure}
However this is resulting in only the second caption appearing under the first image, and the first caption not appearing at all, although both appear in the list of figures. I'm at a loss as to why this would be happening, if I don't include the second caption, the first caption is displayed fine underneath the first image, but it appears as though the second caption is somehow overwriting the first.

Recommended reading 2024:

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

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

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Issue w/ Multiple Figures Using \minipage - Odd captioning

Post by gmedina »

Hi,

instead of \caption that can only be used inside floating environments, use the \captionof command provided by the caption package ; i.e., use something like the following:

Code: Select all

...
\captionof{figure}{Image 1}
...
\captionof{figure}{Image 2}
...
Of course, you have to load the caption package: in the preamble:

Code: Select all

\usepackage{caption}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
jw5801
Posts: 4
Joined: Sat Oct 04, 2008 2:25 pm

Issue w/ Multiple Figures Using \minipage - Odd captioning

Post by jw5801 »

Thanks for the reply. Attempting to use \captionof throws me an odd error about incorrect \prevdepth:

Code: Select all

...
<images/batteries.jpg, id=224, 2601.72pt x 1951.29pt>
<use images/batteries.jpg>
! Improper \prevdepth.
<recently read> \prevdepth 
                           
l.7     \captionof{figure}{Image 1}
Have I got a bad version of the caption package, or could something else be wrong?
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Issue w/ Multiple Figures Using \minipage - Odd captioning

Post by gmedina »

Hi,

a complete modified version of your previous code should look something like the following:

Code: Select all

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}

\begin{document}

\noindent\begin{minipage}[b]{0.46\textwidth}
  \centering
  \includegraphics[width=60mm]{images/image1.jpg}
  \captionof{figure}{Image 1}
  \label{fig:figure1}
\end{minipage}
\hfill
\begin{minipage}[b]{0.48\linewidth}
  \centering
  \includegraphics[width=60mm]{images/image2.jpg}
  \captionof{figure}{Image 2}
  \label{fig:figure2}
\end{minipage}

\end{document}
Do you get any errors when you compile the above code? If so, please add

Code: Select all

\listfiles
before the \documentclass{article} line, compile the document and attach the .log file obtained.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

Issue w/ Multiple Figures Using \minipage - Odd captioning

Post by sommerfee »

jw5801 wrote:However this is resulting in only the second caption appearing under the first image, and the first caption not appearing at all, although both appear in the list of figures.
Then you have redefined the figure environment somewhere in your document. I assume you are using the float package and have the line \restylefloat{figure} in your document. If this is true, please read the documentation of the float package properly and you'll see that the above behaviour is totally correct in terms of the float package. If you don't know why you have \restylefloat{figure} in your document (because you started with a document scheme you got elsewhere), just remove it and this will solve your problem immediately. (And if there is a \restylefloat{table} as well, removed it, too.)
Attempting to use \captionof throws me an odd error about incorrect \prevdepth
It seems you have either a very early version of the caption package 3.0 or 3.1. (Please take a look at your log file.) Updating the caption package should help here. If not I'm very interested in getting a complete LaTeX document which shows the problem, so I can examine and solve the problem.

Axel
jw5801
Posts: 4
Joined: Sat Oct 04, 2008 2:25 pm

Issue w/ Multiple Figures Using \minipage - Odd captioning

Post by jw5801 »

Ok, it builds excellently in isolation (probably should have tested that myself, apologies). So a bit of trial and error shows that the hyperref package appeared to be conflicting. Commenting out where I'd called it enables me to compile the document fine, leaving it in causes the `Improper \prevdepth' error. That's probably because I only have version 3.0 of the caption package. The later suggestion solved my issue however so no need to update it!

Code: Select all

(/usr/share/texmf-texlive/tex/latex/caption/caption.sty
Package: caption 2007/01/07 v3.0k Customising captions (AR)

(/usr/share/texmf-texlive/tex/latex/caption/caption3.sty
Package: caption3 2007/01/07 v3.0k caption3 kernel (AR)
\captionmargin=\dimen126
\captionmarginx=\dimen127
\captionwidth=\dimen128
\captionindent=\dimen129
\captionparindent=\dimen130
\captionhangindent=\dimen131
) 
Removing \restylefloat{figure} fixed the issue, and I'm back to using regular \caption. I had \restylefloat{figure} in my preamble as I was lead to believe that it was necessary in order to use the `H' location specifier. This assumption does now appear to be incorrect, so I have removed the line and all is good and right again.

Thanks very much!
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

Issue w/ Multiple Figures Using \minipage - Odd captioning

Post by sommerfee »

jw5801 wrote:So a bit of trial and error shows that the hyperref package appeared to be conflicting. Commenting out where I'd called it enables me to compile the document fine, leaving it in causes the `Improper \prevdepth' error.
So it seems that the combination of caption v3.0k, hyperref and float package has caused this problem. I'm not aware of such problem, but I hope it's fixed in the actual version 3.1 of the caption package which has a completely revised hyperref support.
I had \restylefloat{figure} in my preamble as I was lead to believe that it was necessary in order to use the `H' location specifier. This assumption does now appear to be incorrect, so I have removed the line and all is good and right again.
Yes, this assumption is incorrect, just loading the float package is totally sufficient for using the "H" location specifier. I use to call this the "restylefloat virus" because it's out of my understanding why such a wrong information is spread so much. AFAIK there is no sentence in the float package manual which could lead to this misunderstanding.

Axel
jw5801
Posts: 4
Joined: Sat Oct 04, 2008 2:25 pm

Issue w/ Multiple Figures Using \minipage - Odd captioning

Post by jw5801 »

sommerfee wrote:So it seems that the combination of caption v3.0k, hyperref and float package has caused this problem. I'm not aware of such problem, but I hope it's fixed in the actual version 3.1 of the caption package which has a completely revised hyperref support.
It would appear so yes! If I get a chance I'll upgrade my version of the caption package and see what happens.
Yes, this assumption is incorrect, just loading the float package is totally sufficient for using the "H" location specifier. I use to call this the "restylefloat virus" because it's out of my understanding why such a wrong information is spread so much. AFAIK there is no sentence in the float package manual which could lead to this misunderstanding.
I read it in some documentation about the fancyhdr package (see page 23). Which seems to be a fairly reputable source, even if it is a bit dated.
Post Reply