2

Which width, instead of \textwidth (as suggested here), can I use here to avoid getting an "Overfull \hbox" warning? I expect it's the page width minus margins.

\documentclass[twocolumn, draft]{article}
\usepackage{subfig}
\usepackage{graphicx}

\begin{document}
\begin{figure*}
    \begin{center}
        \subfloat %[] if you want labeled subfigures.
        {
            \includegraphics[width=0.5\textwidth]{example-image-a}
        }
        \subfloat
        {
            \includegraphics[width=0.5\textwidth]{example-image-a}
        }
    \end{center}
    \caption{Your caption here}
\end{figure*}

\end{document}

Gives

Overfull \hbox (13.33331pt too wide) in paragraph at lines 11--16

[][] |

pdflatex output

Using four subfigures results in "Overfull \hbox (26.66663pt too wide)", by the way.

Gus
  • 1,217
  • Ideally I would find a solution that would let me avoid guessing at using .24 or .485. – Gus Jun 30 '19 at 00:11
  • Well, that would depend on the used code (is there a defined separator value or not, did you use hfill or not) and at last on the used images and their sizes ... That makes it not easy or propably impossible to find a formula to handle this in an automatic way ... – Mensch Jun 30 '19 at 17:27

1 Answers1

6

The culprit here is not \textwidth, it is your factor 0.5 which results in an total length for both images as 0.5\textwidth+ separator length + 0.5\textwidth > \textwidth. That results in your overful box.

Just play with the factor, use for example 0.485 as shown in the following mwe (I added package showframe to visualize typing area and margins):

\documentclass[twocolumn]{article}

\usepackage{subfig}
\usepackage{graphicx}

\usepackage{showframe} % <============= to visiualize typing area and margins

\begin{document}
\begin{figure*}
  \centering
  \subfloat %[] if you want labeled subfigures.
  {%
    \includegraphics[width=0.485\textwidth]{example-image-a}
  }%
  \subfloat
  {%
    \includegraphics[width=0.485\textwidth]{example-image-b}
  }%
  \caption{Your caption here}
\end{figure*}

\end{document}

and the result:

resulting figure

BTW: Because you are using environment figure* you can use \textwidth, because figure* spans both columns. If you use figure your figure is placed in one column and you should use \columnwidth. Please see the expanded mwe

\documentclass[twocolumn]{article}

\usepackage{subfig}
\usepackage{graphicx}

\usepackage{showframe} % <============= to visiualize typing area and margins
\usepackage{blindtext}

\begin{document}
\begin{figure*}
  \centering
  \subfloat %[] if you want labeled subfigures.
  {%
    \includegraphics[width=0.485\textwidth]{example-image-a}
  }%
  \subfloat
  {%
    \includegraphics[width=0.485\textwidth]{example-image-b}
  }%
  \caption{Your caption here}
\end{figure*}

\Blindtext

\begin{figure}[!hb]
  \includegraphics[width=\columnwidth]{example-image-c}
\end{figure}

\Blindtext

\end{document}

and the result:

resulting figures

Mensch
  • 65,388
  • Thanks for this information. At a high level, I want to, say, put four subfigures in a row, so semantically, they should each take up a 1/4 of the width. Yes, there will be three separators, but I would hope to still specify that four of them should fit snuggly, regardless of the separator (and even if the separator width gets redefined). – Gus Jun 15 '19 at 02:43
  • @Gus You can try with four times \subfloat{\includegraphics[width=0.24\textwidth]{example-image-a}}% – Mensch Jun 15 '19 at 02:57