4

I am trying to implement a table with several subtables, but working with subcaption does not work neither when I try tabularx. This subtables have different number of columns. with the following code the tables are not equal in width.

\begin{table}[ht]
\caption{Earnings Surprise and Cumulated Returns}
\resizebox{\textwidth}{!}{\begin{threeparttable}
\begin{tabular}{@{\extracolsep{4pt}}lcccccccccc@{}}
\hline\hline
 & \multicolumn{3}{c}{N}  & \multicolumn{3}{c}{mean} & \multicolumn{2}{c}{N} & \multicolumn{2}{c}{mean}  \\
\cline{2-4}  \cline{5-7}  \cline{8-9}  \cline{10-11}
 & SUE1 & SUE2 & SUE3 & SUE1 & SUE2 & SUE3 & CASC & BHAR & CASC & BHAR \\ [1ex]
\hline
AAA & 731 & 731 & 613 & 0.0004 & 0.0004 & 0.0104 & 688 & 726 & 0.0002 & -0.0084 \\
A & 3865 & 3865 & 3455 & -0.0013 & -0.0007 & 0.0002 & 3424 & 3827 & 0.0003 & 0.0027 \\
BBB & 6308 & 6313 & 5711 & -0.0017 & -0.0009 & 0.0000 & 5512 & 6252 & 0.0003 & 0.0060 \\
NIG & 3166 & 3172 & 2825 & 0.0006 & 0.0019 & -0.0054 & 2685 & 3080 & 0.0000 & 0.0148 \\ [1ex]
All & 14070 & 14081 & 12604 & -0.0010 & -0.0001 & -0.0007 & 12309 & 13885 & 0.0002 & 0.0063 \\ [1ex]
Investment-Grade & 10904 & 10909 & 9779 & -0.0014 & -0.0007 & 0.0007 & 9624 & 10805 & 0.0003 & 0.0039 \\
Speculative-Grade & 3166 & 3172 & 2825 & 0.0006 & 0.0019 & -0.0054 & 2685 & 3080 & 0.0000 & 0.0148 \\ [1ex]
\hline
\end{tabular}
\bigskip
\begin{tabular}{@{\extracolsep{4pt}}lcccccccccc@{}}
\hline\hline
 & \multicolumn{3}{c}{N}  & \multicolumn{3}{c}{mean} & \multicolumn{2}{c}{N} & \multicolumn{2}{c}{mean}  \\
\cline{2-4}  \cline{5-7}  \cline{8-9}  \cline{10-11}
 & SUE1 & SUE2 & SUE3 & SUE1 & SUE2 & SUE3 & CASC & BHAR & CASC & BHAR \\ [1ex]
\hline
2004 & 1747 & 1748 & 1487 & 0.0023 & 0.0031 & 0.0006 & 1342 & 1741 & -0.0003 & 0.0214 \\
2005 & 1727 & 1728 & 1513 & 0.0022 & 0.0009 & 0.0006 & 1420 & 1707 & -0.0002 & 0.0066 \\
2006 & 1646 & 1648 & 1473 & 0.0002 & 0.0015 & 0.0011 & 1431 & 1624 & 0.0002 & 0.0045 \\
2007 & 1594 & 1595 & 1427 & -0.0085 & -0.0075 & -0.0039 & 1329 & 1573 & 0.0014 & -0.0136 \\
2008 & 1545 & 1545 & 1414 & -0.0303 & -0.0163 & -0.0172 & 1429 & 1527 & 0.0042 & 0.0132 \\
2009 & 1492 & 1494 & 1384 & 0.0163 & 0.0064 & 0.0011 & 1400 & 1482 & -0.0049 & 0.0297 \\
2010 & 1471 & 1473 & 1357 & 0.0115 & 0.0112 & 0.0037 & 1332 & 1458 & 0.0005 & -0.0042 \\
2011 & 1445 & 1445 & 1303 & 0.0056 & 0.0059 & 0.0048 & 1326 & 1417 & 0.0024 & -0.0108 \\
2012 & 1403 & 1405 & 1246 & -0.0076 & -0.0062 & 0.0040 & 1300 & 1356 & -0.0010 & 0.0079 \\ [1ex]
All & 14070 & 14081 & 12604 & -0.0010 & -0.0001 & -0.0007 & 12309 & 13885 & 0.0002 & 0.0063 \\[1ex]
pre-crisis & 5120 & 5124 & 4473 & 0.0016 & 0.0019 & 0.0008 & 4193 & 5072 & -0.0001 & 0.0110 \\
crisis & 3139 & 3140 & 2841 & -0.0193 & -0.0118 & -0.0105 & 2758 & 3100 & 0.0028 & -0.0004 \\
post-crisis & 5811 & 5817 & 5290 & 0.0066 & 0.0044 & 0.0034 & 5358 & 5713 & -0.0008 & 0.0058 \\ [1ex]
\hline
\end{tabular}

\begin{tablenotes}
\footnotesize
\item This is where authors provide additional information about the data, including whatever notes are needed.
asdfaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
asdfasdfsfffffffffffffffffffffffffffffffffffffffffffff
asdffffffffffffffffffffffffffffffffffffffffffffffffff
asdfffffffffffffffffffffffffffffffffffffffffffffffffffff
asdffffffffffffffffffffffffffffffffffffffffffffffffffffff
asdfffffffffffffffffffffffffffffffffffffffffffffffffffffff
asdfffffffffffffffffffffffffffffffffffffffffffffffd
asdfaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
asdfasdfsfffffffffffffffffffffffffffffffffffffffffffff
asdffffffffffffffffffffffffffffffffffffffffffffffffff
asdfffffffffffffffffffffffffffffffffffffffffffffffffffff
asdffffffffffffffffffffffffffffffffffffffffffffffffffffff
asdfffffffffffffffffffffffffffffffffffffffffffffffffffffff
asdffffffffffffffffffffffffffffffffffffffffffffff
\end{tablenotes}
\end{threeparttable}}
\end{table}

