5

I have a table float with four subtables and having trouble with alignment and placing. Here's the code:

\begin{table}
\begin{subtable}{0.45\textwidth}
\centering
\begin{tabular}[t]{cccc}
\toprule
 Band &   L & $\mathcal{O}_{JK}^2$ & $\mathcal{O}_{EP}^2$ \\
\midrule
    1 &   0 &           0.97470(3) &            0.9881(3) \\
\midrule                                                  
     &   2 &            0.8290(2) &             0.882(2)  \\
     &   3 &           0.96595(4) &             0.979(1)  \\
    2 &   4 &           0.95328(6) &            0.9736(8) \\
     &   5 &           0.98727(2) &           0.9950(10)  \\
     &   6 &            0.9168(1) &             0.950(1)  \\
\midrule                                                  
     &   0 &            0.7776(4) &            0.8685(8)  \\
     &   1 &           0.96289(5) &             0.971(2)  \\
     &   2 &            0.8385(2) &            0.8838(8)  \\
     &   3 &            0.9021(1) &             0.929(1)  \\
     &   4 &            0.8687(2) &            0.9079(7)  \\
    3 &   5 &            0.9382(1) &             0.946(3) \\
     &   6 &            0.9052(2) &            0.9401(4)  \\
     &   7 &            0.9198(2) &            0.9483(5)  \\
     &   8 &            0.9649(5) &            0.9763(4)  \\
     &   9 &            0.9502(1) &             0.971(2)  \\
     &  10 &            0.9126(3) &             0.941(2)  \\
\bottomrule
\end{tabular}
\caption{\footnotesize (10,15)}
\label{tab:table1_a}
\end{subtable}%
\begin{subtable}{0.45\textwidth}
\centering
\begin{tabular}[t]{cccc}
\toprule
 Band &  L & $\mathcal{O}_{JK}^2$ & $\mathcal{O}_{EP}^2$ \\ 
\midrule
    1 &  0 &          0.997120(3) &            0.9987(2)  \\
\midrule                                                  
     &  2 &           0.97193(2) &            0.9830(7)   \\
    2 &  3 &           0.93118(5) &            0.9542(7)  \\
     &  4 &           0.92257(8) &            0.9486(7)   \\
     &  5 &           0.98844(1) &            0.9937(6)   \\
\midrule                                                  
     &  0 &            0.8450(1) &             0.905(2)   \\
     &  1 &            0.6931(3) &             0.726(2)   \\
     &  2 &            0.8618(1) &            0.8945(5)   \\
     &  3 &           0.90250(9) &            0.9233(9)   \\
    3 &  4 &            0.8487(1) &            0.8839(6)  \\
     &  5 &            0.9145(1) &            0.9382(7)   \\
     &  6 &            0.8884(2) &            0.9174(5)   \\
     &  7 &            0.9572(1) &             0.978(1)   \\
     &  8 &           0.97651(6) &             0.977(1)   \\
\bottomrule
\end{tabular}
\caption{\footnotesize (9,16)}
\label{tab:table1_b}
\end{subtable}%
\\
\par\bigskip
\begin{subtable}{0.45\textwidth}
\centering
\begin{tabular}[t]{cccc}
\toprule
 Band &    L & $\mathcal{O}_{JK}^2$ & $\mathcal{O}_{EP}^2$ \\
\midrule                                                    
    1 &  2.5 &           0.97230(3) &            0.9866(6) \\
\midrule                                                    
     &  1.5 &           0.96685(6)  &             0.980(3) \\
     &  2.5 &           0.92390(9)  &             0.956(4) \\
     &  3.5 &            0.9075(3)  &            0.9403(5) \\
    2 &  4.5 &            0.9256(4) &            0.9541(4) \\
     &  5.5 &            0.9920(3)  &            0.9957(5) \\
     &  6.5 &           0.97562(4)  &             0.984(1) \\
     &  7.5 &            0.9358(1)  &             0.963(2) \\
\bottomrule
\end{tabular}
\caption{\footnotesize (9,13)}
\label{tab:table1_c}
\end{subtable}%
\begin{subtable}{0.45\textwidth}
\centering
\begin{tabular}[t]{cccc}
\toprule
 Band &  L & $\mathcal{O}_{JK}^2$ & $\mathcal{O}_{EP}^2$ \\
\midrule                                                 
     &  1 &           0.97285(3) &            0.9834(9)  \\
    1 &  3 &          0.89744(10) &           0.9298(10) \\
     &  5 &           0.97480(3) &            0.9863(6)  \\
\midrule                                                  
     &  1 &            0.8590(3) &             0.915(1)  \\
     &  2 &            0.8428(4) &            0.8925(8)  \\
     &  3 &            0.8859(5) &            0.9195(8)  \\
    2 &  4 &            0.8799(1) &           0.9139(10) \\
     &  5 &            0.8939(3) &            0.9216(9)  \\
     &  6 &            0.9587(2) &            0.9752(9)  \\
     &  7 &            0.9286(1) &            0.9541(8)  \\
     &  8 &           0.94937(5) &             0.965(2)  \\
\bottomrule
\end{tabular}
\caption{\footnotesize (10,16)}
\label{tab:table1_d}
\end{subtable}%
\caption{\footnotesize Main caption describing \subref{table1_a}, \subref{table1_b}, \subref{table1_c} and \subref{table1_d}.}
\label{tab:table1}
\end{table}

My main problem is that these are overlapping horizontally, although I thought \begin{subtable}{0.45\textwidth} would take care of this the way it does with \begin{subfigure}. I get the same problem using \subpar, and \subfloat seems to clash with some other of my packages.

Secondly I'd like their upper edges to line up, and thought the [t] in begin{tabular}[t]{cccc} would take care of this, but it doesn't.

5

To achieve top-alignment of the subtables, add the [t] positioning specifier to each subtable environment. Also, do make sure that the widths of the tabular environments don't exceed the widths allocated to the subtable environments that enclose them. I would therefore suggest you change the allocated widths from 0.45\textwidth to 0.48\textwidth (and use \flushright directives inside subtables "b" and "d").

To separate the subtables horizontally, I suggest you insert an \hspace{\fill} instruction between subtables 1 and 2 and subtables 3 and 4, respectively.

You may also want to align the numbers in columns 3 and 4 of the subtables on their respective decimal markers.

enter image description here

\documentclass{article}
\usepackage{booktabs,subcaption,amsfonts,dcolumn}
\newcolumntype{d}[1]{D..{#1}}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro
\begin{document}

\begin{table}
\begin{subtable}[t]{0.48\textwidth}
\begin{tabular}[t]{@{} l c *{2}{d{1.7}} @{}}
\toprule
 Band &   L & \mc{$\mathcal{O}_{JK}^2$} & \mc{$\mathcal{O}_{EP}^2$} \\
\midrule
   1 &   0 &      0.97470(3) &       0.9881(3) \\
\midrule                                                  
     &   2 &      0.8290(2)  &       0.882(2)  \\
     &   3 &      0.96595(4) &       0.979(1)  \\
   2 &   4 &      0.95328(6) &       0.9736(8) \\
     &   5 &      0.98727(2) &       0.9950(10)\\
     &   6 &      0.9168(1)  &       0.950(1)  \\
\midrule                                                  
     &   0 &      0.7776(4) &       0.8685(8) \\
     &   1 &      0.96289(5)&       0.971(2)  \\
     &   2 &      0.8385(2) &       0.8838(8) \\
     &   3 &      0.9021(1) &       0.929(1)  \\
     &   4 &      0.8687(2) &       0.9079(7) \\
   3 &   5 &      0.9382(1) &       0.946(3)  \\
     &   6 &      0.9052(2) &       0.9401(4) \\
     &   7 &      0.9198(2) &       0.9483(5) \\
     &   8 &      0.9649(5) &       0.9763(4) \\
     &   9 &      0.9502(1) &       0.971(2)  \\
     &  10 &      0.9126(3) &       0.941(2)  \\
\bottomrule
\end{tabular}
\caption{\footnotesize (10,15)}
\label{tab:table1_a}
\end{subtable}
\hspace{\fill}
\begin{subtable}[t]{0.48\textwidth}
\flushright
\begin{tabular}[t]{@{} l c *{2}{d{1.7}} @{}}
\toprule
 Band &  L & \mc{$\mathcal{O}_{JK}^2$} & \mc{$\mathcal{O}_{EP}^2$} \\ 
\midrule
   1 &  0 &      0.997120(3) &      0.9987(2) \\
\midrule                                                  
     &  2 &      0.97193(2) &      0.9830(7)  \\
   2 &  3 &      0.93118(5) &      0.9542(7)  \\
     &  4 &      0.92257(8) &      0.9486(7)  \\
     &  5 &      0.98844(1) &      0.9937(6)  \\
\midrule                                                  
     &  0 &      0.8450(1) &       0.905(2)   \\
     &  1 &      0.6931(3) &       0.726(2)   \\
     &  2 &      0.8618(1) &       0.8945(5)  \\
     &  3 &      0.90250(9)&       0.9233(9)  \\
   3 &  4 &      0.8487(1) &       0.8839(6)  \\
     &  5 &      0.9145(1) &       0.9382(7)  \\
     &  6 &      0.8884(2) &       0.9174(5)  \\
     &  7 &      0.9572(1) &       0.978(1)   \\
     &  8 &      0.97651(6)&       0.977(1)   \\
\bottomrule
\end{tabular}
\caption{\footnotesize (9,16)}
\label{tab:table1_b}
\end{subtable}

\bigskip 

\begin{subtable}[t]{0.48\textwidth}
\begin{tabular}[t]{@{} l c *{2}{d{1.7}} @{}}
\toprule
 Band &    L & \mc{$\mathcal{O}_{JK}^2$} & \mc{$\mathcal{O}_{EP}^2$} \\
\midrule                                                    
   1 &  2.5 &      0.97230(3) &      0.9866(6) \\
\midrule                                                    
     &  1.5 &      0.96685(6) &      0.980(3)  \\
     &  2.5 &      0.92390(9) &      0.956(4)  \\
     &  3.5 &      0.9075(3)  &      0.9403(5) \\
   2 &  4.5 &      0.9256(4)  &      0.9541(4) \\
     &  5.5 &      0.9920(3)  &      0.9957(5) \\
     &  6.5 &      0.97562(4) &      0.984(1)  \\
     &  7.5 &      0.9358(1)  &      0.963(2)  \\
\bottomrule
\end{tabular}
\caption{\footnotesize (9,13)}
\label{tab:table1_c}
\end{subtable}
\hspace{\fill}
\begin{subtable}[t]{0.48\textwidth}
\flushright
\begin{tabular}[t]{@{} l c *{2}{d{1.7}} @{}}
\toprule
 Band &  L & \mc{$\mathcal{O}_{JK}^2$} & \mc{$\mathcal{O}_{EP}^2$} \\
\midrule                                                 
     &  1 &        0.97285(3) &      0.9834(9)  \\
   1 &  3 &        0.89744(10)&      0.9298(10) \\
     &  5 &        0.97480(3) &      0.9863(6)  \\
\midrule                                                  
     &  1 &      0.8590(3) &      0.915(1)   \\
     &  2 &      0.8428(4) &      0.8925(8)  \\
     &  3 &      0.8859(5) &      0.9195(8)  \\
   2 &  4 &      0.8799(1) &      0.9139(10) \\
     &  5 &      0.8939(3) &      0.9216(9)  \\
     &  6 &      0.9587(2) &      0.9752(9)  \\
     &  7 &      0.9286(1) &      0.9541(8)  \\
     &  8 &      0.94937(5)&      0.965(2)   \\
\bottomrule
\end{tabular}
\caption{\footnotesize (10,16)}
\label{tab:table1_d}
\end{subtable}

\caption{\footnotesize Main caption describing \subref{tab:table1_a}, \subref{tab:table1_b}, \subref{tab:table1_c} and \subref{tab:table1_d}.}
\label{tab:table1}
\end{table}
\end{document}
  • Thanks, that looks great! A few questions: What does the \newcolumntype{d}[1]{D..{#1}} do? Is this aligning the numbers? And what does the multicolumn macro do? – jorgen Feb 18 '16 at 10:17
  • 1
    @jorgen - The dcolumn package provides a column type called D. The \newcolumntype{d}[1]{D..{#1}} instruction creates a simplified interface, allowing me to write d{1.7} instead of D{.}{.}{1.7}. The first . (dot) specifies the input decimal marker, the second . (dot) specifies the output decimal marker, and 1.7 says, "set aside space for one digit before the decimal marker and for seven digits after the decimal marker". Since all entries in a column of type d are expected to be numeric, the \mc{...} wrapper is needed to provide an override for the header cell contents. – Mico Feb 18 '16 at 10:25
  • Hello again! I would like to use your excellent setup for another table with more columns, but I'm having some trouble generalising it. For three columns of data my best result is using \begin{tabular}[t]{@{} l c *{3}{d{1.7}} @{}}, i.e. substituting the 2 for a 3. This aligns the numbers in the columns, but the last one has much more space than the first two. What's missing? – jorgen Feb 21 '16 at 9:56
  • @jorgen - It's not easy to provide a full diagnosis, given the limited amount of information. Is there maybe a header cell in the third data column that's taking up more space than the material in the other header cells? Did you encase the header information in all header cells in \mc{...} wrappers? Are two or more tabular environments being typeset side by side? – Mico Feb 21 '16 at 10:18
  • None of those, although there are other characters than number in the data, could that be it? To make the question more clear I started a new one: tex.stackexchange.com/questions/295084/… – jorgen Feb 21 '16 at 10:32

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.