TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Two pictures should be next to each other. What is their perfect width? Is 0.5 + 0.5 = 1 for TeX, or does the compiler need a tiny space between the objects?



be used or better something like


in this example:

  \subfloat[]{\label{a} \includegraphics[width=0.5\textwidth]{a.jpg}}
  \subfloat[]{\label{b} \includegraphics[width=0.5\textwidth]{b.jpg}}
  \caption{The a and the b.}
share|improve this question
TeX is really accurate considering dimesions, but wouldn't be nicer to have some small gap in between, like ... 0.47\textwidth ... \hfill ... \0.47\textwidth ... ? – yo' Dec 10 '12 at 18:15
The sum of the widths in the example is larger than \textwidth, because of the space after the first \subfloat. Put % next to the end: a.jpg}}% and LaTeX will happily put the two objects on one line. – egreg Dec 10 '12 at 18:15
I tried \subfloat[]{\label{a} \includegraphics[width=0.49\textwidth]{a.jpg}}% \hfill% \subfloat[]{\label{b} \includegraphics[width=0.49\textwidth]{b.jpg}} but that makes a newline between the pictures – Jonas Stein Dec 10 '12 at 18:21
I usually give the figures a width close to (but less than) 0.5\textwidth, and put a \hfill between figures. This space expands to the required amount o align he outer edges of the figures with the page margins. – JLDiaz Dec 10 '12 at 18:22
@JonasStein perhaps the space between \label and \includegraphics? – JLDiaz Dec 10 '12 at 18:23
up vote 20 down vote accepted

Let's examine your example with care.


You're starting a figure environment. Error: [h] should be [htp] or something.


You want to center everything. In particular, there's no indentation at the start of the paragraphs.

  \subfloat[]{\label{a} \includegraphics[width=0.5\textwidth]{a.jpg}}
  \subfloat[]{\label{b} \includegraphics[width=0.5\textwidth]{b.jpg}}

These make a paragraph (boxes, as far as TeX is concerned, are just like big characters). You have an object 0.5\textwidth wide, a space and another 0.5\textwidth wide object. This makes impossible for TeX to use only one line for the paragraph. Just add a %:

  \subfloat[]{\label{a} \includegraphics[width=0.5\textwidth]{a.jpg}}%
  \subfloat[]{\label{b} \includegraphics[width=0.5\textwidth]{b.jpg}}

and the space will not be there. The width is equal to the \textwidth (with possible tiny errors due to the truncation of fractional numbers, where 1+1 is not always 2); if the error is by defect (of 2sp at most, which is 1/65536 of 1pt) the \centering declaration will add the necessary padding; if the error is by excess, the \hfuzz parameter usually is 0.1pt, which is way bigger than 2sp and no Overfull \hbox message will appear. Thus in both cases the two subfloats will appear next to each other. On the contrary, a space is usually larger than 0.1pt, thus making it impossible to set only one line.

  \caption{The a and the b.}

This makes an object independent of the above paragraph, which is terminated and typeset; then the \caption is typeset and all actions related to it are performed; it doesn't start a paragraph.


The \label contributes nothing and doesn't start a paragraph; the final space is removed anyway.


The environment ends. Notice that \label should go after \caption in order to refer correctly to the generated number (thanks to cgnieder for remarking it).

In very rare cases, one might be bitten by the fact that 1+1 is not necessarily 2, when truncation of fractional numbers happens. The example is

\hbox to 2in{\hskip1in\hskip1in}

that results in an Underfull \hbox because the binary arithmetic used by TeX (that truncates possible fractional parts) makes 1in + 1in less than 2in by exactly 1sp. Nothing to be worried about in normal situations.

share|improve this answer
The \label should be placed after \caption, though. Also the blank between \label{a} and \includegraphics (and similar in the second subfloat) is not discarded. – clemens Dec 10 '12 at 18:45
@cgnieder Thanks! I wasn't looking for that! – egreg Dec 10 '12 at 19:06

Your Answer


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.