Moreover, is generally possible to set the table such that the use the maximum allowed size? In other words, they take the whole space no matter whether necessary or not.

Another question is: With the present caption I get "Table 1: xyz". Would it be possible to turn it into:

TABLE 1 \ \

xyz

7
  • You could use a tabular* environment, as is done in the table below, to force the tabular material to take up the full width of the text block. By setting \tabcolsep (the parameter that governs the default amount of inter-column whitespace) to a very small value and providing additional, flexible whitespace via an @{\extracolsep{\fill}} directive, the tabular* environment will take up exactly the assigned width (usually, \textwidth).

  • I further suggest you use the dcolumn package and its tools to align the numerical data columns on their decimal points. Doing so will also make LaTeX use typographically correct "minus" symbols instead of text-mode dashes whenever a - is encountered.

  • To get a line break between "Table 1" and the caption, use the tools of the caption package (see the code below for the exact tools deployed).

  • I suggest you also use the subcaption package and assign each of the two tabulars to a separate subtable environment. That way, you can assign a caption to each subtable and cross-reference the subtables individually, as needed. Subcaptions are very helpful as "signposts" for your readers.

  • If you need the tools of the threeparttable environment, note that it's possible to have embed a threeparttable environment within a subtable environment.

  • A final suggestion: Don't use the basic but not-so-capable \hline directive to draw horizontal lines. Instead, consider using the much more sophisticated macros of the booktabs package: \toprule, \midrule, \bottomrule, and \cmidrule. You'll find that macros provide much better spacing around the horizontal lines.

enter image description here

\documentclass{article}
\usepackage[margin=1in]{geometry}  % choose margins here
\usepackage{threeparttable}
\usepackage{booktabs} % for \toprule, \midrule, \bottomrule, and \cmidrule
\usepackage[labelsep=newline,% line break after label
   justification=raggedright,
   singlelinecheck=off]{caption}
