9

I am trying to place three tables next to each other. Because they have the same caption, they are placed in three tabular envs in the same table env. For positioning I use minipage.

This works fairly well, but when looking closely, the gaps between tables 1/2 and 2/3 are not exactly the same width. This looks annoying with longer tables. Any ideas about how to get those gaps exactly the same width? The overall table should stay centered.

I actually use this in a large document with lots of packages loaded, but the behaviour seems to be the same in this MWE.

\documentclass{scrartcl}        
\begin{document}        
        \begin{table}
            \footnotesize
                \begin{minipage}{0.33\textwidth}
                \raggedright
                \begin{tabular}{|p{3.2cm}|c|}
                    \hline
                    bla&1\\ \hline
                    blubb&2 \\ \hline
                    bla&1\\ \hline
                    blubb&2 \\ \hline   
                    bla&1\\ \hline
                    blubb&2 \\ \hline   
                \end{tabular}
                \end{minipage}
                \begin{minipage}[c]{0.33\textwidth}
                %\centering
                \begin{tabular}{|p{3.2cm}|c|}
                    \hline
                    bla&1\\ \hline
                    blubb&2 \\ \hline
                    bla&1\\ \hline
                    blubb&2 \\ \hline   
                    bla&1\\ \hline
                    blubb&2 \\ \hline   
                \end{tabular}
                \end{minipage}%
                \begin{minipage}[c]{0.33\textwidth}
                %\raggedleft
                \begin{tabular}{|p{3.2cm}|c|}
                    \hline
                    bla&1\\ \hline
                    blubb&2 \\ \hline
                    bla&1\\ \hline
                    blubb&2 \\ \hline   
                    bla&1\\ \hline
                    blubb&2 \\ \hline   
                \end{tabular}
                \end{minipage}
                \caption{99 most frequent hashtags in the data set.}
            \end{table}
\end{document}
4
  • 1
    Difference is because you didn't put after first minipage % as after second one. Add this % after first minipage or erase one after second minipage.
    – Zarko
    Aug 11, 2015 at 14:06
  • You are right, this works in the MWE. In my actual code it does not. There it makes the gap difference even wider. (strange)
    – anjuta
    Aug 11, 2015 at 14:17
  • because you in the first and last minipages use ˛\raggedright and in center one nothing. If you put in all three minipages \centering, then both gaps become equal. After all, far more simple solution you receive in @AboAmmar answer.
    – Zarko
    Aug 11, 2015 at 14:21
  • Thank you for trying to help. I think I actually tried all of those things in my actual document and nothing seemed to work properly. But maybe this is caused by some package or other. thank you anyway
    – anjuta
    Aug 11, 2015 at 14:23

2 Answers 2

14

enter image description here

No need for minipages, \raggedright or any extra stuff. Just tabulars and \hfill between any two of them. The placement option [t] also aligns the tables' headers.

\documentclass{scrartcl}        
\begin{document}        
        \begin{table}
            \footnotesize
                \begin{tabular}[t]{|p{3.2cm}|c|}
                    \hline
                    bla&1\\ \hline
                    blubb&2 \\ \hline
                    bla&1\\ \hline
                    blubb&2 \\ \hline   
                    bla&1\\ \hline
                    blubb&2 \\ \hline   
                \end{tabular}
                \hfill
                \begin{tabular}[t]{|p{3.2cm}|c|}
                    \hline
                    bla&1\\ \hline
                    blubb&2 \\ \hline
                    bla&1\\ \hline
                    blubb&2 \\ \hline   
                    bla&1\\ \hline
                    blubb&2 \\ \hline   
                \end{tabular}
                \hfill
                \begin{tabular}[t]{|p{3.2cm}|c|}
                    \hline
                    bla&1\\ \hline
                    blubb&2 \\ \hline
                    bla&1\\ \hline
                    blubb&2 \\ \hline   
                    bla&1\\ \hline
                    blubb&2 \\ \hline   
                \end{tabular}
                \caption{99 most frequent hashtags in the data set.}
            \end{table}
\end{document}
2
  • 2
    May I know how to modify your code if I want to have caption of each sub-tables?
    – nam
    Sep 15, 2017 at 8:08
  • If this doesn't work, it might be because the tables are too wide.
    – Elazar
    Nov 23, 2017 at 17:12
2

Anyway if somebody is interested to know how to make subcaption for each table here the code. As Trevin Avery says in the remarks that I forgot to precise it requires the package \usepackage{subcaption} :

\begin{table}
\subcaptionbox{caption A}{
\begin{tabular}{|c|c|}
    \hline
    bla&1\\ \hline
    blubb&2 \\ \hline
    bla&1\\ \hline
    blubb&2 \\ \hline   
    bla&1\\ \hline
    blubb&2 \\ \hline   
\end{tabular}
}
\hfill
\subcaptionbox{caption B}{
\begin{tabular}{|c|c|}
    \hline
    bla&1\\ \hline
    blubb&2 \\ \hline
    bla&1\\ \hline
    blubb&2 \\ \hline   
    bla&1\\ \hline
    blubb&2 \\ \hline   
\end{tabular}
}
\hfill
\subcaptionbox{caption C}{
\begin{tabular}{|c|c|}
    \hline
    bla&1\\ \hline
    blubb&2 \\ \hline
    bla&1\\ \hline
    blubb&2 \\ \hline   
    bla&1\\ \hline
    blubb&2 \\ \hline   
\end{tabular}
}
\hfill
\caption{99 most frequent hashtags in the data set.}
\end{table}

I really Thank AboAmmar for his help to build this solution

2
  • This requires \usepackage{subcaption} in the preamble. You can see the additional options in the docs. Aug 6, 2021 at 21:56
  • Yes you're right it requires this package. Thanks for the precision for anyone who need. I will notice in the main post. Aug 12, 2021 at 12:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .