1

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?

  • Between the two subfigures you have a normal space (the end-of-line after \end{minipage}) and 14pt. Remove \hspace*{14pt} and put \hfill after \end{minipage} (same line, no space in between). By the way you should use \raggedright, not \flushleft. – egreg Mar 15 '16 at 22:03
  • please don't edit the question to ask a completely different question, it makes the existing answers impossible to understand, best to ask a new question, but the normal thing to do is use \centering for captions but yours appear to be flush left, probably due to code you have not shown. It is always best to post complete documents that show the issue (use \includegraphics[]{example-image} which is an image in most distributions, to make your example portable. – David Carlisle Mar 15 '16 at 23:36
  • The caption package has justification=raggedright and justification=raggedleft options. You can call \captionsetup inside each minipage. – John Kormylo Mar 16 '16 at 2:38
2

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.

1

You haven't posted enough information to completely diagnose the problem but

\begin{minipage}[b]{0.49\textwidth}
\end{minipage}
\hspace*{14pt}% separation between the subfigures
\begin{minipage}{0.49\textwidth}
\end{minipage}

is a line .98\textwidth + 1 word space + 14pt wide so that may or may not be wider than \textwidth.

Perhaps you want

\begin{minipage}[b]{0.49\textwidth}
\end{minipage}\hfill 
\begin{minipage}{0.49\textwidth}
\end{minipage}

which will have exactly .02\textwidth space between the minipages, with a total line width of exactly \textwidth.

  • Thanks a lot for your fast comments and the explanation! I think there was a big error in reasoning ;-) I have tried your suggestions already and edited my post above with a new question. – Milou Mar 15 '16 at 23:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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