Placing figures/tables side-by-side (\minipage)

By thurnherr

Including images in a report is very common. Structuring your work nicely is probably the most obvious reason why you want to put two figures/tables side-by-side. Another reason might be to save space, wherever a smaller size of an image is sufficient. The following code can be used to place two figures side-by-side by creating a minipage…


\begin{figure}[ht]
\begin{minipage}[b]{0.5\linewidth}
\centering
\includegraphics[scale=1]{filename1}
\caption{default}
\label{fig:figure1}
\end{minipage}
\hspace{0.5cm}
\begin{minipage}[b]{0.5\linewidth}
\centering
\includegraphics[scale=1]{filename2}
\caption{default}
\label{fig:figure2}
\end{minipage}
\end{figure}

Note that for JPEG images the graphics package is required:

\usepackage{graphics}

The same “local column” – effect can be achieved for tables. The following code shows you how:


\begin{table}[ht]
\begin{minipage}[b]{0.5\linewidth}\centering
\begin{tabular}{|c|c|c|}
\hline
1&1&1\\
\hline
2&2&2\\
\hline
\end{tabular}
\end{minipage}
\hspace{0.5cm}
\begin{minipage}[b]{0.5\linewidth}
\centering
\begin{tabular}{|c|c|c|}
\hline
1&1&1\\
\hline
2&2&2\\
\hline
\end{tabular}
\end{minipage}
\end{table}

You can also have more than two column simply by adding another \minipage in between the table-command and reduce the width of each \minipage (0.33\linewidth for three columns) in addition to the \hspace. LaTex will automaticaly place objects onto the next line, if space is not sufficient.

Remark: Using the subfigure-package is another way to place figures or tables side-by-side. You might want to have a look at this post on subfigures.

Tags: , , , , , , , ,

