格式化表格,按第一个点对齐非数字值

格式化表格,按第一个点对齐非数字值

我正在尝试格式化下表,使其按每个数字的第一个点对齐。但是,由于它有多种类型的数据(数字和非数字),因此以下问题中提供的解决方案 表格格式使用 S 列对齐表格中的数字和分离的不确定性, 和在表格中沿点对齐渲染不适合我的问题。

有人可以指导我如何调整引用问题中提供的解决方案或提供新的解决方案吗?谢谢。

\documentclass[12pt]{article}
\begin{document}
\begin{table}
\begin{tabular}{lrr}
  \hline
Variables & LC-MIXL $(\delta=0.5)$ & LC-MIXL $(\delta=1)$ \\ 
  \hline
$x_{1} (\mu_{1})$ &     0.982( 0.038)*** &     1.900(0.065)*** \\ 
  $x_{1} (\mu_{2})$ &     2.106( 0.095)*** &     0.987(0.029)*** \\ 
  $x_{1} (\mu_{3})$ &     1.500( 0.052)*** &     3.116(0.119)*** \\ \hline
  $x_{1} (\sigma_{1}) $ &    -0.475( 0.032)*** &    -0.412(0.090)*** \\ 
  $x_{1} (\sigma_{2}) $ &    -0.500( 0.209)*   &    -0.476(0.031)*** \\ 
  $x_{1} (\sigma_{3}) $ &     0.451( 0.079)*** &    -0.362(0.164)*   \\\hline 
  $\lambda_{2}$ & -1256.463( 6.938)*** &   713.931(0.109)*** \\ 
  $Z_1 (\gamma_{2})$ &  1393.016(10.198)*** & -1363.373(0.170)*** \\ 
  $Z_2 (\gamma_{2})$ &   548.092(49.471)*** &    90.991(1.333)*** \\ 
  $Z_3 (\gamma_{2})$ &    -0.065( 2.693)    &   -39.020(3.230)*** \\ 
  $Z_4 (\gamma_{2})$ &    96.515(71.407)    &   -39.031(2.010)*** \\ 
  $Z_5 (\gamma_{2})$ &   -89.312(12.438)*** &    65.439(3.031)*** \\ \hline
  N & 15000 & 15000 \\ 
  LL & -10337.07 & 9443.21 \\ 
  Num.Params & 30 & 30 \\ 
  AIC & 20962.61 & 19174.89 \\ 
  BIC & 20734.13 & 18946.41 \\ \hline
  $\bar{\pi}_{1}$ & \%54.17 & \%24.17 \\ 
$\bar{\pi}_{2}$ & \%19.05 & \%54.27 \\ 
$\bar{\pi}_{3}$ & \%26.78 & \%21.57 \\ 
   \hline\hline
\end{tabular}
\end{table}
\end{document}

在此处输入图片描述

答案1

由于保留相同的小数位数,因此您可以简单地对所有数字应用右对齐。在特殊情况下,\hphantom{}如果您需要将整数与非整数混合,请在右侧添加额外的空格;宏不会排版任何内容,但会添加与其内容相等的空格(参见示例)。

我还将数字和不确定性分成两个单独的列;封闭tabular内部threeparttable环境,让您可以在表格底部添加注释;最后添加自定义规则定义,booktabs以便更好地呈现。

在此处输入图片描述

