1

I have a problem with the alignment of the heading in my table. Here I want to force a line break with the function \shortstack for the table headers. This works also so far. However, I would like to align the heading to the top of the table. I have not found a working alternative for the \shortstack-function yet.

Solutions are offered here, but for some reason they do not work in my case: How to add a forced line break inside a table cell

Can someone help me to align the headers to the top? (And possibly left-aligned in addition?)

Here is my code:

\documentclass[]{article}
\usepackage[margin=1in]{geometry}
\usepackage{floatrow} \floatsetup[figure]{capposition=top} \floatsetup[table]{capposition=top} \usepackage{setspace}
\usepackage{siunitx} \newcolumntype{d}{S[table-format=2.1]}
\usepackage{booktabs}
\usepackage{array}
\usepackage{multirow}
\usepackage{wrapfig}
\usepackage{float}
\usepackage{tabu}
\usepackage{threeparttable}
\usepackage{threeparttablex}
\usepackage[normalem]{ulem}
\usepackage{makecell}
\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage[usestackEOL]{stackengine}

\begin{document}
\begin{tabu} to \linewidth {>{\raggedright}l|d|dddd}
\toprule
\shortstack{CAAR\\Window} & \shortstack{All\\transaction\\forms} & \shortstack{Acquisition Of\\ Partial Interest} & \shortstack{Acquisition Of\\ Majority Assets} &  \shortstack{Acquisition Of \\ Remaining Interest} & \shortstack{Merger}\\
\midrule
{(-15,-2)} & 1.7*** & 1.3** & 1.8** & 2.2*** & 2.0***\\
{(-10,-1)} & 1.9*** & 0.9** & 2.2*** & 2.4*** & 2.5***\\
{(-5,-1)} & 1.3*** & 0.9*** & 1.2*** & 1.4*** & 1.7***\\
{(-5,+5)} & 13.3*** & 5.7*** & 12.2*** & 14.7*** & 20.9***\\
{(-2,+2)} & 12.6*** & 5.5*** & 11.1*** & 13.8*** & 19.9***\\
{(-1,+1)} & 11.8*** & 5.0*** & 9.8*** & 11.9*** & 19.4***\\
{(0,0)} & 8.7*** & 3.0*** & 6.3*** & 7.0*** & 16.0***\\
{(0,+10)} & 12.1*** & 4.9*** & 10.7*** & 13.5*** & 19.4***\\
{(1,+10)} & 3.4*** & 1.8*** & 4.4*** & 6.5*** & 3.5***\\
{(2,+15)} & 1.2*** & 0.4 & 1.6** & 2.1*** & 1.4***\\
\bottomrule
\end{tabu}
\end{document}

enter image description here


I already used the \thead and the \makecell-function , but the table heading is shifted strangely:

enter image description here

