[Tex/LaTex] Overfull \hbox warning – two plots side-by-side

minipagepsfragsubfloats

I am trying to create an environment for plotting two figures side-by-side:

    \begin{figure}[t] 
        \begin{minipage}[b]{0.49\textwidth}
            \flushleft
                \psfragfig[frame,mode=nonstop]{Plot_random_Breite_05_1}
                    \caption{Figur Nr. 8a} 
                    \label{fig:8a}
        \end{minipage}
\hspace*{14pt}% separation between the subfigures
        \begin{minipage}[b]{0.49\textwidth}
            \flushleft
                \psfragfig[frame,mode=nonstop]{Plot_random_Breite_05_2}
                    \caption{Figur Nr. 8b} 
                     \label{fig:8b}
        \end{minipage}
    \end{figure}

The output looks like this:
enter image description here

Unfortunately I get an "Overfull hbox" warning.

I tried several things to remove this warning:

  • remove \hspace
  • smaller width (0.4\textwidth)
  • \linewidth instead of \textwidth
  • subfigure instead of minipage

Nothing helped. The plot is not scaled, the textwidth is about 9cm and the size of the plot is about 3cm.

Has someone an idea? Can't figure out where the bug is -.-

If I use \hfill as recommended below, my code and the output look like this:

\begin{figure}[t] 
    \begin{minipage}[b]{0.49\textwidth}
        \raggedright
            \psfragfig[frame,mode=nonstop]{Plot_random_Breite_05_1}
                \caption{Figur Nr. 8a} 
                \label{fig:8a}
    \end{minipage}\hfill
     \begin{minipage}[b]{0.49\textwidth}
        \raggedleft
            \psfragfig[frame,mode=nonstop]{Plot_random_Breite_05_2}
                \caption{Figur Nr. 8b} 
                 \label{fig:8b}
    \end{minipage}
\end{figure}

enter image description here

As you can see I would prefer, if both picture align with the margins.

Is there a way to align the second caption with the frame of the plot?

Best Answer

The construction on the line that contains your two sub-figures consist of elements that have the following widths:

  1. A minipage of width 0.49\textwidth;

  2. An inter-word space between the first minipage and the \hspace*;

  3. A hard space of 14pt;

  4. A minipage of width 0.49\textwidth.

The above combination is wider than \textwidth, obviously, as is indicated by the first construction below (I'm using \rule instead of minipage, but the effect is the same):

enter image description here

\documentclass{article}

\begin{document}

\begin{figure}
  X \dotfill X% For reference

  \rule{0.49\textwidth}{1pt}
  \hspace*{14pt}% Separation between sub-figures
  \rule{0.49\textwidth}{1pt}

  \rule{\dimexpr0.5\textwidth-7pt}{1pt}%
  \hspace*{14pt}% Separation between sub-figures
  \rule{\dimexpr0.5\textwidth-7pt}{1pt}

  \rule{0.49\textwidth}{1pt}
  \hfill% Flexible fill between sub-figures
  \rule{0.49\textwidth}{1pt}

  X \dotfill X% For reference
\end{figure}

\end{document}

If you're stuck on having the fixed 14pt gap between the two sub-figures, then you need to make sure that each component is exactly split between the remainder. That is, each image (or minipage) takes up 0.5\textwidth-7pt. That's what the second construction achieves.

Note the use of % sign after the first sub-figure in order to avoid the inter-word space that is naturally inserted after a macro with an argument.


Alternatively, if you're interested in fixing the width of the sub-figures (rather than the 14pt gap mentioned above), then you can insert a flexible fill using \hfill.