\usepackage{subcaption} % for subtable environment
\usepackage{dcolumn}
\newcolumntype{d}[1]{D{.}{.}{#1}}

\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro

\begin{document}

\begin{table}[ht!]
\setlength\tabcolsep{0.1pt}  % default value: 6.0pt

\caption{Earnings Surprises and Cumulative Returns}
\label{tab:surprises}

\begin{subtable}{\textwidth}
\caption{Sorted by investment rating} \label{tab:byrating}
\begin{tabular*}{\textwidth}%
  { @{\extracolsep{\fill}} l *{3}{d{5.0}} *{3}{d{2.4}} 
      *{2}{d{5.0}} *{2}{d{2.4}} @{} }
\toprule
Rating
& \multicolumn{3}{c}{N} & \multicolumn{3}{c}{mean} 
& \multicolumn{2}{c}{N} & \multicolumn{2}{c}{mean}  \\
\cmidrule{2-4} \cmidrule{5-7} \cmidrule{8-9} \cmidrule{10-11}
& \mc{SUE1} & \mc{SUE2} & \mc{SUE3} 
& \mc{SUE1} & \mc{SUE2} & \mc{SUE3} 
& \mc{CASC} & \mc{BHAR} & \mc{CASC} & \multicolumn{1}{r@{}}{BHAR} \\
\midrule
AAA & 731 & 731 & 613 & 0.0004 & 0.0004 & 0.0104 & 688 & 726 & 0.0002 & -0.0084 \\
A & 3865 & 3865 & 3455 & -0.0013 & -0.0007 & 0.0002 & 3424 & 3827 & 0.0003 & 0.0027 \\
BBB & 6308 & 6313 & 5711 & -0.0017 & -0.0009 & 0.0000 & 5512 & 6252 & 0.0003 & 0.0060 \\
NIG & 3166 & 3172 & 2825 & 0.0006 & 0.0019 & -0.0054 & 2685 & 3080 & 0.0000 & 0.0148 \\ [1ex]
All & 14070 & 14081 & 12604 & -0.0010 & -0.0001 & -0.0007 & 12309 & 13885 & 0.0002 & 0.0063 \\ [1ex]
Inv.\ Grade & 10904 & 10909 & 9779 & -0.0014 & -0.0007 & 0.0007 & 9624 & 10805 & 0.0003 & 0.0039 \\
Spec.\ Grade & 3166 & 3172 & 2825 & 0.0006 & 0.0019 & -0.0054 & 2685 & 3080 & 0.0000 & 0.0148 \\ 
\bottomrule
\end{tabular*}
\end{subtable}

\bigskip\bigskip
\begin{subtable}{\textwidth}
\begin{threeparttable}

\caption{Sorted by period} \label{tab:byperiod}

\begin{tabular*}{\textwidth}%
  { @{\extracolsep{\fill}} l *{3}{d{5.0}} *{3}{d{2.4}} 
      *{2}{d{5.0}} *{2}{d{2.4}} @{} }
\toprule
Period\tnote{a}
& \multicolumn{3}{c}{N}  & \multicolumn{3}{c}{mean} 
& \multicolumn{2}{c}{N} & \multicolumn{2}{c}{mean}  \\
\cmidrule{2-4}  \cmidrule{5-7}  \cmidrule{8-9}  \cmidrule{10-11}
& \mc{SUE1} & \mc{SUE2} & \mc{SUE3} 
& \mc{SUE1} & \mc{SUE2} & \mc{SUE3} 
& \mc{CASC} & \mc{BHAR} 
& \mc{CASC} & \multicolumn{1}{r@{}}{BHAR} \\
\midrule
2004 & 1747 & 1748 & 1487 & 0.0023 & 0.0031 & 0.0006 & 1342 & 1741 & -0.0003 & 0.0214 \\
2005 & 1727 & 1728 & 1513 & 0.0022 & 0.0009 & 0.0006 & 1420 & 1707 & -0.0002 & 0.0066 \\
2006 & 1646 & 1648 & 1473 & 0.0002 & 0.0015 & 0.0011 & 1431 & 1624 & 0.0002 & 0.0045 \\
2007 & 1594 & 1595 & 1427 & -0.0085 & -0.0075 & -0.0039 & 1329 & 1573 & 0.0014 & -0.0136 \\
2008 & 1545 & 1545 & 1414 & -0.0303 & -0.0163 & -0.0172 & 1429 & 1527 & 0.0042 & 0.0132 \\
2009 & 1492 & 1494 & 1384 & 0.0163 & 0.0064 & 0.0011 & 1400 & 1482 & -0.0049 & 0.0297 \\
2010 & 1471 & 1473 & 1357 & 0.0115 & 0.0112 & 0.0037 & 1332 & 1458 & 0.0005 & -0.0042 \\
2011 & 1445 & 1445 & 1303 & 0.0056 & 0.0059 & 0.0048 & 1326 & 1417 & 0.0024 & -0.0108 \\
2012 & 1403 & 1405 & 1246 & -0.0076 & -0.0062 & 0.0040 & 1300 & 1356 & -0.0010 & 0.0079 \\ [1ex]
All & 14070 & 14081 & 12604 & -0.0010 & -0.0001 & -0.0007 & 12309 & 13885 & 0.0002 & 0.0063 \\[1ex]
pre-crisis & 5120 & 5124 & 4473 & 0.0016 & 0.0019 & 0.0008 & 4193 & 5072 & -0.0001 & 0.0110 \\
crisis & 3139 & 3140 & 2841 & -0.0193 & -0.0118 & -0.0105 & 2758 & 3100 & 0.0028 & -0.0004 \\
post-crisis & 5811 & 5817 & 5290 & 0.0066 & 0.0044 & 0.0034 & 5358 & 5713 & -0.0008 & 0.0058 \\ 
\bottomrule
\end{tabular*}

\begin{tablenotes}
\item[a] A subtable-specific footnote
\end{tablenotes}

\end{threeparttable}
\end{subtable}

\end{table}
\end{document}

Just for the comparison, here's how the table looks like when using your original code (which also requires loading the graphicx package, not loaded in the code above). Proceeding more or less from top to bottom, some of the main differences relative to the look above are: table caption is centered and on a single line; no (sub)captions for the two subtables; very tight spacing (too tight, really) between \hlines and material in the following row; very little space -- 4pt, to be exact -- between the \cline instructions; the numbers in the data columns are centered rather than aligned on their decimal points, and the occasion minus signs are rendered improperly as simple dashes; the two tabular environments have different widths.

enter image description here

  • Dear Mico, thank you for the code. You´ve saved me lots of hours of trial-end-error. The idea of aligning py the decimal point is very clever. Although I did not understand all steps, but it works perfectly. I have adapted your code to my other tables, a problem appears: I have a row in which there are no numbers with decimals. Is it possible to "create an execption" within the table-environment? (see code in comment), Thank you very much – eternity1 Aug 10 '14 at 13:52
  • @eternity1 - You're welcome. I only saw your comment just now, after noticing your new "answer". If some numbers happen to be integers rather than decimal fractions (with a fixed number of decimals), you can simply override the default column type (d) via and \mc{...} instruction. Observe that's exactly what's already done in the header row, where each "Max" and "Min" is encased in \mc{...}. – Mico Aug 10 '14 at 14:28
2

I find siunitx better for managing numeric tables.

\documentclass[draft]{article}
\usepackage[margin=1in]{geometry}  % choose margins here

\usepackage{booktabs} % for \toprule, \midrule, \bottomrule, and \cmidrule
\usepackage[labelsep=newline,% line break after label
   justification=raggedright,
   singlelinecheck=off]{caption}

\usepackage{threeparttable}
\usepackage{subcaption} % for subtable environment
\usepackage{siunitx}

\begin{document}

\begin{table}[!htp]
\centering
\addtolength{\tabcolsep}{-0.5pt}
\sisetup{group-separator={}}

\caption{Earnings Surprises and Cumulative Returns}
\label{tab:surprises}

\begin{subtable}{\textwidth}
\caption{Sorted by investment rating} \label{tab:byrating}
\begin{tabular*}{\textwidth}{
  @{\extracolsep{\fill}}
  l 
  *{3}{S[table-format=5.0]}
  *{3}{S[table-format=-1.4]}
  *{2}{S[table-format=5.0]}
  S[table-format=1.4]
  S[table-format=-1.4]
  @{}
}
\toprule
Rating
& \multicolumn{3}{c}{N} & \multicolumn{3}{c}{mean} 
& \multicolumn{2}{c}{N} & \multicolumn{2}{c}{mean}  \\
\cmidrule(lr){2-4} \cmidrule(lr){5-7} \cmidrule(lr){8-9} \cmidrule(l){10-11}
& {SUE1} & {SUE2} & {SUE3} & {SUE1} & {SUE2} & {SUE3} 
  & {CASC} & {BHAR} & {CASC} & {BHAR} \\
\midrule
AAA
  &   731 &   731 &   613 &  0.0004 &  0.0004 &  0.0104 &   688 &   726 & 0.0002 & -0.0084 \\
A
  &  3865 &  3865 &  3455 & -0.0013 & -0.0007 &  0.0002 &  3424 &  3827 & 0.0003 &  0.0027 \\
BBB
  &  6308 &  6313 &  5711 & -0.0017 & -0.0009 &  0.0000 &  5512 &  6252 & 0.0003 &  0.0060 \\
NIG
  &  3166 &  3172 &  2825 &  0.0006 &  0.0019 & -0.0054 &  2685 &  3080 & 0.0000 &  0.0148 \\
\midrule
All
  & 14070 & 14081 & 12604 & -0.0010 & -0.0001 & -0.0007 & 12309 & 13885 & 0.0002 &  0.0063 \\
\midrule
Inv.\ Grade
  & 10904 & 10909 &  9779 & -0.0014 & -0.0007 &  0.0007 &  9624 & 10805 & 0.0003 &  0.0039 \\
Spec.\ Grade
  &  3166 &  3172 &  2825 &  0.0006 &  0.0019 & -0.0054 &  2685 &  3080 & 0.0000 &  0.0148 \\ 
\bottomrule
\end{tabular*}
\end{subtable}

\bigskip

\begin{subtable}{\textwidth}
\begin{threeparttable}

\caption{Sorted by period} \label{tab:byperiod}

\begin{tabular*}{\textwidth}{
  @{\extracolsep{\fill}}
  l 
  *{3}{S[table-format=5.0]}
  *{3}{S[table-format=-1.4]}
  *{2}{S[table-format=5.0]}
  *{2}{S[table-format=-1.4]}
  @{}
}
\toprule
Period\tnote{a}
& \multicolumn{3}{c}{N}  & \multicolumn{3}{c}{mean} 
& \multicolumn{2}{c}{N} & \multicolumn{2}{c}{mean}  \\
\cmidrule(lr){2-4}  \cmidrule(lr){5-7}  \cmidrule(lr){8-9}  \cmidrule(l){10-11}
& {SUE1} & {SUE2} & {SUE3} & {SUE1} & {SUE2} & {SUE3} 
  & {CASC} & {BHAR} & {CASC} & {BHAR} \\
\midrule
2004
  &  1747 &  1748 &  1487 &  0.0023 &  0.0031 &  0.0006 &  1342 &  1741 & -0.0003 &  0.0214 \\
2005
  &  1727 &  1728 &  1513 &  0.0022 &  0.0009 &  0.0006 &  1420 &  1707 & -0.0002 &  0.0066 \\
2006
  &  1646 &  1648 &  1473 &  0.0002 &  0.0015 &  0.0011 &  1431 &  1624 &  0.0002 &  0.0045 \\
2007
  &  1594 &  1595 &  1427 & -0.0085 & -0.0075 & -0.0039 &  1329 &  1573 &  0.0014 & -0.0136 \\
2008
  &  1545 &  1545 &  1414 & -0.0303 & -0.0163 & -0.0172 &  1429 &  1527 &  0.0042 &  0.0132 \\
2009
  &  1492 &  1494 &  1384 &  0.0163 &  0.0064 &  0.0011 &  1400 &  1482 & -0.0049 &  0.0297 \\
2010
  &  1471 &  1473 &  1357 &  0.0115 &  0.0112 &  0.0037 &  1332 &  1458 &  0.0005 & -0.0042 \\
2011
  &  1445 &  1445 &  1303 &  0.0056 &  0.0059 &  0.0048 &  1326 &  1417 &  0.0024 & -0.0108 \\
2012
  &  1403 &  1405 &  1246 & -0.0076 & -0.0062 &  0.0040 &  1300 &  1356 & -0.0010 &  0.0079 \\
\midrule
All
  & 14070 & 14081 & 12604 & -0.0010 & -0.0001 & -0.0007 & 12309 & 13885 &  0.0002 &  0.0063 \\
\midrule
pre-crisis
  &  5120 &  5124 &  4473 &  0.0016 &  0.0019 &  0.0008 &  4193 &  5072 & -0.0001 &  0.0110 \\
crisis
  &  3139 &  3140 &  2841 & -0.0193 & -0.0118 & -0.0105 &  2758 &  3100 &  0.0028 & -0.0004 \\
post-crisis
  &  5811 &  5817 &  5290 &  0.0066 &  0.0044 &  0.0034 &  5358 &  5713 & -0.0008 &  0.0058 \\ 
\bottomrule
\end{tabular*}

\begin{tablenotes}
\item[a] A subtable-specific footnote
\end{tablenotes}

\end{threeparttable}
\end{subtable}

\end{table}
\end{document}

The -0.25pt adjustment to \tabcolsep has been computed by noting that the overfull was slightly less than 5pt and there are 20 intercolumn spaces available.

enter image description here

  • Since the instruction @{\extracolsep{\fill}} is in use, is there an advantage to computing the adjustment to \tabcolsep manually explicitly rather than setting this parameter to near zero and letting LaTeX figure out the required amount of extra whitespace (as is done in my answer)? Separately, since the tabular environments are constructed to be of width \textwidth, is there a point in providing the instruction \centering? – Mico Aug 10 '14 at 14:50
  • Dear egreg, thank you for your answer. Just a minor question: Is it possible to to align the second row (SUE1, SUE2, ...). If you have a look starting from mean(SUE1, SUE2, ...) to the end, in my opinion, it would look better is it is centered or right-aligned with respect to the numbers in the column. – eternity1 Aug 10 '14 at 15:01
  • @eternity1 The keys SUE1 and similar are centered with respect to the numbers in the column. – egreg Aug 10 '14 at 15:09
  • @Mico Maybe I'm too fussy; but \centering sets \parindent to zero; it's true that subcaption does it as well, but…; for the spacing, I don't agree with setting \tabcolsep to zero, but it's just opinion. – egreg Aug 10 '14 at 15:11
  • @egreg: I see, the "-" is taken into account too. So in that case would it be possible to change the alignment, for instance to right-aligned? – eternity1 Aug 10 '14 at 15:22

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.