# Should two pictures side by side have 0.5 or 0.49999 textwidth?

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?

Should

\includegraphics[width=0.5\textwidth]


be used or better something like

\includegraphics[width=0.4999\textwidth]


in this example:

\begin{figure}[h]
\centering
\subfloat[]{\label{a} \includegraphics[width=0.5\textwidth]{a.jpg}}
\subfloat[]{\label{b} \includegraphics[width=0.5\textwidth]{b.jpg}}
\label{fig:abpics}
\caption{The a and the b.}
\end{figure}

-
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 ... ? –  tohecz 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

Let's examine your example with care.

\begin{figure}[h]


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

  \centering


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.

  \label{fig:abpics}


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

\end{figure}


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.

-
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. –  cgnieder Dec 10 '12 at 18:45
@cgnieder Thanks! I wasn't looking for that! –  egreg Dec 10 '12 at 19:06
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.9525144100189209, "perplexity": 3160.312177789333}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 5, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2014-15/segments/1397609536300.49/warc/CC-MAIN-20140416005216-00010-ip-10-147-4-33.ec2.internal.warc.gz"}