7

today is my first day to learn how to make a table in Latex. I come up with the following example:

enter image description here

My difficult right now is how to align asterisks. I want to match 0.019's "9" with the ending bracket of the number (36.58), then the asterisk should follow the "9" and should not be above the ")" of 36.58, can anyone help me with that?

\documentclass[11pt,a4paper]{article}
\usepackage{mathtools}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{siunitx}
\usepackage{makecell,graphicx,rotating,array,dcolumn,lscape}
\begin{document}
\newcolumntype{d}[1]{D{.}{.}{#1}}
\def\sym#1{\ensuremath{^{\mathrlap{#1}}}}
\begin{landscape}
{\setlength{\extrarowheight}{1.5pt}
\begin{table}[htbp]
\sisetup{table-align-text-post=false}
  \centering
  \caption{The Results of Future Abnormal Return}
    \begin{tabular}{*{9}{l}}
    \toprule
     \multicolumn{1}{l}{}& \multicolumn{1}{c}{EW1M}& \multicolumn{1}{c}{EW3M}&\multicolumn{1}{c}{EW6M}&\multicolumn{1}{c}{EW12M}&\multicolumn{1}{c}{VW1M} &\multicolumn{1}{c}{VW3M}&\multicolumn{1}{c}{VW6M}&\multicolumn{1}{c}{VW12M}\\
      \multicolumn{1}{c}{} & \multicolumn{1}{c}{(1)} &\multicolumn{1}{c}{(2)} &\multicolumn{1}{c}{(3)}  &       \multicolumn{1}{c}{(4)} & \multicolumn{1}{c}{(5)} & \multicolumn{1}{c}{(6)}& \multicolumn{1}{c}{(7)}& \multicolumn{1}{c}{(8)}\\ \midrule
       Purchaser (NPV) &0.019^{***}&0.021^{***}&0.025^{***}&0.025^{***}&0.017^{***}&0.025^{***}&0.038^{***}&0.060^{***}\\
          &(36.58)&(26.98)&(23.34)&(16.84)&(34.03)&(31.64)&(34.72)&(38.85)\\
          &130,982  &129,738    &128,316    &124,121    &130,982        &129,738    &128,316    &124,121\\
          Purchaser (NPR) &0.019^{***}&0.021^{***}&0.025^{***}&0.025^{***}&0.017^{***}&0.025^{***}&0.038^{***}&0.060^{***}\\
          &(36.57)&(26.99)&(23.37)&(16.89)&(34.03)&(31.64)&(34.72)&(38.85)\\
          &130,904  &129,660    &128,239    &124,051    &130,982        &129,738    &128,316    &124,121\\          
    \end{tabular}%
  \label{tab:addlabel}%
\end{table}}
\end{landscape}
\end{document}
  • 2
    Welcome to TeX.se, and thanks for adding a compilable example. You've loaded the siunitx package, but you're not using its extensive table formatting abilities. You've also defined a d column type, but you're not using that either. But siunitx should be able to do most of this. – Alan Munn Jul 21 at 19:46
  • Try this: \begin{tabular}{l *{8}{d{3}}} -- ? – John Jul 21 at 19:49
  • @AlanMunn Thanks Alan, I started to learn this literally today. So I am a fresher. I appreciate your help, but can you give me some more specified clues, then I can try to figure it out by myself. – veryBigman Jul 21 at 19:52
7

With the type of column S (of siunitx). All elements which are not part of the numbers must be protected by braces ({...}).

 \documentclass[11pt,a4paper]{article}
 \usepackage{mathtools}
 \usepackage{booktabs}
 \usepackage{amsmath}
 \usepackage{siunitx}
 \usepackage{makecell,graphicx,rotating,array,lscape}
 \begin{document}
 \def\sym#1{\ensuremath{^{\mathrlap{#1}}}}
 \begin{landscape}
 {\setlength{\extrarowheight}{1.5pt}
 \begin{table}[htbp]
 \sisetup{table-align-text-post=false}
   \centering
   \caption{The Results of Future Abnormal Return}
     \begin{tabular}{l*{8}{S}}
     \toprule
       {}& {EW1M}& {EW3M}&{EW6M}&{EW12M}&{VW1M} &{VW3M}&{VW6M}&{VW12M}\\
       {} & {(1)} &{(2)} &{(3)} & {(4)} & {(5)} & {(6)}& {(7)}& {(8)}\\ \midrule
        Purchaser (NPV) &0.019{$^{***}$}&0.021{$^{***}$}&0.025{$^{***}$}&0.025{$^{***}$}&0.017{$^{***}$}&0.025{$^{***}$}&0.038{$^{***}$}&0.060{$^{***}$}\\
           &{(}36.58{)}&{(}26.98{)}&{(}23.34{)}&{(}16.84{)}&{(}34.03{)}&{(}31.64{)}&{(}34.72{)}&{(}38.85{)}\\
           &130.982  &129.738    &128.316    &124.121    &130.982        &129.738    &128.316    &124.121\\
           Purchaser {(}NPR{)} &0.019{$^{***}$}&0.021{$^{***}$}&0.025{$^{***}$}&0.025{$^{***}$}&0.017{$^{***}$}&0.025{$^{***}$}&0.038{$^{***}$}&0.060{$^{***}$}\\
           &{(}36.57{)}&{(}26.99{)}&{(}23.37{)}&{(}16.89{)}&{(}34.03{)}&{(}31.64{)}&{(}34.72{)}&{(}38.85{)}\\
           &130.904  &129.660    &128.239    &124.051    &130.982        &129.738    &128.316    &124.121\\          
     \end{tabular}%
   \label{tab:addlabel}%
 \end{table}}
 \end{landscape}
 \end{document}

enter image description here

  • Why have you divided the large numbers by 1000? – John Jul 21 at 20:21
  • 1
    Sorry. I'm French. I did'nt understood that the comma was a separation for the groups of 3 digits. In French, the comma is synonymous of the decimal point and we put only a space between groups of 3 digits. – F. Pantigny Jul 21 at 20:24
  • Yes, I suspected! No worry. – John Jul 21 at 20:25
  • @F.Pantigny That's very interesting to see the cultural difference here. Thank you for your reply and for your answer. I will learn from it as much as I can. – veryBigman Jul 21 at 20:26
  • I think that ISO 80000-2 recommend to use point or comma for the decimal separator and space between the groups of 3 digits. – F. Pantigny Jul 21 at 20:32
7

Since you load the dcolumn package, I suggest you make use of its D column type to align (most of) the numbers in the 8 data columns on their decimal markers.

enter image description here

\documentclass[11pt,a4paper]{article}
\usepackage{mathtools,booktabs,array,dcolumn,lscape}
\newcolumntype{d}[1]{D{.}{.}{#1}}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro

\begin{document}
\begin{landscape}
\begin{table}[htbp]
  \centering
  \caption{The Results of Future Abnormal Return}
  \label{tab:addlabel}
  \medskip
    \begin{tabular}{@{} l *{8}{d{2.5}} @{}}
      \toprule
      & \mc{EW1M}& \mc{EW3M}&\mc{EW6M}&\mc{EW12M}&\mc{VW1M} &\mc{VW3M}&\mc{VW6M}&\mc{VW12M}\\
      & \mc{(1)} &\mc{(2)} &\mc{(3)}  & \mc{(4)} & \mc{(5)} & \mc{(6)}& \mc{(7)}& \mc{(8)}\\ 
      \midrule
      Purchaser (NPV) &0.019^{***}&0.021^{***}&0.025^{***}&0.025^{***}&0.017^{***}&0.025^{***}&0.038^{***}&0.060^{***}\\
      &(36.58)&(26.98)&(23.34)&(16.84)&(34.03)&(31.64)&(34.72)&(38.85)\\
      &\mc{130,982}  &\mc{129,738} &\mc{128,316} &\mc{124,121} &\mc{130,982} &\mc{129,738} &\mc{128,316} &\mc{124,121}\\
      \addlinespace
      Purchaser (NPR) &0.019^{***}&0.021^{***}&0.025^{***}&0.025^{***}&0.017^{***}&0.025^{***}&0.038^{***}&0.060^{***}\\
      &(36.57)&(26.99)&(23.37)&(16.89)&(34.03)&(31.64)&(34.72)&(38.85)\\
      &\mc{130,904} &\mc{129,660} &\mc{128,239} &\mc{124,051} &\mc{130,982} &\mc{129,738} &\mc{128,316} &\mc{124,121}\\    
      \bottomrule      
    \end{tabular}
\end{table}
\end{landscape}
\end{document}
  • 1
    Hi Mico. May I ask you a very beginner question? What does {@{} l *{8}{d{2.5}} @{}} mean? I promise, I spent a moderate amount of time to search online, but I could not find a clear explanation. Today is my first day, so I am really struggling. If you know a good website can explain the stuff to me, can you let me know? I want to express my gratitude in advance – veryBigman Jul 21 at 20:07
  • 1
    @veryBigman - l means “left-alignment; d{2.5} means “alignment on the decimal marker, setting aside enough space for two digits before and five digits after the decimal marker; *{8}{...} means “repeat 8 times”; and @{} means “suppress the horizontal padding that would otherwise be inserted to the left of the first column and to the right of the final column”. – Mico Jul 21 at 20:20
6

Maybe the following code. I have put the asterisks in other columns.

\documentclass[11pt,a4paper]{article}
\usepackage{mathtools}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{siunitx}
\usepackage{makecell,graphicx,rotating,array,dcolumn,lscape}
\begin{document}
\newcolumntype{d}[1]{D{.}{.}{#1}}
\def\sym#1{\ensuremath{^{\mathrlap{#1}}}}
\begin{landscape}
{\setlength{\extrarowheight}{1.5pt}
\begin{table}[htbp]
\sisetup{table-align-text-post=false}
  \centering
  \caption{The Results of Future Abnormal Return}
    \begin{tabular}{*{9}{r@{}>{$}l<{$}}}
    \toprule
     \multicolumn{2}{l}{}& \multicolumn{2}{c}{EW1M}& \multicolumn{2}{c}{EW3M}&\multicolumn{2}{c}{EW6M}&\multicolumn{2}{c}{EW12M}&\multicolumn{2}{c}{VW1M} &\multicolumn{2}{c}{VW3M}&\multicolumn{2}{c}{VW6M}&\multicolumn{2}{c}{VW12M}\\
      \multicolumn{2}{c}{} & \multicolumn{2}{c}{(1)} &\multicolumn{2}{c}{(2)} &\multicolumn{2}{c}{(3)}  &       \multicolumn{2}{c}{(4)} & \multicolumn{2}{c}{(5)} & \multicolumn{2}{c}{(6)}& \multicolumn{2}{c}{(7)}& \multicolumn{2}{c}{(8)}\\ \midrule
       Purchaser (NPV) &&0.019&^{***}&0.021&^{***}&0.025&^{***}&0.025&^{***}&0.017&^{***}&0.025&^{***}&0.038&^{***}&0.060&^{***}\\
          &&(36.58)&&(26.98)&&(23.34)&&(16.84)&&(34.03)&&(31.64)&&(34.72)&&(38.85)\\
          &&130,982  &&129,738    &&128,316    &&124,121    &&130,982        &&129,738    &&128,316    &&124,121\\
          Purchaser (NPR) &&0.019&^{***}&0.021&^{***}&0.025&^{***}&0.025&^{***}&0.017&^{***}&0.025&^{***}&0.038&^{***}&0.060&^{***}\\
          &&(36.57)&&(26.99)&&(23.37)&&(16.89)&&(34.03)&&(31.64)&&(34.72)&&(38.85)\\
          &&130,904  &&129,660    &&128,239    &&124,051    &&130,982        &&129,738    &&128,316    &&124,121\\          
    \end{tabular}%
  \label{tab:addlabel}%
\end{table}}
\end{landscape}
\end{document}

The result of the code above

  • Thanks !! This is a very easy way to solve my question. I literally started today, and therefore was not thinking about this. Do you know any better way to do what I want? I mean, give me some general suggestions and I will search online. – veryBigman Jul 21 at 19:57
  • You should use the siunitx's S column type ... it has properties for the text after too. – koleygr Jul 21 at 19:57
4

The solution that I'd posted as a comment to the OP keeps the longer numbers aligned at the decimal digit (if that's what's desired ... )

\documentclass[11pt,a4paper]{article}
\usepackage{mathtools}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{siunitx}
\usepackage{makecell,graphicx,rotating,array,dcolumn,lscape}
\begin{document}
\newcolumntype{d}[1]{D{.}{.}{#1}}
\def\sym#1{\ensuremath{^{\mathrlap{#1}}}}
\begin{landscape}
{\setlength{\extrarowheight}{1.5pt}
\begin{table}[htbp]
\sisetup{table-align-text-post=false}
  \centering
  \caption{The Results of Future Abnormal Return}
    \begin{tabular}{l *{8}{d{3}}} %%<======== aligns all the numbers on the decimal
    \toprule
     \multicolumn{1}{l}{}& \multicolumn{1}{c}{EW1M}& \multicolumn{1}{c}{EW3M}&\multicolumn{1}{c}{EW6M}&\multicolumn{1}{c}{EW12M}&\multicolumn{1}{c}{VW1M} &\multicolumn{1}{c}{VW3M}&\multicolumn{1}{c}{VW6M}&\multicolumn{1}{c}{VW12M}\\
      \multicolumn{1}{c}{} & \multicolumn{1}{c}{(1)} &\multicolumn{1}{c}{(2)} &\multicolumn{1}{c}{(3)}  &       \multicolumn{1}{c}{(4)} & \multicolumn{1}{c}{(5)} & \multicolumn{1}{c}{(6)}& \multicolumn{1}{c}{(7)}& \multicolumn{1}{c}{(8)}\\ \midrule
       Purchaser (NPV) &0.019^{***}&0.021^{***}&0.025^{***}&0.025^{***}&0.017^{***}&0.025^{***}&0.038^{***}&0.060^{***}\\
          &(36.58)&(26.98)&(23.34)&(16.84)&(34.03)&(31.64)&(34.72)&(38.85)\\
          &130,982  &129,738    &128,316    &124,121    &130,982        &129,738    &128,316    &124,121\\
          Purchaser (NPR) &0.019^{***}&0.021^{***}&0.025^{***}&0.025^{***}&0.017^{***}&0.025^{***}&0.038^{***}&0.060^{***}\\
          &(36.57)&(26.99)&(23.37)&(16.89)&(34.03)&(31.64)&(34.72)&(38.85)\\
          &130,904  &129,660    &128,239    &124,051    &130,982        &129,738    &128,316    &124,121\\          
    \end{tabular}%
  \label{tab:addlabel}%
\end{table}}
\end{landscape}
\

end{document} enter image description here

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.