3

Sometimes I use a figure numbering style in which each number is placed to the left of a figure. When using this formatting, I try to make sure that the space occupied by a given number and figure is confined by the same margins as those set for the main text. This creates a nice alignment effect. I have tried to achieve it in LaTeX by using two minipage environments inside a figure environment and some simple mathematics:

\begin{figure}[htp]
\begin{minipage}{\1cm}
{\Large(3)}
\end{minipage}%
\newlength{\pic}
\setlength{\pic}{\columnwidth}
\addtolength{\pic}{-\1cm}
\begin{minipage}{\pic}
\includegraphics[width=\pic]{blue}
\caption{Caption}
\label{blue}
\end{minipage}%
\end{figure}

This code, however, didn't work quite as I expected: as you can see in the picture below, the figure sticks out onto the right margin.

Figure

How can I ensure that the figure fills up the space next to the number while being neatly aligned with the body of the text?

(Incidentally, I would also be very grateful for some suggestions on how to make the number and the picture aligned at the top.)

2

This is caused by spurious spaces in your code. Line endings are taken as spaces which add a little bit more distance between the minipages. Simply place % at the lines ending with } or {. Alternatively place an \unskip direct before the second minipage. The following code should work:

\begin{figure}[htp]
  \begin{minipage}{1cm}
    {\Large(3)}
  \end{minipage}%
  \newlength{\pic}%   % should be in the preamble!
  \setlength{\pic}{\columnwidth}%
  \addtolength{\pic}{-1cm}%
  \begin{minipage}{\pic}
    \includegraphics[width=\pic]{blue}%
    \caption{Caption}
    \label{blue}
  \end{minipage}%
\end{figure}

You can also write it a little simpler by using \dimexpr (introduced by eTeX):

\begin{figure}[htp]
  \begin{minipage}{1cm}
    {\Large(3)}
  \end{minipage}%
  \begin{minipage}{\dimexpr\columnwidth-1cm\relax}
    \includegraphics[width=\textwidth]{blue}%
    \caption{Caption}
    \label{blue}
  \end{minipage}%
\end{figure}

Note that inside a minipage the \textwidth refers to the minipage width.

  • @Marin Scharrer It works like a charm, thank you so much! In fact, I experimented with % before but obviously didn't put enough percent signs ;) And I'm sorry about the sloppy code. – jemp Jul 1 '11 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.