6

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}
  • 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 '15 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 '15 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 '15 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 '15 at 14:23
11

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
    May I know how to modify your code if I want to have caption of each sub-tables? – nam Sep 15 '17 at 8:08
  • If this doesn't work, it might be because the tables are too wide. – Elazar Nov 23 '17 at 17:12

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.