Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.)

share|improve this question
    
Welcome to TeX.sx! –  Martin Scharrer Jul 1 '11 at 19:24
    
Also check out Is there a way to measure the remaining space of a line of text? for the automatic measuring of the remaining space. –  Martin Scharrer Jul 1 '11 at 19:26

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
@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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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