改变字体大小时表格对齐方式会发生变化(STATA 的 etable 输出)

改变字体大小时表格对齐方式会发生变化(STATA 的 etable 输出)

我使用 etable 选项从 STATA 导出了一个表格。我将字体大小更改为极小以使表格适合文档页面并使用了居中选项。但是,这会破坏表格的整个格式。还有其他方法吗?我尝试使用 table、tabularx 和 tabulary。它们似乎都不起作用。任何帮助都将不胜感激

\tiny
\centering
\begin{tabular}{lllllllllll}
\cline{1-11}
\multicolumn{1}{r}{} &
  \multicolumn{2}{c}{Excellent} &
  \multicolumn{2}{c}{V.Good} &
  \multicolumn{2}{c}{Good} &
  \multicolumn{2}{c}{Fair} &
  \multicolumn{2}{c}{Poor} \\
\multicolumn{1}{r}{} &
  \multicolumn{1}{r}{} &
  \multicolumn{1}{r}{} &
  \multicolumn{1}{r}{} &
  \multicolumn{1}{r}{} &
  \multicolumn{1}{r}{} &
  \multicolumn{1}{r}{} &
  \multicolumn{1}{r}{} &
  \multicolumn{1}{r}{} &
  \multicolumn{1}{r}{} &
  \multicolumn{1}{r}{} \\
\cline{1-11}
\multicolumn{1}{l}{Prior heart attack} &
  \multicolumn{1}{r}{-0.301} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{-0.057} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.153} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.137} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.069} &
  \multicolumn{1}{l}{**} \\
\multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.023)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.006)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.012)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.010)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.006)} &
  \multicolumn{1}{l}{} \\
\multicolumn{1}{l}{Number of people in household} &
  \multicolumn{1}{r}{-0.008} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{-0.001} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.004} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.004} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.002} &
  \multicolumn{1}{l}{**} \\
\multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.003)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.000)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.001)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.001)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.001)} &
  \multicolumn{1}{l}{} \\
\multicolumn{1}{l}{Body mass index (BMI)} &
  \multicolumn{1}{r}{-0.006} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{-0.001} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.003} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.003} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.001} &
  \multicolumn{1}{l}{**} \\
\multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.001)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.000)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.000)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.000)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.000)} &
  \multicolumn{1}{l}{} \\
\multicolumn{1}{l}{Diabetes status} &
  \multicolumn{1}{r}{-0.235} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{-0.044} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.119} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.107} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.054} &
  \multicolumn{1}{l}{**} \\
\multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.022)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.005)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.012)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.010)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.005)} &
  \multicolumn{1}{l}{} \\
\multicolumn{1}{l}{30-39} &
  \multicolumn{1}{r}{-0.024} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{0.001} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{0.013} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{0.007} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{0.003} &
  \multicolumn{1}{l}{} \\
\multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.014)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.001)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.008)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.004)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.002)} &
  \multicolumn{1}{l}{} \\
\multicolumn{1}{l}{40-49} &
  \multicolumn{1}{r}{-0.098} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{-0.007} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.057} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.035} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.014} &
  \multicolumn{1}{l}{**} \\
\multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.015)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.003)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.009)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.006)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.002)} &
  \multicolumn{1}{l}{} \\
\multicolumn{1}{l}{50-59} &
  \multicolumn{1}{r}{-0.185} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{-0.043} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.106} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.086} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.036} &
  \multicolumn{1}{l}{**} \\
\multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.012)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.006)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.007)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.007)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.003)} &
  \multicolumn{1}{l}{} \\
\multicolumn{1}{l}{60-69} &
  \multicolumn{1}{r}{-0.237} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{-0.084} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.125} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.133} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.063} &
  \multicolumn{1}{l}{**} \\
\multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.010)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.006)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.006)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.007)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.004)} &
  \multicolumn{1}{l}{} \\
\multicolumn{1}{l}{70+} &
  \multicolumn{1}{r}{-0.248} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{-0.096} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.127} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.146} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.071} &
  \multicolumn{1}{l}{**} \\
\multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.012)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.009)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.006)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.011)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.007)} &
  \multicolumn{1}{l}{} \\
\multicolumn{1}{l}{Black} &
  \multicolumn{1}{r}{-0.165} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{-0.031} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.083} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.075} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.037} &
  \multicolumn{1}{l}{**} \\
\multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.013)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.003)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.007)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.006)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.003)} &
  \multicolumn{1}{l}{} \\
\multicolumn{1}{l}{Female} &
  \multicolumn{1}{r}{-0.039} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{-0.007} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.020} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.018} &
  \multicolumn{1}{l}{**} &
  \multicolumn{1}{r}{0.009} &
  \multicolumn{1}{l}{**} \\
\multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.008)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.002)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.004)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.004)} &
  \multicolumn{1}{l}{} &
  \multicolumn{1}{r}{(0.002)} &
  \multicolumn{1}{l}{} \\
\cline{1-11}
\end{tabular}

\footnotesize{
** p$<$.01, * p$<$.05
}

答案1

将数据导出到 R 并使用其插件会更容易kable(请参阅手动的),它可以生成相当不错的表格。

所生成的代码的问题在于列太多导致表格太宽。这就是为什么您必须使用非常小的字体才能适应它。另一个问题与代码有关,因为它包含大量冗余内容。

在下面的示例中,有两个宏\pone和,\ptwo它们添加了注释——请参见第一个值。我注意到,p < 0.05除了一行之外,整个表格都报告了相同的内容。报告不是的内容不是更容易吗p < 0.05?作为示例,我在该行中放了一个“匕首”,并注释了它的含义。还有一个自定义长度,它控制主要值之间的间距并将具有不确定性的统计数据放在一起。

代码:

\documentclass{article}
\usepackage{array}
\usepackage{booktabs}

\newcommand\pone{\rlap{\textsuperscript{*}}}
\newcommand\ptwo{\rlap{\textsuperscript{**}}}
\newlength\vdist\setlength\vdist{4pt}
\setlength\cmidrulewidth{0.3pt}


\begin{document}
\begin{table}[tbh]
  \setlength\tabcolsep{9pt}
  \newcommand\xth[1]{\makebox[0pt][c]{\normalsize#1}}
  %
  \small
  \centering
  \caption{Caption}\label{tab:label-for-table}
  \vspace{3pt}
  \begin{tabular}{@{}l @{\hspace{2em}} *5{c} @{}}
    \toprule
    & \xth{Excellent} & \xth{V. Good} & \xth{Good} & \xth{Fair} & \xth{Poor} \\
    \midrule
    Prior heart attack
    & -0.301\ptwo  & -0.057  & 0.153   & 0.137   & 0.069 \\
    & (0.023) & (0.006) & (0.012) & (0.010) & (0.006) \\ \addlinespace[\vdist]
    Number of people in
    & -0.008  & -0.001  & 0.004   & 0.004   & 0.002 \\
    household & (0.003) & (0.000) & (0.001) & (0.001) & (0.001) \\ \addlinespace[\vdist] 
    Body mass index (BMI)
    & -0.006  & -0.001  & 0.003   & 0.003   & 0.001 \\
    & (0.001) & (0.000) & (0.000) & (0.000) & (0.000) \\ \addlinespace[\vdist] 
    Diabetes status
    & -0.235  & -0.044  & 0.119   & 0.107   & 0.054 \\
    & (0.022) & (0.005) & (0.012) & (0.010) & (0.005) \\ \cmidrule{2-6}
    30-39$^{\dag}$
    & -0.024  & 0.001   & 0.013   & 0.007   & 0.003 \\
    & (0.014) & (0.001) & (0.008) & (0.004) & (0.002) \\ \addlinespace[\vdist] 
    40-49
    & -0.098  & -0.007  & 0.057   & 0.035   & 0.014 \\
    & (0.015) & (0.003) & (0.009) & (0.006) & (0.002) \\ \addlinespace[\vdist] 
    50-59
    & -0.185  & -0.043  & 0.106   & 0.086   & 0.036 \\
    & (0.012) & (0.006) & (0.007) & (0.007) & (0.003) \\ \addlinespace[\vdist] 
    60-69
    & -0.237  & -0.084  & 0.125   & 0.133   & 0.063 \\
    & (0.010) & (0.006) & (0.006) & (0.007) & (0.004) \\ \addlinespace[\vdist] 
    70+
    & -0.248  & -0.096  & 0.127   & 0.146   & 0.071 \\
    & (0.012) & (0.009) & (0.006) & (0.011) & (0.007) \\ \cmidrule{2-6}
    Black
    & -0.165  & -0.031  & 0.083   & 0.075   & 0.037 \\
    & (0.013) & (0.003) & (0.007) & (0.006) & (0.003) \\  \addlinespace[\vdist]
    Female
    & -0.039  & -0.007  & 0.020   & 0.018   & 0.009 \\
    & (0.008) & (0.002) & (0.004) & (0.004) & (0.002) \\
    \bottomrule
    \multicolumn{6}{@{}l}{\footnotesize $^{\dag}$ $p < 0.05$ except for this row}\\
  \end{tabular}
\end{table}
\end{document}

在此处输入图片描述

相关内容