Monday, May 14, 2007

Subfigures in LaTeX

There is a "new" package in LaTeX that is called subfig, which handles multiple figures all lined up nice and clean. Before there was the subfigure
package but that is no longer in development and is being replaced by subfig.
The only difference is that instead of saying something like

\begin{figure}
\mbox{
\subfigure{\includegraphics}
}
\end{figure}

you say

\begin{figure}
\mbox{
\subfloat{\includegraphics}
}
\end{figure}

and notice that the two brackets there don't have to be but it gets pretty ugly if their not, they represent the text that comes in the List-Of-Floats (LOF) and the caption to the file respectively. If only one [] pair is given with text in them then that is the caption to the figure and that text also appears in the LOF, if two brackets are given then the first one will be the LOF (if empty then nothing is printed in the LOF.)

Notice allso that the subfig package calls the caption package I talked about earlyer so defining the caption package again in the preamble will cause an error. Use the \captionsetup command instead to set the caption options.

So to put up 4 figures in a 2x2 formation you would do something like this:

\begin{figure}[htbp]
\begin{center}
\mbox{
\subfloat[][caption1]{\epsfig{figure=figure1.eps}}\quad
\subfloat[][caption2]{\epsfig{figure=figure2.eps}}
}
\mbox{
\subfloat[][caption3]{\epsfig{figure=figure3.eps}}\quad
\subfloat[][caption4]{\epsfig{figure=figure4.eps}}
}
}

Read the subfig.pdf file in the ctan directory for this package for more information.

No comments: