系数对齐问题

系数对齐问题

我对此表中系数的对齐方式有疑问。我尝试使用几何包修改边距,但没有成功。我真的不知道该怎么办!我使用 Stata 中的命令 esttab 从以 .tex 格式保存的原始版本修改了此表。我只想让每个数字都对齐。

为了便于阅读,我也在 pastebin 上提供了它。 https://pastebin.com/chH9uvGD

\documentclass[12,legalpaper]{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\begin{document}
    \begin{table}
\raggedleft{\caption{Explaining imperfect representation through costs and benefits}}
{
    \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
        \begin{tabular}{l*{2}{cc}}
        \hline\hline
        \\
                                 &   \multicolumn{4}{c}{Dep. variable: Quality of representation}             \\
                                 &                                                             \\
                                 & Misrepresented    &          &      Indifferent  &          \\
                                 &  \cline{1-4}      &          &                   &          \\
                                 &   Odds Ratio      &     SE   &      Odds Ratio   &   SE     \\
\hline
\\
\textit{Benefits}                                                                              \\
\\
Positive evaluation                &     1.245\sym{***}&  (0.0750)&     1.156\sym{***}&  (0.0459)\\
EU economic policy influence       &     1.015         &  (0.0302)&     1.001         &  (0.0205)\\
\\
\textit{Costs}                                                                              \\
\\
Immigration should decrease        &     0.830\sym{***}&  (0.0364)&     1.007         &  (0.0307)\\
EP doesn't consider citiz. concerns&     0.874\sym{**} &  (0.0451)&     1.022         &  (0.0357)\\
\\
\textit{Context}                                                                              \\
\\
New EU12                           &     0.937         &  (0.0947)&     1.715\sym{***}&   (0.116)\\
EU spending(log)                   &     0.993         &  (0.0510)&     0.953         &  (0.0342)\\
N dimensions party competition     &     0.874\sym{*}  &  (0.0514)&     1.031         &  (0.0401)\\
\\
\textit{Salience}                                                                              \\
\\
My voice counts                    &     0.541\sym{***}&  (0.0675)&     0.967         &  (0.0677)\\
EU deals with imp issues           &     1.003         &  (0.0684)&     0.921         &  (0.0435)\\
Cares which party wins EP elections&     1.104\sym{*}  &  (0.0433)&     1.023         &  (0.0268)\\
Feels European                     &     1.284\sym{**} &  (0.118) &     1.221\sym{***}&  (0.0734)\\
\\
\textit{Controls}                                                                              \\
\\
Education                          &     1.064         &  (0.0491)&     0.945         &  (0.0299)\\
Standard of living                 &     0.919         &  (0.0763)&     0.884\sym{*}  &  (0.0492)\\
Neither left nor right             &     1.127         &  (0.0784)&     1.018         &  (0.0493)\\
Evaluation of govt econ performance&     0.934         &  (0.0349)&     1.037         &  (0.0268)\\
Watch election news on TV          &     0.921         &  (0.0469)&     0.946         &  (0.0332)\\
How many days follows news         &     1.095         &  (0.0713)&     1.221\sym{***}&  (0.0528)\\
\hline
Pseudo R-Square                  &    0.0227         &          &                   &          \\
$\chi^2 $                            &     395.3         &          &                   &          \\
P                                &  0.000000         &          &                   &          \\
\hline\hline
\multicolumn{5}{l}{\footnotesize Exponentiated coefficients; Standard errors in parentheses}\\
\multicolumn{5}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
        \end{tabular}
}
    \end{table}
\end{document}

答案1

为了将数据列中的数字与各自的小数点对齐,我建议您加载dcolumn包及其D列类型。或者,加载siunitx包并使用其S列类型;请参阅@leandriis 的回答以供实施。

我还想建议您使用booktabs包的线条绘制宏,而不是基本\hline\cline指令。并且,为了将标题的开头与环境的左边缘对齐tabular,我建议您使用threeparttable包及其同名环境。

在此处输入图片描述

\documentclass[12pt,legalpaper]{article} % not "12", but "12pt"
\usepackage[margin=1in]{geometry} % choose suitable page parameters
\usepackage{amsmath,amsfonts,amssymb}
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}

