3

I was going through some crazy hoops to get minipage and subfloat work nicely (?) together, only to find out in the very end that I screwed up the figure references.

I have a figure with two subfloats, one on the left one on the right. The left is composed of two graphics above one another. That last fact causes big trouble because I cannot use \\ or \newline in subfloat alone. So I build a minipage around it, but then the subfloat cannot contain the minipage, so I reversed their nesting:

\documentclass[a4paper]{book}
% note: the following packages are _givens_, I cannot change them at this point
\usepackage[top=35mm, bottom=38mm, inner=40mm, outer=24mm]{geometry}
\usepackage[hang,small]{caption}
\usepackage{subfig}
\usepackage{graphicx}

\begin{document}

As shown in Fig.~\ref{fig:right}...

\begin{figure} \centering \begin{minipage}{0.39\textwidth}% \includegraphics[width=1\textwidth, trim=0 0 0 -70mm]{figures/zelle148_IMG_1903m.jpg}\[2mm]% \includegraphics[width=1\textwidth, trim=0 -60mm 0 0]{figures/zelle148_IMG_1901m.jpg}% \\centering \subfloat[Left]{\hspace{0.9\textwidth}}\label{fig:left} \end{minipage}% \begin{minipage}{0.58\textwidth}% \includegraphics[width=1\textwidth, trim=-2mm 0 0 0]{figures/Zelle148ScoreCut.pdf}% \\centering \subfloat[Right]{\hspace{1\textwidth}}\label{fig:right} \end{minipage}% \caption{Full caption} \label{fig:both} \end{figure}

\end{document}

The problem is, I get errors

Package caption Warning: \label before \caption on input line 20.

LaTeX Warning: Reference `fig:right' on page 1 undefined on input line 9.

LaTeX Warning: There were undefined references.

The figure result looks as I want:

enter image description here

But the reference in the text just shows up as "??" instead of "1b".

Emit Taste
  • 4,404
  • I tried to replace subfig with subcaption which I read is recommended. I didn't disturb the rest of the thesis I have formatted so far, so I'm ok to make this change if it helps. – Emit Taste Nov 01 '13 at 12:11

2 Answers2

5

Does the following fulfill your purpose? It comes without any trim or anything like that. The basic idea here is to create a two column table, both columns centered. The left column is again a single column table with two rows, where you put your Left pictures one above another. The right column is again a table, with only one row, which contains your Right picture. You align the last two tables at bottom. You will want to tweak the column widths. Here I have used 0.4\textwidth, but slightly wider should also be alright.

\documentclass[a4paper]{book}
\usepackage[top=35mm, bottom=38mm, inner=40mm, outer=24mm]{geometry}
\usepackage[hang,small]{caption}
\usepackage{subfig}
\usepackage{graphicx}

\begin{document}

As shown in Fig.~\ref{fig:right}...

\begin{figure}[!tbp]
  \centering
  \begin{tabular}[c]{cc}
    \subfloat[Left]{\label{fig:left}%
      \begin{tabular}[b]{c}
        \includegraphics[width=0.4\textwidth]{figures/zelle148_IMG_1903m.jpg}\\[2mm]
        \includegraphics[width=0.4\textwidth]{figures/zelle148_IMG_1901m.jpg}
      \end{tabular}}
    &
    \begin{tabular}[b]{c}
      \subfloat[Right]{\label{fig:right}%
        \includegraphics[width=0.4\textwidth]{figures/Zelle148ScoreCut.pdf}}
    \end{tabular}
  \end{tabular}
  \caption{Full caption}
  \label{fig:both}
\end{figure}

\end{document}

Here is the output,

enter image description here

Masroor
  • 17,842
  • Thanks, that works fine, too. Didn't know you can put tabular inside subfloat when you can't put minipage there. – Emit Taste Nov 01 '13 at 21:44
0

Using subcaption indeed seems to solve my problem. I kind of combines minipage and subfloat:

\documentclass[a4paper]{book}
\usepackage[top=35mm, bottom=38mm, inner=40mm, outer=24mm]{geometry}
\usepackage[hang,small]{caption}
\usepackage{subcaption} % !!!
\usepackage{graphicx}

\begin{document}

As shown in Fig.~\ref{fig:right}...

\begin{figure}
\centering 
\begin{subfigure}{0.39\textwidth}
\centering
\includegraphics[width=1\textwidth, trim=0 0 0 -70mm]{figures/zelle148_IMG_1903m.jpg}\\[2mm]%
\includegraphics[width=1\textwidth, trim=0 -60mm 0 0]{figures/zelle148_IMG_1901m.jpg}%
\caption{Left}\label{fig:left}
\end{subfigure}
\begin{subfigure}{0.58\textwidth}
\centering
\includegraphics[width=1\textwidth, trim=-2mm 0 0 0]{figures/Zelle148ScoreCut.pdf}%
\caption{Right}\label{fig:right}
\end{subfigure}
\caption{Full caption}
\label{fig:both}
\end{figure}

\end{document}

Does anyone have a better solution than using negative trim hackery to achieve the vertical centering of left and right side, while keeping sub captions on the same vertical position?

Emit Taste
  • 4,404