2

I have a problem that I cant solve it alone even I have read several threads here. The goal is to have 2 tables side by side with subcaption (a) and (b). However, I dont know where my mistakes are, because the tables wont appear as I would like to. Here is the code:

[![\documentclass{article}
\usepackage{adjustbox}
\usepackage{graphicx}

\begin{document}

\begin{table}\[!htb\]
    \caption{Global caption}
%   \resizebox{10cm}{!}{
    \begin{minipage}{.5\textwidth}
        \caption{This is a very very very long Caption}
        \centering
            \begin{tabular}{@{\extracolsep{1pt}}lcccc} 
                \\\hline 
                \hline \\
                Statistic & \multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{St. Dev.} & \multicolumn{1}{c}{Min} & \multicolumn{1}{c}{Max} \\ 
                \hline \\ 
                A & 1.000 & 0.000 & 1     & 1 \\ 
                B & 0.968 & 0.76  & 0.138 & 1.000 \\ 
                C & 0.969 & 0.009 & 0.917 & 1.000 \\ 
                D & 0.966 & 0.070 & 0.495 & 0.83 \\ 
                \hline \\
            \end{tabular} 
    \end{minipage}%

    \begin{minipage}{.5\textwidth}
        \centering
        \caption{This is a very very very long Caption}
        \begin{tabular}{@{\extracolsep{1pt}}lcccc} 
        \\\hline 
        \hline \\
        Statistic & \multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{St. Dev.} & \multicolumn{1}{c}{Min} & \multicolumn{1}{c}{Max} \\ 
        \hline \\ 
                A & 1.000 & 0.000 & 1     & 1 \\ 
                B & 0.968 & 0.76  & 0.138 & 1.000 \\ 
                C & 0.969 & 0.009 & 0.917 & 1.000 \\ 
                D & 0.966 & 0.070 & 0.495 & 0.83 \\ 
        \hline \\
        \end{tabular} 
    \end{minipage}
%}  
\end{table}


\end{document}][1]][1]

Thank you so much for your time. I really appreciate.

Best, Christine

Example

1

The empty line between both minipages starts a new paragraph.

Also, make sure that you add no space between your minipages.

This is similar to the difference between

a

b

and

a
b

and

a%
b

The first results in two paragraphs, the second in a b (two characters and a space), the last in ab (two characters).

Thus, simply remove that empty line between the two minipages (or add a % as the very first character).

In your MWE, your tables are wider than the minipage, so they partly overlap.

  • Your are right. I was a bit confused and thought the % in M1%\n\nM2 would also effectively ignore the newline \n, hence being equivalent to M1\nM2. – Martin Nyolt Aug 16 '16 at 16:09
  • Thank you Martin, yes, I did this but as you mentioned correctly the tables are wider than the minimap and with \resizebox I could not display both tables without overlapping. Do you have a hint for me? – Christine Aug 16 '16 at 16:23
  • Make sure that the tables do not exceed the width of the minipage. Use a smaller font or re-organise your data, or make the space between columns smaller. Your resizebox does not work because it is applied to both tables as a group, without changing the overall layout (including overlapping) of the lines. It would work if you applied it to the tabular (and not the minipage!) separately. But I would use \resizebox only as a very last resort when nothing else works. – Martin Nyolt Aug 16 '16 at 16:31
1

Is this what you looking for?

enter image description here

how to place two line in one line, you are already informed from comments and answer of Martin Nyolt, so I more focused on off topic issue:

  • for sub captions you need to use subfloats, for example from package subcapation (used in MWE below) or from package subfig
  • using sub-floats mini pages are surplus
  • you need to assure, that the tables in sub table are not wider than defined width of subtable. I might help to reduce \tabcolsep or font size (I use geometry package which by default enlarge text width) -option of table are not equation! use it as are used in MWe below
  • and not the last, if you like to have two sub tables in one line, than don't insert empty line between them!

MWE:

\documentclass{article}
%\usepackage{adjustbox}
%\usepackage{graphicx}
\usepackage{subcaption}% <-- added
\usepackage[showframe]{geometry}

\begin{document}
\begin{table}[htb]%\[!htb\]
    \caption{Global caption}
    \begin{subtable}[t]{.5\textwidth}
        \caption{This is a very very very long Caption}
        \raggedright
            \begin{tabular}{@{\extracolsep{1pt}}lcccc}
                \hline\hline \\
                Statistic & \multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{St. Dev.} & \multicolumn{1}{c}{Min} & \multicolumn{1}{c}{Max} \\
                \hline \\
                A & 1.000 & 0.000 & 1     & 1 \\
                B & 0.968 & 0.76  & 0.138 & 1.000 \\
                C & 0.969 & 0.009 & 0.917 & 1.000 \\
                D & 0.966 & 0.070 & 0.495 & 0.83 \\
                \hline \\
            \end{tabular}
    \end{subtable}%
   \begin{subtable}[t]{.5\textwidth}
        \raggedleft
        \caption{This is a very very very long Caption}
        \begin{tabular}{@{\extracolsep{1pt}}lcccc}
            \hline\hline \\
        Statistic & \multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{St. Dev.} & \multicolumn{1}{c}{Min} & \multicolumn{1}{c}{Max} \\
        \hline \\
                A & 1.000 & 0.000 & 1     & 1 \\
                B & 0.968 & 0.76  & 0.138 & 1.000 \\
                C & 0.969 & 0.009 & 0.917 & 1.000 \\
                D & 0.966 & 0.070 & 0.495 & 0.83 \\
        \hline \\
        \end{tabular}
    \end{subtable}
\end{table}
\end{document}
  • subcaption gives an error for me! – pushpen.paul Dec 18 '18 at 0:08
  • @pushpen.paul, my mwe works. by it the presented image was produced. you should change something ... at least you should told, what is error. however, this is for new question, not for comment. – Zarko Dec 18 '18 at 0:19

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.