对齐小数点和标题

对齐小数点和标题
\documentclass[12pt]{article}
\usepackage[portuguese]{babel}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{subfig}
\usepackage[flushleft]{threeparttable}
\usepackage{booktabs}
\usepackage[nodisplayskipstretch]{setspace}
\usepackage{amssymb}
\usepackage{setspace}
\usepackage[section]{placeins}
\usepackage{dcolumn}
\usepackage{siunitx,booktabs}
\usepackage{url}
\usepackage{float}
\usepackage{subcaption}
\usepackage{tabularx}
\usepackage{adjustbox}
\usepackage{rotating}
\usepackage{lipsum}
\usepackage{amsmath}
\usepackage{geometry}
\usepackage[tableposition=top]{caption}
\usepackage{babel}
\usepackage[style=authoryear]{biblatex}
\geometry{
a4paper,
total={140mm,190mm},
}
\usepackage[T1]{fontenc}

\newcolumntype{d}[1]{D{.}{.}{#1}}

\begin{document} 
   \begin{table}[!htb]
    \centering

    \caption{Model results}
    \begin{adjustbox}{max width=\textwidth}
    \begin{tabular}{ld{2.4}d{2.4}d{2.4}d{2.4}d{2.4}d{2.4}}
    \hline
    Link &  \multicolumn{1}{c}{Logit} &  & \multicolumn{1}{c}{Probit} &  & \multicolumn{1}{c}{Cloglog} &\\
    \hline
    Parameter &Mean &Sd & Mean & Sd & Mean &Sd  \\
    \hline
    $\beta_0$ &-0,6229 &0,2370 &-0,3853 &0,1425 &-0,8401 &0,1931  \\
    $\beta_1$ &-0,0123 &0,0033 &-0,0072 &0,0019&-0,0107 &0,0027  \\
    $\beta_2$  &0,1184 &0,0379 &0,0688 &0,0234 &0,1027 &0,0314 \\
    $\phi$  &33,0987 &7,6123 &32,4051 &7,6602 &33,8460 &8,0493 \\
    \hline
    Credible Interval & & & & & &\\
    \hline
    Parameter &  2.5\% & 97.5\% & 2.5\% & 97.5\% & 2.5\% & 97.5\%  \\
    \hline
    $\beta_0$ &-1,1034 &-0,1601 &-0,6631 &-0,1042 &-1,2247 &-0,4598 \\
    $\beta_1$  &-0,0186 &-0,0056 &-0,0112 &-0,0034 &-0,0159 &-0,0050 \\
    $\beta_2$  & 0,0443 &0,1933 &0,0219 &0,1134 & 0,0415&0,1627 \\
    $\phi$  &19,6661 &49,6969 & 19,0686 &49,1156 &20,1797&51,8046 \\
    \hline
    \end{tabular}
    \end{adjustbox}
    \end{table}
\end{document}

参数 2.5%、97.5% 等的值与平均值和标准差不一致。

答案1

这里有两个解决方案,一个是使用siunitx(使用 时似乎会发生奇怪的事情dcolumn)。在第二个解决方案中,我使用了 booktabs,没有任何垂直线,以获得更专业的外观。在这两个解决方案中,我删除了环境adjustwidth,它不应该与表格一起使用。另外,请注意包subfig andsubcaption` 不兼容。更喜欢后者。

\documentclass[12pt, portuguese]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{graphicx}
\usepackage{mathtools}
\usepackage[flushleft]{threeparttable}
\usepackage[nodisplayskipstretch]{setspace}
\usepackage{amssymb}
\usepackage{setspace}
\usepackage[section]{placeins}
\usepackage{siunitx,booktabs}
\usepackage{url}
\usepackage{float}
\usepackage{tabularx}
\usepackage{adjustbox}
\usepackage{rotating}
\usepackage{lipsum}
\usepackage{geometry}
\usepackage[tableposition=top]{caption}
\usepackage{subcaption}
\usepackage[style=authoryear]{biblatex}
\geometry{
a4paper,
total={140mm,190mm},
}

\newcolumntype{d}[1]{D{.}{.}{#1}}

\begin{document}

   \begin{table}[!htb]
    \centering
    \caption{Model results}
\sisetup{table-format = -1.4, table-number-alignment=center}
    \begin{tabular}{l|*{6}{S|}}
    \hline
    Link & \multicolumn{2}{c|}{Logit} &\multicolumn{2}{c|}{Probit} & \multicolumn{2}{c|}{Cloglog}\\
    \hline
    Parameter &{Mean} &{Sd} & {Mean} & {Sd }& {Mean} & {Sd} \\
    \hline
    $\beta_0$ &-0,6229 &0,2370 &-0,3853 &0,1425 &-0,8401 &0,1931 \\
    $\beta_1$ &-0,0123 &0,0033 &-0,0072 &0,0019&-0,0107 &0,0027 \\
    $\beta_2$ &0,1184 &0,0379 &0,0688 &0,0234 &0,1027 &0,0314 \\
    $\phi$ &33,0987 &7,6123 &32,4051 &7,6602 &33,8460 &8,0493 \\
    \hline
    Credible Interval & & & & & &\\
    \hline
    Parameter & \SI{2.5}{\%} & \SI{97.5}{\%} & \SI{2.5}{\%} & \SI{97.5}{\%} & \SI{2.5}{\%} & \SI{97.5}{\%} \\
    \hline
    $\beta_0$ &-1,1034 &-0,1601 &-0,6631 &-0,1042 &-1,2247 &-0,4598 \\
    $\beta_1$ &-0,0186 &-0,0056 &-0,0112 &-0,0034 &-0,0159 &-0,0050 \\
    $\beta_2$ & 0,0443 &0,1933 &0,0219 &0,1134 & 0,0415&0,1627 \\
    $\phi$ &19,6661 &49,6969 & 19,0686 &49,1156 &20,1797&51,8046 \\
    \hline
    \end{tabular}
    \end{table}

   \begin{table}[!htb]
    \centering
    \caption{Model results}
\sisetup{table-format = -1.4, table-number-alignment=center}
    \begin{tabular}{l*{6}{S}}
    \toprule
    Link & \multicolumn{2}{c}{Logit} &\multicolumn{2}{c}{Probit} & \multicolumn{2}{c}{Cloglog}\\
    \cmidrule{1-7}
    Parameter &{Mean} &{Sd} & {Mean} & {Sd }& {Mean} & {Sd} \\
    \midrule
    $\beta_0$ &-0,6229 &0,2370 &-0,3853 &0,1425 &-0,8401 &0,1931 \\
    $\beta_1$ &-0,0123 &0,0033 &-0,0072 &0,0019&-0,0107 &0,0027 \\
    $\beta_2$ &0,1184 &0,0379 &0,0688 &0,0234 &0,1027 &0,0314 \\
    $\phi$ &33,0987 &7,6123 &32,4051 &7,6602 &33,8460 &8,0493 \\
    \midrule
    Credible Interval \\
    \cmidrule{1-7}
    Parameter & \SI{2.5}{\%} & \SI{97.5}{\%} & \SI{2.5}{\%} & \SI{97.5}{\%} & \SI{2.5}{\%} & \SI{97.5}{\%} \\
    \midrule
    $\beta_0$ &-1,1034 &-0,1601 &-0,6631 &-0,1042 &-1,2247 &-0,4598 \\
    $\beta_1$ &-0,0186 &-0,0056 &-0,0112 &-0,0034 &-0,0159 &-0,0050 \\
    $\beta_2$ & 0,0443 &0,1933 &0,0219 &0,1134 & 0,0415&0,1627 \\
    $\phi$ &19,6661 &49,6969 & 19,0686 &49,1156 &20,1797&51,8046 \\%
    \bottomrule
    \end{tabular}
    \end{table}

\end{document} 

在此处输入图片描述

答案2

这是一个继续使用dcolumn包及其d列类型的解决方案。

由于您似乎使用,(逗号) 作为输出小数点标记,我建议将其替换\newcolumntype{d}[1]{D{.}{.}{#1}}\newcolumntype{d}[1]{D{,}{,}{#1}}。由于您booktabs无论如何都在使用该包,因此我还重新组织了表格的外观,使其看起来更加开放:请注意,没有垂直线,并且存在较少但间距更好的水平线。

在此处输入图片描述

\documentclass[12pt]{article}
% I've stripped down the preamble to the bare mininum
\usepackage[portuguese]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{dcolumn,booktabs,geometry}
\geometry{a4paper,total={140mm,190mm}}
\usepackage[skip=0.333\baselineskip]{caption}

\newcolumntype{d}[1]{D{,}{,}{#1}} $ commas, not periods
\newcommand\mr[1]{\multicolumn{1}{r}{#1}} % handy shortcut macro

\begin{document} 
\begin{table}[!htb]
    \centering
    \caption{Model results}
    \begin{tabular}{@{}l*{6}{d{2.4}}@{}}
    \toprule
    Link &  \multicolumn{2}{c}{Logit} & \multicolumn{2}{c}{Probit} & \multicolumn{2}{c}{Cloglog} \\
    \cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(l){6-7}
    Parameter &\mr{Mean} &\mr{Sd} &\mr{Mean} &\mr{Sd} &\mr{Mean} &\multicolumn{1}{r@{}}{Sd}   \\
    \midrule
    $\beta_0$ &-0,6229 &0,2370 &-0,3853 &0,1425 &-0,8401 &0,1931  \\
    $\beta_1$ &-0,0123 &0,0033 &-0,0072 &0,0019&-0,0107 &0,0027  \\
    $\beta_2$  &0,1184 &0,0379 &0,0688 &0,0234 &0,1027 &0,0314 \\
    $\phi$  &33,0987 &7,6123 &32,4051 &7,6602 &33,8460 &8,0493 \\

    \addlinespace
    &\multicolumn{6}{c@{}}{Confidence Interval Bounds} \\
    \cmidrule(l){2-7}
    &  \mr{2.5\%} & \mr{97.5\%} & \mr{2.5\%} & \mr{97.5\%} &\mr{2.5\%} & \multicolumn{1}{r@{}}{97.5\%} \\
    \midrule
    $\beta_0$ &-1,1034 &-0,1601 &-0,6631 &-0,1042 &-1,2247 &-0,4598 \\
    $\beta_1$  &-0,0186 &-0,0056 &-0,0112 &-0,0034 &-0,0159 &-0,0050 \\
    $\beta_2$  & 0,0443 &0,1933 &0,0219 &0,1134 & 0,0415&0,1627 \\
    $\phi$  &19,6661 &49,6969 & 19,0686 &49,1156 &20,1797&51,8046 \\
    \bottomrule
    \end{tabular}
\end{table}
\end{document}

相关内容