表格帮助(对齐和“插入缺失$”)!

表格帮助(对齐和“插入缺失$”)!

到目前为止,我对我的桌子非常满意,但也存在一些问题,希望有人能帮助我解决:

  1. 使用“***”和“-”会导致我的数字错位,有没有办法使它们对齐?
  2. 我无法添加另一行(或者,由于某些奇怪的原因,使用 ^{**} 在最后一列添加更多星星),而不会在尝试重新编译时收到错误消息。
  3. 变量 Y 实际上并不位于数字上方的中心(当我有实际数字时更加明显),可以调整吗?
  4. 由于某种原因,我的变量名出现一条错误消息,提示“缺少插入$”,这是为什么?

非常感谢您的帮助!

/亚当

\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}

答案1

这是我的建议,基于siunitx

在此处输入图片描述

\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}

相关内容