\usepackage{dcolumn,booktabs,caption,threeparttable}
\newcolumntype{d}[1]{D..{#1}}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}}
\begin{document}

\begin{table}
\centering
\captionsetup{singlelinecheck=false,
              justification=raggedright,
              skip=0.333\baselineskip}
\begin{threeparttable}
\caption{Explaining imperfect representation through costs and benefits}
\begin{tabular}{@{} l*{4}{d{2.5}}@{}}
\toprule
& \multicolumn{4}{c@{}}{Dep. variable: Quality of representation} \\
\cmidrule(l){2-5}
  & \multicolumn{2}{c}{Misrepresented} 
  & \multicolumn{2}{c@{}}{Indifferent}\\
\cmidrule(lr){2-3} \cmidrule(l){4-5}
  & \mc{Odds Ratio} & \mc{SE} 
  & \mc{Odds Ratio} & \multicolumn{1}{c@{}}{SE} \\
\midrule
\textit{Benefits} \\ \addlinespace
Positive evaluation                &     1.245\sym{***}&  (0.0750)&     1.156\sym{***}&  (0.0459)\\
EU economic policy influence       &     1.015         &  (0.0302)&     1.001         &  (0.0205)\\
\\
\textit{Costs} \\ \addlinespace
Immigration should decrease        &     0.830\sym{***}&  (0.0364)&     1.007         &  (0.0307)\\
EP doesn't consider citiz.\ concerns&    0.874\sym{**} &  (0.0451)&     1.022         &  (0.0357)\\
\\
\textit{Context}  \\ \addlinespace
New EU12                           &     0.937         &  (0.0947)&     1.715\sym{***}&   (0.116)\\
EU spending(log)                   &     0.993         &  (0.0510)&     0.953         &  (0.0342)\\
N dimensions party competition     &     0.874\sym{*}  &  (0.0514)&     1.031         &  (0.0401)\\
\\
\textit{Salience} \\ \addlinespace
My voice counts                    &     0.541\sym{***}&  (0.0675)&     0.967         &  (0.0677)\\
EU deals with imp issues           &     1.003         &  (0.0684)&     0.921         &  (0.0435)\\
Cares which party wins EP elections&     1.104\sym{*}  &  (0.0433)&     1.023         &  (0.0268)\\
Feels European                     &     1.284\sym{**} &  (0.118) &     1.221\sym{***}&  (0.0734)\\
\\
\textit{Controls} \\ \addlinespace
Education                          &     1.064         &  (0.0491)&     0.945         &  (0.0299)\\
Standard of living                 &     0.919         &  (0.0763)&     0.884\sym{*}  &  (0.0492)\\
Neither left nor right             &     1.127         &  (0.0784)&     1.018         &  (0.0493)\\
Evaluation of govt econ performance&     0.934         &  (0.0349)&     1.037         &  (0.0268)\\
Watch election news on TV          &     0.921         &  (0.0469)&     0.946         &  (0.0332)\\
How many days follows news         &     1.095         &  (0.0713)&     1.221\sym{***}&  (0.0528)\\
\midrule
Pseudo R-Squared    &    \mc{0.0227}\\
$\chi^2 $           &    \mc{395.3} \\
P                   & \mc{0.000000} \\
\bottomrule
\addlinespace
\multicolumn{5}{@{}l}{\footnotesize Exponentiated coefficients; Standard errors in parentheses.}\\
\multicolumn{5}{@{}l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
\end{tabular}
\end{threeparttable}
\end{table}
\end{document}

答案2

在以下 MWE 中,我使用tabularx来使表格与文本宽度一样宽,方法是在第一列引入自动换行符。此外,我使用 来siunitx对齐数字:(右侧的垂直线表示文本宽度的宽度)

\documentclass[legalpaper]{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{tabularx}
\usepackage{ragged2e}
\usepackage{siunitx}
\sisetup{input-symbols = ()}
\sisetup{table-space-text-post = \sym{***}}

\begin{document}
    \begin{table}
\raggedleft{\caption{Explaining imperfect representation through costs and benefits}}
{
    \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
        \begin{tabularx}{\textwidth}{>{\RaggedRight}X*{2}{S[,table-format=1.4,table-align-text-post=false]S[table-format=2.5,table-align-text-post=false]}}
        \hline\hline
        \\
                                 &   \multicolumn{4}{c}{Dep. variable: Quality of representation}             \\
                                 &                                                             \\
                                 & \multicolumn{2}{c}{Misrepresented}              &      \multicolumn{2}{c}{Indifferent}            \\
                                 &  \cline{1-4}      &          &                   &          \\
                                 &   {Odds Ratio}      &     {SE}   &      {Odds Ratio}   &   {SE}     \\
\hline
\\
\textit{Benefits}                                                                              \\
\\
Positive evaluation                &     1.245\sym{***}&  (0.0750)&     1.156\sym{***}&  (0.0459)\\
EU economic policy influence       &     1.015         &  (0.0302)&     1.001         &  (0.0205)\\
\\
\textit{Costs}                                                                              \\
\\
Immigration should decrease        &     0.830\sym{***}&  (0.0364)&     1.007         &  (0.0307)\\
EP doesn't consider citiz. concerns&     0.874\sym{**} &  (0.0451)&     1.022         &  (0.0357)\\
\\
\textit{Context}                                                                              \\
\\
New EU12                           &     0.937         &  (0.0947)&     1.715\sym{***}&   (0.116)\\
EU spending(log)                   &     0.993         &  (0.0510)&     0.953         &  (0.0342)\\
N dimensions party competition     &     0.874\sym{*}  &  (0.0514)&     1.031         &  (0.0401)\\
\\
\textit{Salience}                                                                              \\
\\
My voice counts                    &     0.541\sym{***}&  (0.0675)&     0.967         &  (0.0677)\\
EU deals with imp issues           &     1.003         &  (0.0684)&     0.921         &  (0.0435)\\
Cares which party wins EP elections&     1.104\sym{*}  &  (0.0433)&     1.023         &  (0.0268)\\
Feels European                     &     1.284\sym{**} &  (0.118) &     1.221\sym{***}&  (0.0734)\\
\\
\textit{Controls}                                                                              \\
\\
Education                          &     1.064         &  (0.0491)&     0.945         &  (0.0299)\\
Standard of living                 &     0.919         &  (0.0763)&     0.884\sym{*}  &  (0.0492)\\
Neither left nor right             &     1.127         &  (0.0784)&     1.018         &  (0.0493)\\
Evaluation of govt econ performance&     0.934         &  (0.0349)&     1.037         &  (0.0268)\\
Watch election news on TV          &     0.921         &  (0.0469)&     0.946         &  (0.0332)\\
How many days follows news         &     1.095         &  (0.0713)&     1.221\sym{***}&  (0.0528)\\
\hline
Pseudo R-Square                  &    {0.0227}         &          &                   &          \\
$\chi^2 $                            &     {395.3}         &          &                   &          \\
P                                &  {0.000000}         &          &                   &          \\
\hline\hline
\multicolumn{5}{l}{\footnotesize Exponentiated coefficients; Standard errors in parentheses}\\
\multicolumn{5}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
        \end{tabularx}
}
    \end{table}


\end{document}

在此处输入图片描述


就我个人而言,我还会使用包中的水平线booktabs,并用以下命令替换一些空白行\addlinespace

    \documentclass[legalpaper]{article}

    \usepackage{amsmath}
    \usepackage{amsfonts}
    \usepackage{amssymb}
    \usepackage{tabularx}
    \usepackage{ragged2e}
    \usepackage{booktabs}
    \usepackage{siunitx}
    \sisetup{input-symbols = ()}
    \sisetup{table-space-text-post = \sym{***}}

    \usepackage{lipsum}
    \begin{document}
        \begin{table}
    \raggedleft{\caption{Explaining imperfect representation through costs and benefits}}
    {
        \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
            \begin{tabularx}{\textwidth}{>{\RaggedRight}X*{2}{S[,table-format=1.4,table-align-text-post=false]S[table-format=2.5,table-align-text-post=false]}}
            \toprule
                                     &   \multicolumn{4}{c}{Dep. variable: Quality of representation}             \\

                                     & \multicolumn{2}{c}{Misrepresented}              &      \multicolumn{2}{c}{Indifferent}            \\
                                     \cmidrule{2-5}
                                     &   {Odds Ratio}      &     {SE}   &      {Odds Ratio}   &   {SE}     \\
    \midrule
    \textit{Benefits}\\ \addlinespace
    Positive evaluation                &     1.245\sym{***}&  (0.0750)&     1.156\sym{***}&  (0.0459)\\
    EU economic policy influence       &     1.015         &  (0.0302)&     1.001         &  (0.0205)\\
    \\
    \textit{Costs}\\ \addlinespace
    Immigration should decrease        &     0.830\sym{***}&  (0.0364)&     1.007         &  (0.0307)\\
    EP doesn't consider citiz. concerns&     0.874\sym{**} &  (0.0451)&     1.022         &  (0.0357)\\
    \\
    \textit{Context} \\ \addlinespace
    New EU12                           &     0.937         &  (0.0947)&     1.715\sym{***}&   (0.116)\\
    EU spending(log)                   &     0.993         &  (0.0510)&     0.953         &  (0.0342)\\
    N dimensions party competition     &     0.874\sym{*}  &  (0.0514)&     1.031         &  (0.0401)\\
    \\
    \textit{Salience} \\ \addlinespace
    My voice counts                    &     0.541\sym{***}&  (0.0675)&     0.967         &  (0.0677)\\
    EU deals with imp issues           &     1.003         &  (0.0684)&     0.921         &  (0.0435)\\
    Cares which party wins EP elections&     1.104\sym{*}  &  (0.0433)&     1.023         &  (0.0268)\\
    Feels European                     &     1.284\sym{**} &  (0.118) &     1.221\sym{***}&  (0.0734)\\
    \\
    \textit{Controls}\\ \addlinespace
    Education                          &     1.064         &  (0.0491)&     0.945         &  (0.0299)\\
    Standard of living                 &     0.919         &  (0.0763)&     0.884\sym{*}  &  (0.0492)\\
    Neither left nor right             &     1.127         &  (0.0784)&     1.018         &  (0.0493)\\
    Evaluation of govt econ performance&     0.934         &  (0.0349)&     1.037         &  (0.0268)\\
    Watch election news on TV          &     0.921         &  (0.0469)&     0.946         &  (0.0332)\\
    How many days follows news         &     1.095         &  (0.0713)&     1.221\sym{***}&  (0.0528)\\
    \midrule
    Pseudo R-Square                  &    {0.0227}         &          &                   &          \\
    $\chi^2 $                            &     {395.3}         &          &                   &          \\
    P                                &  {0.000000}         &          &                   &          \\
    \bottomrule
    \multicolumn{5}{l}{\footnotesize Exponentiated coefficients; Standard errors in parentheses}\\
    \multicolumn{5}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
            \end{tabularx}
    }
        \end{table}


    \end{document}

在此处输入图片描述


12最后,请注意,我从 documentclass 中删除了不正确的选项。您可能想改用12pt后者。如果您使用后一个选项,您的表格很可能不再适合一页,因此您可能需要允许分页符或对表格内容使用较小的字体大小。


在下面的例子中,我暂时减小了文本两侧的边距,以便水平居中原本过宽的表格。(表格下方的短文本由\lipsum包生成lipsum,以显示文本宽度。)您还可以减小表格中的字体大小,并使用较小的宽度作为 的参数adjustwidth

\documentclass[legalpaper]{article}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{booktabs}
\usepackage{siunitx}
\sisetup{input-symbols = ()}
\sisetup{table-space-text-post = \sym{***}}
\usepackage{changepage}
\usepackage{lipsum}

\begin{document}
\lipsum[4]
    \begin{table}
\raggedleft{\caption{Explaining imperfect representation through costs and benefits}}

    \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{adjustwidth}{-0.12\textwidth}{-0.12\textwidth}
        \begin{tabular}{l*{2}{S[,table-format=1.4,table-align-text-post=false]S[table-format=2.5,table-align-text-post=false]}}
        \toprule
                                 &   \multicolumn{4}{c}{Dep. variable: Quality of representation}             \\

                                 & \multicolumn{2}{c}{Misrepresented}              &      \multicolumn{2}{c}{Indifferent}            \\
                                 \cmidrule{2-5}
                                 &   {Odds Ratio}      &     {SE}   &      {Odds Ratio}   &   {SE}     \\
\midrule
\textit{Benefits}\\ \addlinespace
Positive evaluation                &     1.245\sym{***}&  (0.0750)&     1.156\sym{***}&  (0.0459)\\
EU economic policy influence       &     1.015         &  (0.0302)&     1.001         &  (0.0205)\\
\\
\textit{Costs}\\ \addlinespace
Immigration should decrease        &     0.830\sym{***}&  (0.0364)&     1.007         &  (0.0307)\\
EP doesn't consider citiz. concerns&     0.874\sym{**} &  (0.0451)&     1.022         &  (0.0357)\\
\\
\textit{Context} \\ \addlinespace
New EU12                           &     0.937         &  (0.0947)&     1.715\sym{***}&   (0.116)\\
EU spending(log)                   &     0.993         &  (0.0510)&     0.953         &  (0.0342)\\
N dimensions party competition     &     0.874\sym{*}  &  (0.0514)&     1.031         &  (0.0401)\\
\\
\textit{Salience} \\ \addlinespace
My voice counts                    &     0.541\sym{***}&  (0.0675)&     0.967         &  (0.0677)\\
EU deals with imp issues           &     1.003         &  (0.0684)&     0.921         &  (0.0435)\\
Cares which party wins EP elections&     1.104\sym{*}  &  (0.0433)&     1.023         &  (0.0268)\\
Feels European                     &     1.284\sym{**} &  (0.118) &     1.221\sym{***}&  (0.0734)\\
\\
\textit{Controls}\\ \addlinespace
Education                          &     1.064         &  (0.0491)&     0.945         &  (0.0299)\\
Standard of living                 &     0.919         &  (0.0763)&     0.884\sym{*}  &  (0.0492)\\
Neither left nor right             &     1.127         &  (0.0784)&     1.018         &  (0.0493)\\
Evaluation of govt econ performance&     0.934         &  (0.0349)&     1.037         &  (0.0268)\\
Watch election news on TV          &     0.921         &  (0.0469)&     0.946         &  (0.0332)\\
How many days follows news         &     1.095         &  (0.0713)&     1.221\sym{***}&  (0.0528)\\
\midrule
Pseudo R-Square                  &    {0.0227}         &          &                   &          \\
$\chi^2 $                            &     {395.3}         &          &                   &          \\
P                                &  {0.000000}         &          &                   &          \\
\bottomrule
\multicolumn{5}{l}{\footnotesize Exponentiated coefficients; Standard errors in parentheses}\\
\multicolumn{5}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
        \end{tabular}

\end{adjustwidth}
    \end{table}


\end{document}

在此处输入图片描述

相关内容