1

I'm very happy with my table so far but there are some problems that I hope someone here can help me with:

  1. Using "***" and "-" causes my numbers to misalign, is it a way to align them?
  2. I can't add another row (or, for some strange reason, add more stars in the last column using ^{**}) without getting an error message when I try to recompile.
  3. Variable Y is not actually centered above the numbers (more obvious when I have the actual numbers in there), is that possible to adjust?
  4. For some reason my variable name get an error-message saying "Missing $ inserted", why is that?

Help would be greatly appreciated!

/Adam

\usepackage[utf8]{inputenc}
\usepackage{dcolumn} 
    \newcolumntype{d}[1]{D..{#1}}
\usepackage[margin=1in]{geometry}
\usepackage{booktabs,caption}
\captionsetup[table]{name=Table} 
\captionsetup{skip=0pt}% no extra space below caption
\usepackage[flushleft]{threeparttable} 
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro

\begin{document}

%------------- Table -----------------------------
\begin{table}[!htbp] 
\centering 
\begin{threeparttable}
\caption{This is a sentence that describes the table} 
\label{table2} 
\begin{tabular}{@{} l *{6}{d{8.3}} @{}} 

\toprule
& \multicolumn{4}{c}{One type} & \multicolumn{2}{c@{}}{Another type} \\ 
\cmidrule(lr){2-5} \cmidrule(l){6-7}
& \mc{(1)} & \mc{(2)} & \mc{(3)} & \mc{(4)} & \mc{(5)} & \mc{(6)} \\ 
\addlinespace
Dep. Var. & \mc{Var Y} & \mc{Var Y} & \mc{Var Y} & \mc{Var Y} & \mc{Var Y} & \mc{Var Y} \\
\midrule

W[p$_{t-1}$]     & \mc{1,000,000^{***}}      & \mc{1,000,000^{**}}   & \mc{1,000,000^{**}}   & \mc{1,000,000^{**}}   & \mc{1,000,000^{**}}   & \mc{1,000,000^{**}}  \\ 
\quad            & \mc{(500,000)}            & \mc{(500,000)}        & \mc{(500,000)}        & \mc{(500,000)}        & \mc{(500,000)}        & \mc{(500,000)}     \\ \addlinespace

W[p$_{t-1}$]$^2$ & \mc{-1,000,000^{***}}    & \mc{-1,000,000^{**}}  & \mc{−1,000,000^{**}}  & \mc{-1,000,000^{**}}  & \mc{-1,000,000^{**}}  & \mc{-1,000,000}  \\
\quad            & \mc{(500,000)}           & \mc{(500,000)}        & \mc{(500,000)}        & \mc{(500,000)}        & \mc{(500,000)}        & \mc{(500,000)}               \\ \addlinespace

W[p$_{t-1}$]$^3$ & \mc{1,000,0004^{***}}    & \mc{1,000,000^{**}}   & \mc{1,000,000^{**}}   &  \mc{1,000,000^{**}}  & \mc{1,000,000^{**}}   & \mc{1,000,000}                  \\ 
\quad            & \mc{(500,000)}           & \mc{(500,000)}        & \mc{(500,000)}        &  \mc{(500,000)}       & \mc{(500,000)}        & \mc{(500,000)}                  \\ 
\addlinespace
\addlinespace

W[p$_{t-1}$]     & \mc{1,000,000^{***}}      & \mc{1,000,000^{**}}   & \mc{1,000,000^{**}}   & \mc{1,000,000^{**}}   & \mc{1,000,000^{**}}   & \mc{1,000,000^{**}}  \\ 
\quad            & \mc{(500,000)}            & \mc{(500,000)}        & \mc{(500,000)}        & \mc{(500,000)}        & \mc{(500,000)}        & \mc{(500,000)}     \\ \addlinespace

W[p$_{t-1}$]$^2$ & \mc{-1,000,000^{***}}    & \mc{-1,000,000^{**}}  & \mc{−1,000,000^{**}}  & \mc{-1,000,000^{**}}  & \mc{-1,000,000^{**}}  & \mc{-1,000,000}  \\
\quad            & \mc{(500,000)}           & \mc{(500,000)}        & \mc{(500,000)}        & \mc{(500,000)}        & \mc{(500,000)}        & \mc{(500,000)}               \\ \addlinespace

W[p$_{t-1}$]$^3$ & \mc{1,000,0004^{***}}    & \mc{1,000,000^{**}}   & \mc{1,000,000^{**}}   &  \mc{1,000,000^{**}}  & \mc{1,000,000^{**}}   & \mc{1,000,000}                  \\ 
\quad            & \mc{(500,000)}           & \mc{(500,000)}        & \mc{(500,000)}        &  \mc{(500,000)}       & \mc{(500,000)}        & \mc{(500,000)}                  \\ 
\addlinespace
\addlinespace

W[p$_{t-1}$]     & \mc{1,000,000^{***}}      & \mc{1,000,000^{**}}   & \mc{1,000,000^{**}}   & \mc{1,000,000^{**}}   & \mc{1,000,000^{**}}   & \mc{1,000,000^{**}}  \\ 
\quad            & \mc{(500,000)}            & \mc{(500,000)}        & \mc{(500,000)}        & \mc{(500,000)}        & \mc{(500,000)}        & \mc{(500,000)}     \\ \addlinespace

W[p$_{t-1}$]$^2$ & \mc{-1,000,000^{***}}    & \mc{-1,000,000^{**}}  & \mc{−1,000,000^{**}}  & \mc{-1,000,000^{**}}  & \mc{-1,000,000^{**}}  & \mc{-1,000,000}  \\
\quad            & \mc{(500,000)}           & \mc{(500,000)}        & \mc{(500,000)}        & \mc{(500,000)}        & \mc{(500,000)}        & \mc{(500,000)}               \\ \addlinespace

W[p$_{t-1}$]$^3$ & \mc{1,000,0004^{***}}    & \mc{1,000,000^{**}}   & \mc{1,000,000^{**}}   &  \mc{1,000,000^{**}}  & \mc{1,000,000^{**}}   & \mc{1,000,000}                  \\ 
\quad            & \mc{(500,000)}           & \mc{(500,000)}        & \mc{(500,000)}        &  \mc{(500,000)}       & \mc{(500,000)}        & \mc{(500,000)}                  \\ 
\addlinespace
\addlinespace

Month           & \mc{Yes}      & \mc{Yes}      & \mc{Yes}      & \mc{Yes}      & \mc{Yes}      & \mc{Yes} \\
Year            & \mc{No}       & \mc{Yes}      & \mc{Yes}      & \mc{Yes}      & \mc{No}       & \mc{Yes} \\

\midrule
Observations    & \mc{10,000}   & \mc{10,000}   & \mc{10,000}   & \mc{10,000}   & \mc{10,000}   & \mc{10,000}  \\ 
Groups          & \mc{150}      & \mc{150}      & \mc{150}      & \mc{150}      & \mc{150}      & \mc{150} \\   
\midrule

{R-squared:} \\
{within}  & \mc{0.150} & \mc{0.150} & \mc{0.150} & \mc{0.150} & \mc{0.150} & \mc{0.150} \\
{between} & \mc{0.150} & \mc{0.150} & \mc{0.150} & \mc{0.150} & \mc{0.150} & \mc{0.150} \\
{overall} & \mc{0.150} & \mc{0.150} & \mc{0.150} & \mc{0.150} & \mc{0.150} & \mc{0.150} \\
\bottomrule 

\end{tabular} 
\begin{tablenotes}
\small 
\item $^{*}\ p<0.05$; $^{**}\ p<0.01$; $^{***}\ p<0.001$.
\end{tablenotes}
\end{threeparttable}
\end{table}
%-------------------------------- End Table ---------------------------------
\end{document}
3
  • 1
    Welcome! Using D columns and overriding each entry with \mc is useless.
    – egreg
    Commented Dec 3, 2020 at 18:09
  • The error message you get is not related to the variable name, but caused by your use of ^ outside of math mode.
    – leandriis
    Commented Dec 3, 2020 at 18:49
  • Regarding all the alignment issue you mention: Do not look at the pdf after you recieved an error message. Even if you get something that on first glance resembles a pdf file, there can still be issues with it. After an error, TeX only tries to recover enough to syntax check more of the file, it does not try to make sensible output after an error. Thus, try to fix the error message(s) first.
    – leandriis
    Commented Dec 3, 2020 at 19:19

1 Answer 1

1

Here is my suggestion based on siunitx:

enter image description here

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{siunitx}
\usepackage[margin=1in]{geometry}
\usepackage{booktabs,caption}
\captionsetup[table]{name=Table} 
\captionsetup{skip=0pt}% no extra space below caption
\usepackage[flushleft]{threeparttable} 

\newcommand{\starone}{\textsuperscript{*}}
\newcommand{\startwo}{\textsuperscript{**}}
\newcommand{\starthree}{\textsuperscript{***}}
\sisetup{input-ignore={,},
         input-decimal-markers={.}, 
         group-separator={,}, 
         input-open-uncertainty = ,
         input-close-uncertainty = ,
         table-align-text-pre = false,
         table-align-text-post = false,}
\begin{document}


\begin{table}[!htbp] 
\centering 
\setlength{\tabcolsep}{2pt}
\begin{threeparttable}
\caption{This is a sentence that describes the table} 
\label{table2} 
\begin{tabular}{@{} l *{6}{S[table-format=-7.0,table-space-text-pre=(, table-space-text-post=\starthree]} @{}} 

\toprule
                 & \multicolumn{4}{c}{One type}                                                        & \multicolumn{2}{c@{}}{Another type} \\ 
\cmidrule(r){2-5} \cmidrule(l){6-7}
                 & {(1)}                & {(2)}              & {(3)}              & {(4)}              & {(5)}              & {(6)} \\ 
\addlinespace
Dep. Var.        & {Var Y}              & {Var Y}            & {Var Y}            & {Var Y}            & {Var Y}            & {Var Y} \\
\midrule
W[p$_{t-1}$]$^2$ & -1,000,000\starthree & -1,000,000\startwo & -1,000,000\startwo & -1,000,000\startwo & -1,000,000\startwo & -1,000,000  
\\
                 & (500,000)            & (500,000)          & (500,000)          & (500,000)          & (500,000)          & (500,000)    \\ 
\addlinespace
Month            & {Yes}                & {Yes}              & {Yes}              & {Yes}              & {Yes}              & {Yes} \\
Year             & {No}                 & {Yes}              & {Yes}              & {Yes}              & {No}               & {Yes} \\
\midrule
Observations     & {10,000}             & {10,000}           & {10,000}           & {10,000}           & {10,000}           & {10,000}  \\ 
Groups           & {150}                & {150}              & {150}              & {150}              & {150}              & {150} \\   
\midrule          
R-squared: \\
within           & {0.150}             & {0.150}             & {0.150}            & {0.150}            & {0.150}            & {0.150} \\
between          & {0.150}             & {0.150}             & {0.150}            & {0.150}            & {0.150}            & {0.150} \\
overall          & {0.150}             & {0.150}             & {0.150}            & {0.150}            & {0.150}            & {0.150} \\
\bottomrule 
\end{tabular} 
\begin{tablenotes}
\small 
\item $^{*}\ p<0.05$; $^{**}\ p<0.01$; $^{***}\ p<0.001$.
\end{tablenotes}
\end{threeparttable}
\end{table}


\end{document}
5
  • Thank you sir, you solved everything! Just one small detail, I do not get an "," if the number is smaller than 10 000, that is, I get 9999, not 9,999, do you know why that is? What cased the problem with the error message for my variable name ("Missing $ inserted")?
    – Adam
    Commented Dec 7, 2020 at 8:06
  • The reason I ask the last question (outside pure curiosity) is because I get that error message when I put the following footnote under a table "\item L42 = 1 if 1.2 \leq W[p$_{t-1}$] $<$ 1.7, else 0"
    – Adam
    Commented Dec 7, 2020 at 10:41
  • If you pleas, I have a few columns that only contains numbers that are less than 10,000; those rows looks a bit misaligned compared to the {Var Y} above them now (looks great when the column contained larger numbers though!). Is there a way to adjust for this?
    – Adam
    Commented Dec 7, 2020 at 10:56
  • @Adam: The missing thousand separator in a 4 digit number such as 1000 can be added back in using \sisetup{group-minimum-digits=4}. The error message is because you used \leq outside of math mode, you can use \item L42 = 1 if 1.2 $\leq W[p_{t-1}] < 1.7$, else 0 instead. If you have table columns that only contain shorter numbers, adjust the value of table-format accordingy. (For a column, that only contains positive numbers with a maximum of 4 places, such as 1000, use table-format=4.0 instead of table-format=-7.0)
    – leandriis
    Commented Dec 7, 2020 at 18:53
  • Thank you, it worked like a charm!
    – Adam
    Commented Dec 9, 2020 at 16:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .