# How to place two figures next to each other and centered

How can I position two graphs next to each other so that it looks good? For putting two figures next to each other I found the solution below in another question around here, however, I would like both figures to be shifted a bit to the left so that they stick out both on the left and right side of the text line equally instead of only on the right side.

Also, what would be the best way to horizontally align the two figures? All I could figure out is making the caption of the left figure longer than that of the right figure so that it pushes up the graph.

Here's my code:

  \begin{figure}[!tbp]
\centering
\begin{minipage}[b]{0.4\textwidth}
\scalebox{.9}{\input{./graf/LVQ.tex}}
\caption{Caption Figure 4}
\end{minipage}
\hfill
\begin{minipage}[b]{0.4\textwidth}
\scalebox{.55}{\input{./graf/baselinererun.tex}}
\caption{Caption Figure 5}
\end{minipage}
\end{figure}

• Welcome to TeX SE! please post a complete minimal working example (MWE) that demonstrates your problem which starts with \begin{document} ... and ends with \end{document}. This way, people here can reproduce the situation and try to help you. Besides, when you copy and modify text from a source, you should cite it properly to provide complete information. – AboAmmar Jul 7 '15 at 1:25
• part of the problem might be how you generate the graphs - I would make sure the fonts & axes lengths are the same size in both to begin with ( see legend seems to push the 2nd graph downwards - perhaps relocate it) – prettygully Jul 7 '15 at 2:16
• Yes, I am becoming desperate trying to somehow set up gnuplot for consistent output in with the latex terminal. The thing is I only have the .tex file for the left plot, while I generated the right one myself. The left plot is 1000 times 700 pixels wide, while my gnuplot makes it 1500 times 900. It seems that you can only set the output size in inches with the latex terminal, so maybe I have to find out how many inches correspond to 1000 pixels. But then also the axes are not consistent, I have no idea how to make them, although I managed to make the the axes ranges the same: [0,1] and [0,150] – Malo Jul 7 '15 at 13:24

Many options are available for placing two figures side-by-side. See this question and the answers therein, for example.

Here is a solution using the the subfig package:

\documentclass[12pt,a4paper]{article}
\usepackage[demo]{graphicx}
\usepackage[margin=1in,showframe]{geometry}

\usepackage{subfig}
\renewcommand{\thesubfigure}{Figure \arabic{subfigure}}
\captionsetup[subfigure]{labelformat=simple, labelsep=colon}
\begin{document}

\begin{figure}[!tbp]
\makebox[\textwidth][c]{%
\subfloat[Caption Figure 1]{\scalebox{1.7}{\includegraphics{fig4}}\label{fig:f4}}
\subfloat[Caption of Figure 2 which should be so long to se if the two captions are not equal in length]{\scalebox{1.7}{\includegraphics{fig5}}\label{fig:f5}}
}
\end{figure}

\end{document}


## Details

First of all make sure the figures use the same font size, line widths, etc. as pointed out by @prettygully in a comment to see the solution work.

I used the [demo] option for graphicx to insert wide enough dummy figures, in your document, use the actual ones. Also, I used the geometry package option [showframe] to show how the figures are centered w.r.t. the page margins, in your real document, you don't need it.

Second, for placing figures side-by-side, you have several options each having it own pros and cons:

• Using minipage with the subcaption package to add a caption to each minipage
• Using the subfig package which is options-rich and has a \captionsetup command for easy control of the output.
• Using the floatrow package designed for these purposes
• Use the captionof command from the caption/subcation packages.

The first option (minipage) requires manual width adjustments in addition to a much difficulty aligning the figures with different captions length.

The third option (floatrow) has some limitations on caption setup

The fourth option has some cross-referencing problems

The second option is, IMHO, the best choice. It doesn't need manual width adjustments, where the natural width of the figures will be used and it works for figures of different widths and/or heights. Also, with \captionsetup command we can control the caption appearance and it doesn't require the caption package.

Third, for centering the two figures w.r.t. the page margins, we can use the \makebox command from graphicx. Essentially, \makebox[\textwidth] makes the box only \textwidth wide (whatever the actual width can be) which also avoids "Overfull hbox" errors. The second optional argument of \makebox is used to align it in the center. I got the idea from an answer to this question.

Another option for the same purpose is using the adjustbox package, which has many alignment options to be used.

• Thank you a lot! I remember having seen the question you took your answer from, but being new to latex and gnuplot I couldn't find that needle in the haystack, so to say. I'll try to implement it your way this evening. Also thanks for your constructive criticism, I'll make sure to cite my sources next time and have a MWE. – Malo Jul 7 '15 at 13:31
• For anybody getting "File `subfig.sty' not found." as an error trying to run AboAmmars code, you need to install the subfig package. I'm using MikTex which has a package manager which can be found in the MikTex start menu entry in the "Maintenance folder". – Malo Jul 7 '15 at 13:44
• In case somebody has problems with the figure numbering using the subfigure example. Subfigure captions seem to use their own counting. So use a \caption{} before \end{figure} instead and remove the "\renewcommand{\thesubfigure}{Figure \arabic{subfigure}}" line to get "a:" and "b:" below the pictures. – Malo Jul 10 '15 at 14:45