38 Responses to “Placing figures/tables side-by-side (\minipage)”

  1. Donald Says:

    I was wondering if you had any tips on the creation of tables in LaTeX? This seems to be the most frustrating (to me) task. Ideally, I’d like a GUI table generator that converts the table into LaTeX.

    In any event, great blog!

  2. Creating two columns in article, report or book « Blog on Latex Matters Says:

    [...] have posted another article on that, just have a look there. minipage can also be used for text, not only for figures and [...]

  3. Placing figures/tables side-by-side (\subfigure) « Blog on Latex Matters Says:

    [...] within the usual figure-floating-environment. You can find a post on the minipage-environment here, behaving differently compared a subfigure, but is also used within a floating [...]

  4. Miguel Angel Says:

    PLLEEEEASE help me:
    I would like to create a table in Latex and add it a note at the end of the table and the source where I got that table from. How can I add those lines of text at the end of the table?
    Thanks,
    Miguel

  5. thurnherr Says:

    Hi Miguel,

    If I understand correctly, you can simply use the \caption{table description} command. Just make sure you place it before the \label{}. This post shows you how:
    http://texblog.wordpress.com/2007/08/07/introduction-to-tables-in-latex/

    Cheers,
    Tom

  6. Miguel Angel Says:

    Hi Thomas,
    This is how I would like my table to look in Latex (for example):

    Table 1. This is my table title
    _____________________________
    1970 2000
    _____________________________

    GDP 3.5 5.4
    Inflation 2.0 4.1
    _____________________________
    Note: this values are not true.
    Source: World Bank (2003).

    I don’t have problems with citing inside the table. That works fine. But my problem is how to add the note and the source at the end of the table. I’ve tried different options, nothing works (i.e., minipage) and it looks horrible. I wonder if there is an automatic option to do that. Double caption wouldn’t work because there would be two “Table #”, I gather.

    What do you think?

    Miguel

  7. thurnherr Says:

    You might want to try using the table itself to hold the note and source. Try this:
    \begin{table}[ht]
    \begin{minipage}[b]{0.48\linewidth}
    \caption{Table 1. This is my table title}
    \centering
    \begin{tabular}{lcc}
    \hline
    &1970&2000\\
    \hline
    GDP&3.5&5.4\\
    Inflation&2.0&4.1\\
    \hline
    \multicolumn{3}{l}{Note: this values are not true.}\\
    \multicolumn{3}{l}{Source: World Bank (2003).}\\
    \end{tabular}
    \end{minipage}
    \hspace{0.5cm}
    \begin{minipage}[b]{0.48\linewidth}
    \caption{Table 1. This is my table title}
    \centering
    \begin{tabular}{lcc}
    \hline
    &1970&2000\\
    \hline
    GDP&3.5&5.4\\
    Inflation&2.0&4.1\\
    \hline
    \multicolumn{3}{l}{Note: this values are not true.}\\
    \multicolumn{3}{l}{Source: World Bank (2003).}\\
    \end{tabular}
    \end{minipage}
    \end{table}

    If you need vertical lines to separate cells, instead of the horizontal bar in the column-number defining tabular-environment option, you can use \vline
    Example:
    \vline&Inflation&\vline&2.0&\vline&4.1&\vline\\
    It’s a lot more to type, but this way you can omit the vertical lines around the note and source.

  8. Amir Says:

    I’m looking for a way to place a picture next to a table. Do you have any idea on this?

  9. Amir Says:

    Ok, after some tries I could solve it myself. Here is the solution:
    \begin{table}[h]
    \begin{minipage}{0.45\textwidth}
    \centering
    \includegraphics[width=\textwidth]{fig1}
    \caption{caption fig1}
    \label{fig:fig1}

    \end{minipage}
    ~\hfill~
    \begin{minipage}{0.45\textwidth}
    \centering

    \begin{tabular}{|c|c|c|}
    moin & moin & moin\\
    \end{tabular}
    \caption{caption tab1}
    \label{tab:tab1}

    \end{minipage}
    \end{table}

    Thanks,
    Amir

  10. Winkelwagen Says:

    To all those with difficulties making tables:

    If you’re comfortable with a program like OpenOffice.org Calc or Excel or whatever, you can use that program to make your tables.
    If you Google for “Excel table macro Latex” or something like that, you can find a macro to convert the table to a LaTeX table.

    AFAIK Excel2Latex is also usable for this kind of conversions.

  11. ashokg Says:

    i want side caption for figures in two column job and also bottom allignment

  12. Aman Says:

    Hey thanks … found your minipage stuff pretty useful

  13. thurnherr Says:

    @ashokg

    This is not that easy actually. You can try the minipage-command, by using this Latex-source stab it worked perfectly well for me:

    \begin{figure}
    \centering
    \begin{minipage}[t]{0.58\linewidth}
    \includegraphics[width=1\linewidth]{figure-file}
    \end{minipage}\hfill
    \begin{minipage}[b]{0.38\linewidth}
    \caption{Whatever caption-text you want.\label{fig:caption}}
    \end{minipage}
    \end{figure}

    The most important thing here is the bottom-alignment of the right-hand side “minipage” ([b]). The linewidth of the figure is 1 in order to use the complete width provided by the “minipage”.

    Cheers,
    Tom.

  14. David Says:

    Hey

    For some reason, I can’t get the minipage environment to place my tables side-by-side. Here’s the source:

    \begin{table}[h]
    \begin{minipage}[b]{2.25in}
    \centering
    \caption{}
    \begin{tabular}{@{}|l|c|c|}
    \hline
    & \hearts & $\lnot$\hearts\\
    & (0.2) & (0.8)\\
    \hline
    $A$ & &\\ fold hand & $-\$78$ & $-\$78$\\
    \hline
    $B$ & &\\ call raise & $+\$x$ & $-\$228$\\
    \hline
    \end{tabular}
    \label{table3}
    \end{minipage}

    \begin{minipage}[b]{2.25in}
    \centering
    \caption{}
    \begin{tabular}{@{}|l|c|c|}
    \hline
    & \hearts & $\lnot$\hearts\\
    & (0.2) & (0.8)\\
    \hline
    $A$ & &\\ fold hand & $-\$y$ & $-\$y$\\
    \hline
    $B$ & &\\ call raise & $+\$231$ & $-\$228$\\
    \hline
    \end{tabular}
    \label{table4}
    \end{minipage}
    \end{table}

    Any ideas why this won’t work? Thanks.

  15. thurnherr Says:

    @David

    Just remove the space between the two minipage-environments and the tables are placed side-by-side, as long as there is enough space vertically. If you want some space between, you can comment the empty line out
    \end{minipage}
    %
    \begin{minipage}

    Tom.

  16. David Says:

    Miguel (or anyone else wondering about this)

    I’ve placed additional text at the bottom of my tables using a custom command I call ‘\capbot’ (caption bottom)

    \newcommand{\capbot}[1]{%
    \vspace{8pt}\footnotesize\raggedright #1}%

    I then use this command in the table float as follows:

    \end{tabular}
    \end{center}
    \capbot{Data from the IMF’s website: \url{http://www.imf.org/external/np/sec/memdir/members.htm.} Accessed 11 April 2007.}
    \label{nondemocfig}
    \end{table}

    This works quite nicely.

  17. Teni Says:

    Thanks, this article helped me a lot!

  18. Kai Says:

    How to create a big table across a two-column latex document? I tried vertically put the big table in one column for the two-column latex document. But it looks ugly so I tried \minipage. However, it still does not help. Any suggestions?

  19. thurnherr Says:

    Hi Kai,

    What I suggest you to do is use the command \onecolumn, which will start a new page having only one column in your “two column environment” (see my previous post).
    Then you insert your table, depending on the height/width ratio you can even change the page layout to landscape.
    And finally, you switch back to a \twocolumn environment.

    Cheers,
    Tom

  20. Si Says:

    Hi,

    Is it possible to have the two figures/tables aligned at the top stead at the bottom? I’ve tried \minipage[t] but it ended up with the top of the left figure/table aligned to the bottom of the right one. It looked as if the two figures/tables occupied the top right and bottom left of a 2×2 invisible grid.

    Thanks

  21. thurnherr Says:

    Hi Si,

    I had the same problem once I wanted to place a table next to a figure. Try to use subfigure instead of minipage, I’m not sure it will work, but it is worth a try.

    Note:
    Replace \begin{center}…\end{center} by \centering, which does not add any additional white space on top and below the figure/table.

  22. Floating text around figure/table « Blog on Latex Matters Says:

    [...] width of a page. Even though you can have several figures/tables next to each other (see posts on minipage and subfigure), with none of these techniques it is possible to have floating text around a figure [...]

  23. Blog on Latex Matters » Blog Archive » Floating text around figure/table Says:

    [...] width of a page. Even though you can have several figures/tables next to each other (see posts on minipage and subfigure), with none of these techniques it is possible to have floating text around a figure [...]

  24. Blog on Latex Matters » Blog Archive » Placing figures/tables side-by-side (\subfigure) Says:

    [...] within the usual figure-floating-environment. You can find a post on the minipage-environment here, behaving differently compared a subfigure, but is also used within a floating [...]

  25. Blog on Latex Matters » Blog Archive » Creating two columns in article, report or book Says:

    [...] have posted another article on that, just have a look there. minipage can also be used for text, not only for figures and [...]

  26. Hugo Says:

    Hi.
    I’m trying to put a table and a picture side-by-side but my efforts are in vane.. who I can do that?

    I made this but its not working well…


    \begin{figure}[!h]
    \subfloat{
    \includegraphics[scale=0.5]{picture1}
    }
    \hspace{1.2cm}
    \subfloat{
    \begin{minipage}[t]{5cm}{5cm}
    \begin{tabular}{|c|c|c|}
    \hline
    \multicolumn{1}{|c|}{Sectores} & $[345;355[$ & $[355;5[$ \\
    \multicolumn{1}{|c|}{Factores de calibração} & 1.02 & 1.02\\
    \hline
    \end{tabular}
    \end{minipage}
    }
    \end{figure}

  27. thurnherr Says:

    Hi Hugo,

    There is indeed a problem in your code. Y only have one minipage for your tabular environment, but actually you need a minipage for the picture as well. So try this and let me know if you are still facing problems:


    \begin{figure}[!h]
    \begin{minipage}[b]{0.5\linewidth}
    \centering
    \includegraphics{picture1}
    \end{minipage}
    \hspace{1.2cm}
    \begin{minipage}[b]{0.5\linewidth}
    \centering
    \begin{tabular}{|c|c|c|}
    \hline
    \multicolumn{1}{|c|}{Sectores} & $[345;355[$ & $[355;5[$ \\
    \multicolumn{1}{|c|}{Factores de calibração} & 1.02 & 1.02\\
    \hline
    \end{tabular}
    \end{minipage}
    \end{figure}

    Cheers,
    Tom

  28. Siddharth Khimsara Says:

    google xl2latex

  29. Table , figure in twocolumn mode « Hla Hla Htay’s Notes Says:

    [...] from http://texblog.wordpress.com/2007/08/01/placing-figurestables-side-by-side-minipage/ [...]

  30. Amar Nath Satrawala Says:

    Hi

    I am also trying to put a figure and a table side by side. They end up getting both Figure captions or table captions.

    I am not able to give simultaneously different captions i.e. figure to figure and table to table.

    Somebody please help.
    Cheers

    Amar

  31. Amar Nath Satrawala Says:

    Hi

    I found the solution by modifying the help given in http://www.win.tue.nl/latex/documentation/plaatjes/pictures.pdf

    \parbox [h]{0.4\textwidth}{
    \includegraphics [width=\linewidth]{drawing.eps}
    \captionof {figure}{caption1}
    \label{fig:draw}
    }
    %\hfill
    \hspace{0.5cm}
    \parbox [h]{0.4\textwidth }{
    \captionof {table}{caption2}
    \begin{tabular}{|c|l|}
    \hline
    a & b
    \hline
    \end{tabular}
    \label{tab:table1}
    }

  32. Albert Says:

    Laying out two tables of uneven length aligns both tables vertically in the middle. How would I align them both to the top?

    I think that this is exactly the problem that Si was asking about?

    • thurnherr Says:

      Hi Albert,

      I cannot reproduce what you are referring to. Can you please provide a minimal example? Might it be that your tables together are wider than the document’s “textwidth” and hence one is pushed to the next “line”?

      Cheers,
      Tom.

  33. Ketan Says:

    thanks!! That helped!!

  34. Placing figures/tables side-by-side « Bekhongdeokinh’s Blog Says:

    [...] Using minipage environment. Here is an example. [...]

  35. Spiros Says:

    Thanks mate, fantastic blog! I’m adding you to my blog roll, if that’s ok…

  36. Michiel Says:

    When i use the caption package, I got tons of errors after the place where I used the \captionof command… When I do not include the caption package, I only got 2 errors, there where I used the \captionof command…
    anyone?

    • Michiel Says:

      My bad, found the problem. I had this error: “to many unprocessed floats”. By using the caption package, the size of some captions may be changed, and suddenly LaTeX placed all my figures at the end of the document. This happened with so many figures that LaTeX couldn’t put them down nicely on a page any more. By using the float package, I forced some figures in position, and problem solved.

      An other solution when you got the error is putting in a \clearpage or \cleardoublepage command to allow a page full of figures to be generated.

Leave a Reply