\documentclass[12pt]{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{threeparttable}

\begin{document}
\begin{table}
  \centering
  \begin{threeparttable}
    \caption{Example}\label{tab:example}
    \begin{tabular}{
        >{$}l<{$} r@{\;}r @{\hspace{2em}}  r@{\;}r @{\hspace{1.5em}}
      }
      \toprule
      \textup{Variables} & \multicolumn{4}{c}{LC-MIXL} \\
      \cmidrule(lr){2-5}
      & \multicolumn{2}{c}{\((\delta = 0.5)\)} & \multicolumn{2}{c}{\((\delta = 1.0)\)}       \\
      \midrule
      x_{1} (\mu_{1})     &     0.982 & (0.038)\tnote{***}   &     1.900 & (0.065)\tnote{***} \\
      x_{1} (\mu_{2})     &     2.106 & (0.095)\tnote{***}   &     0.987 & (0.029)\tnote{***} \\
      x_{1} (\mu_{3})     &     1.500 & (0.052)\tnote{***}   &     3.116 & (0.119)\tnote{***} \\
      \midrule
      x_{1} (\sigma_{1})  &    -0.475 & (0.032)\tnote{***}   &    -0.412 & (0.090)\tnote{***} \\
      x_{1} (\sigma_{2})  &    -0.500 & (0.209)\tnote{*}     &    -0.476 & (0.031)\tnote{***} \\
      x_{1} (\sigma_{3})  &     0.451 & (0.079)\tnote{***}   &    -0.362 & (0.164)\tnote{*}   \\
      \midrule
      \lambda_{2}         & -1256.463 & (6.938)\tnote{***}   &   713.931 & (0.109)\tnote{***} \\
      Z_1 (\gamma_{2})    &  1393.016 & (10.198)\tnote{***}  & -1363.373 & (0.170)\tnote{***} \\
      Z_2 (\gamma_{2})    &   548.092 & (49.471)\tnote{***}  &    90.991 & (1.333)\tnote{***} \\
      Z_3 (\gamma_{2})    &    -0.065 & (2.693)              &   -39.020 & (3.230)\tnote{***} \\
      Z_4 (\gamma_{2})    &    96.515 & (71.407)             &   -39.031 & (2.010)\tnote{***} \\
      Z_5 (\gamma_{2})    &   -89.312 & (12.438)\tnote{***}  &    65.439 & (3.031)\tnote{***} \\
      \midrule
      \textup{N}          & 15000\hphantom{.00} &            & 15000\hphantom{.00} & \\
      \textup{LL}         & -10337.07 &                      & 9443.21   & \\
      \textup{Num.Params} & 30\hphantom{.00}    &            & 30\hphantom{.00} & \\
      \textup{AIC}        & 20962.61            &            & 19174.89  & \\
      \textup{BIC}        & 20734.13            &            & 18946.41  & \\
      \midrule
      \bar{\pi}_{1}       & \%54.17             &            & \%24.17   & \\
      \bar{\pi}_{2}       & \%19.05             &            & \%54.27   & \\
      \bar{\pi}_{3}       & \%26.78             &            & \%21.57   & \\
      \bottomrule\bottomrule
    \end{tabular}
    \begin{tabular}{>{$}l<{$}@{\;}l}
      ^{*}   & Note for one star \\
      ^{***} & Note for three stars
    \end{tabular}
  \end{threeparttable}
\end{table}
\end{document}

答案2

您可以使用\begin{tabular}{lr@{.}lr@{.}l}并替换所有第一个点&

\begin{document}
\begin{table}
\begin{tabular}{lr@{.}lr@{.}l}
  \hline
Variables & LC-MIXL & $(\delta=0.5)$ & LC-MIXL & $(\delta=1)$ \\ 
  \hline
$x_{1} (\mu_{1})      $ &     0&982( 0.038)*** &     1&900(0.065)*** \\ 
  $x_{1} (\mu_{2})    $ &     2&106( 0.095)*** &     0&987(0.029)*** \\ 
  $x_{1} (\mu_{3})    $ &     1&500( 0.052)*** &     3&116(0.119)*** \\ \hline
  $x_{1} (\sigma_{1}) $ &    -0&475( 0.032)*** &    -0&412(0.090)*** \\ 
  $x_{1} (\sigma_{2}) $ &    -0&500( 0.209)*   &    -0&476(0.031)*** \\ 
  $x_{1} (\sigma_{3}) $ &     0&451( 0.079)*** &    -0&362(0.164)*   \\\hline 
  $\lambda_{2}        $ & -1256&463( 6.938)*** &   713&931(0.109)*** \\ 
  $Z_1 (\gamma_{2})   $ &  1393&016(10.198)*** & -1363&373(0.170)*** \\ 
  $Z_2 (\gamma_{2})   $ &   548&092(49.471)*** &    90&991(1.333)*** \\ 
  $Z_3 (\gamma_{2})   $ &    -0&065( 2.693)    &   -39&020(3.230)*** \\ 
  $Z_4 (\gamma_{2})   $ &    96&515(71.407)    &   -39&031(2.010)*** \\ 
  $Z_5 (\gamma_{2})   $ &   -89&312(12.438)*** &    65&439(3.031)*** \\ \hline
  N                     & 15000&0              & 15000&0 \\ 
  LL                    & -10337&07            & 9443&21 \\ 
  Num.Params            & 30&0                 & 30&0 \\ 
  AIC                   & 20962&61             & 19174&89 \\ 
  BIC                   & 20734&13             & 18946&41 \\ \hline
  $\bar{\pi}_{1}$       & \%54&17              & \%24&17 \\ 
  $\bar{\pi}_{2}$       & \%19&05              & \%54&27 \\ 
  $\bar{\pi}_{3}$       & \%26&78              & \%21&57 \\ 
   \hline\hline
\end{tabular}
\end{table}
\end{document}

会产生

在此处输入图片描述

答案3

你可能想看看siunitxS提供符合您要求的列类型的包。

\documentclass[12pt]{article}
\usepackage{siunitx}
\begin{document}
\begin{table}
\begin{tabular}{lSS}
  \hline
Variables & {LC-MIXL $(\delta=0.5)$} & {LC-MIXL $(\delta=1)$} \\ 
  \hline
$x_{1} (\mu_{1})$ &     0.982( 0.038)*** &     1.900(0.065)*** \\ 
  $x_{1} (\mu_{2})$ &     2.106( 0.095)*** &     0.987(0.029)*** \\ 
  $x_{1} (\mu_{3})$ &     1.500( 0.052)*** &     3.116(0.119)*** \\ \hline
  $x_{1} (\sigma_{1}) $ &    -0.475( 0.032)*** &    -0.412(0.090)*** \\ 
  $x_{1} (\sigma_{2}) $ &    -0.500( 0.209)*   &    -0.476(0.031)*** \\ 
  $x_{1} (\sigma_{3}) $ &     0.451( 0.079)*** &    -0.362(0.164)*   \\\hline 
  $\lambda_{2}$ & -1256.463( 6.938)*** &   713.931(0.109)*** \\ 
  $Z_1 (\gamma_{2})$ &  1393.016(10.198)*** & -1363.373(0.170)*** \\ 
  $Z_2 (\gamma_{2})$ &   548.092(49.471)*** &    90.991(1.333)*** \\ 
  $Z_3 (\gamma_{2})$ &    -0.065( 2.693)    &   -39.020(3.230)*** \\ 
  $Z_4 (\gamma_{2})$ &    96.515(71.407)    &   -39.031(2.010)*** \\ 
  $Z_5 (\gamma_{2})$ &   -89.312(12.438)*** &    65.439(3.031)*** \\ \hline
  N & 15000 & 15000 \\ 
  LL & -10337.07 & 9443.21 \\ 
  Num.Params & 30 & 30 \\ 
  AIC & 20962.61 & 19174.89 \\ 
  BIC & 20734.13 & 18946.41 \\ \hline
  $\bar{\pi}_{1}$ & \%54.17 & \%24.17 \\ 
$\bar{\pi}_{2}$ & \%19.05 & \%54.27 \\ 
$\bar{\pi}_{3}$ & \%26.78 & \%21.57 \\ 
   \hline\hline
\end{tabular}
\end{table}
\end{document}

在此处输入图片描述

相关内容