6
  • Did you try with the \thead command, from makecell? The default alignment is centred both vertically and horizeontally, but you can change it with an optional argument. In your case, if I understand well what you want, \thead[tc]{…} would do it – if it is compatible with tabu.
    – Bernard
    Apr 15, 2021 at 8:26
  • Yes I've tried the \thead[tc]{…}- command, but the table heading is shifted strangely. See my edit.
    – TobKel
    Apr 15, 2021 at 8:29
  • Or maybe, add an empty third row to the \shortstacks with only two rows?
    – Bernard
    Apr 15, 2021 at 8:32
  • Good idea. But \shortstack{CAAR\\Window \\ { } gives me a centered aligned heading not a top aligned.
    – TobKel
    Apr 15, 2021 at 8:37
  • 1
    And with a \phantom{A} in the third row?
    – Bernard
    Apr 15, 2021 at 8:40

2 Answers 2

2
  • I wouldn't use package tabu. It is not maintained anymore, regardless that exist some fixes for its non-combability with new version of the array package, it is not recommended to use.
  • In your case I will rather use tabularx
  • for aligning of numbers I would use S column type defined in the siunitx package
  • It is sufficient, that you load each package only once :-), also is sensible to group packages according to their use (see MWE below)
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{booktabs, makecell, multirow, tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\usepackage[referable]{threeparttablex}
\NewExpandableDocumentCommand\mcc{mO{C}m}{\multicolumn{#1}{#2}{#3}}
\usepackage{siunitx}
\usepackage[normalem]{ulem}
\usepackage[usestackEOL]{stackengine}

\begin{document}
    \begin{table}[ht]
    \sisetup{table-format=2.1,
             table-space-text-post={***}
             } 
    \setcellgapes{2pt}
    \makegapedcells 
    \setlength\tabcolsep{3pt} 
\begin{tabularx}{\linewidth}{>{$}r<{$}@{\,}>{$}l<{$} | S | *{4}{S} @{}}
    \Xhline{1.2pt}
\mcc{2}[c|]{\makecell[t]{CAAR\\Window}} 
    & \mcc{1}[c|]{\makecell[t]{All\\transaction\\forms}} 
        & \mcc{1}{\makecell[t]{Acquisition Of\\ Partial Interest}} 
            & \mcc{1}{\makecell[t]{Acquisition Of\\ Majority Assets}} 
                &  \mcc{1}{\makecell[t]{Acquisition Of \\ Remaining Interest}} 
                    & \mcc{1}{\makecell[t]{Merger}}\\
    \Xhline{0.8pt}
(-15,   & -2)   &  1.7*** & 1.3**  &  1.8**  &  2.2*** &  2.0***    \\
(-10,   & -1)   &  1.9*** & 0.9**  &  2.2*** &  2.4*** &  2.5***    \\
 (-5,   & -1)   &  1.3*** & 0.9*** &  1.2*** &  1.4*** &  1.7***    \\
 (-5,   & +5)   & 13.3*** & 5.7*** & 12.2*** & 14.7*** & 20.9***    \\
 (-2,   & +2)   & 12.6*** & 5.5*** & 11.1*** & 13.8*** & 19.9***    \\
 (-1,   & +1)   & 11.8*** & 5.0*** &  9.8*** & 11.9*** & 19.4***    \\
  (0,   & 0)    &  8.7*** & 3.0*** &  6.3*** &  7.0*** & 16.0***    \\
  (0,   & +10)  & 12.1*** & 4.9*** & 10.7*** & 13.5*** & 19.4***    \\
  (1,   & +10)  &  3.4*** & 1.8*** &  4.4*** &  6.5*** &  3.5***    \\
  (2,   & +15)  &  1.2*** & 0.4    &  1.6**  &  2.1*** &  1.4***    \\
    \Xhline{1.2pt}
\end{tabularx}
    \end{table}
\end{document}

enter image description here

1
  • You not only control the alignment to the decimal points, but also the alignment to the coma in the first column. Great!
    – TobKel
    Apr 15, 2021 at 14:07
1

Your problem is those d columns, I believe --- change them to l using \multicolumn, and \makecell will work:

\documentclass[]{article}
\usepackage[margin=1in]{geometry}
\usepackage{floatrow} \floatsetup[figure]{capposition=top} \floatsetup[table]{capposition=top} \usepackage{setspace}
\usepackage{siunitx} \newcolumntype{d}{S[table-format=2.1]}
\usepackage{booktabs}
\usepackage{array}
\usepackage{multirow}
\usepackage{wrapfig}
\usepackage{float}
\usepackage{tabu}
\usepackage{threeparttable}
\usepackage{threeparttablex}
\usepackage[normalem]{ulem}
\usepackage{makecell}
\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage[usestackEOL]{stackengine}

\begin{document}
\begin{tabu} to \linewidth {>{\raggedright}l|d|dddd}
\toprule
\multicolumn1{l|}{\makecell[t]{CAAR\\Window}} & \multicolumn1{l|}{\makecell[t]{All\\transaction\\forms}} & \multicolumn1l{\makecell[t]{Acquisition Of\\ Partial Interest}} & \multicolumn1l{\makecell[t]{Acquisition Of\\ Majority Assets}} &  \multicolumn1l{\makecell[t]{Acquisition Of \\ Remaining Interest}} & \multicolumn1l{\makecell[t]{Merger}}\\
\midrule
{(-15,-2)} & 1.7*** & 1.3** & 1.8** & 2.2*** & 2.0***\\
{(-10,-1)} & 1.9*** & 0.9** & 2.2*** & 2.4*** & 2.5***\\
{(-5,-1)} & 1.3*** & 0.9*** & 1.2*** & 1.4*** & 1.7***\\
{(-5,+5)} & 13.3*** & 5.7*** & 12.2*** & 14.7*** & 20.9***\\
{(-2,+2)} & 12.6*** & 5.5*** & 11.1*** & 13.8*** & 19.9***\\
{(-1,+1)} & 11.8*** & 5.0*** & 9.8*** & 11.9*** & 19.4***\\
{(0,0)} & 8.7*** & 3.0*** & 6.3*** & 7.0*** & 16.0***\\
{(0,+10)} & 12.1*** & 4.9*** & 10.7*** & 13.5*** & 19.4***\\
{(1,+10)} & 3.4*** & 1.8*** & 4.4*** & 6.5*** & 3.5***\\
{(2,+15)} & 1.2*** & 0.4 & 1.6** & 2.1*** & 1.4***\\
\bottomrule
\end{tabu}
\end{document}

enter image description here

1
  • 1
    Thank you. It works!
    – TobKel
    Apr 15, 2021 at 14:05

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.