
私の質問はこの質問そしてこれも。 したい小数点を基準に値を完全に揃える。 私もしたいコンテンツを最適な列幅に合わせるスペースが無駄にならないようにするためです。
現在の問題の解決策は、より大きなテーブル (10 列以上、20 行以上) を準備するために使用されます。
期待される出力フォーマット:現在の問題は、小数点の位置が正確に揃った、以下の画像 (MS Word で作成) のような形式の表を作成することです。
括弧内の値はtパラメータ推定のための -stat。
編集:
小数点に関する配置の問題は解決できました。しかし、現在、下の図に示すように、他の配置の問題に直面しています。
したい:
- 緑の矢印で示されたギャップを減らす
- 赤い矢印で示された隙間をなくす
MWE は以下の通りです。
\documentclass{article}
\usepackage{amsmath,booktabs,multirow,multicol,tabularx,siunitx}
\usepackage[table, dvipsnames]{xcolor}
\sisetup{
output-exponent-marker = \text{\hspace{1pt}e},
exponent-product={},
retain-explicit-plus,
input-open-uncertainty = ,
input-close-uncertainty = ,
table-align-text-pre = false,
table-align-text-post = false,
round-mode=places,
round-precision=3,
table-space-text-pre = (,
table-space-text-post = )
}
\newcommand{\cellvalItal}[1]{\begin{tabular}[l]{S[round-precision=2,math-rm=\mathit]}#1\end{tabular}}
\newcommand{\cellval}[2]{\begin{tabular}[l]{S}#1\\\cellvalItal{#2}\end{tabular}}
\newcommand{\Shifted}[1]{\begin{tabular}[l]{@{\phantom{~~~}}l@{}}#1\end{tabular}}
\newcommand{\ShiftedWithBaseCase}[2]{\begin{tabular}[l]{@{\phantom{~~~}}l}#1 \\ {[}\emph{#2}{]}\end{tabular}}
\begin{document}
\begin{table}
\begin{tabular}{l@{}S@{}S}
\toprule
\multirow{2.3}{*}{\textbf{Parameter}}
& \multicolumn{2}{@{}c}{\textbf{Estimate}} \\
\cmidrule(lr){2-3}
& {\centering\textbf{Model~M1}} & {\centering\textbf{Model~M2}}\\
\cmidrule(lr){1-1}
\cmidrule(lr){2-2}
\cmidrule(lr){3-3}
{Constant} &
\cellval{-1.316e-2}{(-23.153)} &
\cellval{-58.510}{(-4.26)}\\ % User defined functions to shorten the code length
\addlinespace
\textbf{\emph{Category}} & & \\
\ShiftedWithBaseCase{Male members}{Base case: Female members} & \cellval{0.112}{(2.04)}&
{---}\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
誰か助けてくれませんか?
答え1
これはおそらく最もエレガントな解決策ではなく、さらに調整が必要かもしれませんが、それでも、目的の出力に近づくことを願っています。元の例と比較した関連する変更は を使用して強調表示され、 % <---
その後に対応する変更の簡単な説明が続きます。
\documentclass{article}
\usepackage{amsmath,booktabs,multirow,multicol,tabularx,siunitx}
\usepackage[table, dvipsnames]{xcolor}
\sisetup{
output-exponent-marker = \text{\hspace{1pt}e},
exponent-product={},
retain-explicit-plus,
input-open-uncertainty = ,
input-close-uncertainty = ,
table-align-text-pre = false,
table-align-text-post = false,
round-mode=places,
round-precision=3,
table-space-text-pre = (,
table-space-text-post = )
}
\newcommand{\cellvalItal}[1]{\begin{tabular}[l]{S[round-precision=2,math-rm=\mathit]}#1\end{tabular}}
\newcommand{\cellvalleft}[2]{\begin{tabular}[l]{@{}S[table-format=-2.3e-1]@{}}#1\\\cellvalItal{#2}\end{tabular}} % <--- added @{} to either side of the S column specifier to remove extro horizontal space in the columns
\newcommand{\cellvalright}[2]{\begin{tabular}[l]{@{}S[table-format=-2.3]@{}}#1\\\cellvalItal{#2}\end{tabular}} % <--- added @{} to either side of the S column specifier to remove extro horizontal space in the columns, added appropriate table-format option, needed to be different than the table-format of the second cell, hence the second command.
%\newcommand{\Shifted}[1]{\begin{tabular}[l]{@{\phantom{~~~}}l@{}}#1\end{tabular}}
\newcommand{\ShiftedWithBaseCase}[2]{\begin{tabular}[l]{@{\phantom{~~~}}l}#1 \\ {[}\emph{#2}{]}\end{tabular}}
\renewcommand{\cmidrulekern}{0.25em} % <--- added do decrease space etween adjacent \cmidrule commands
\begin{document}
\begin{table}
\begin{tabular}{@{}l@{}S@{}S@{}} % <---- added @{} here to left align text with the left edge of the table
\toprule
\multirow{2.3}{*}{\textbf{Parameter}}
& \multicolumn{2}{c}{\textbf{Estimate}} \\
\cmidrule(l){2-3} % <--- removed r here in order to make sure the cmirdlue reaches the right "border" of the table
& {\textbf{Model~M1}} & {\textbf{Model~M2}}\\ % <--- removed \centering here. Text in {} is by default centered in S type columns.
\cmidrule(r){1-1} % <--- removed l here to make line left aligned with left endge of table
\cmidrule(lr){2-2}
\cmidrule(l){3-3} % <--- removed r here in order to make sure the cmirdlue reaches the right "border" of the table
{Constant} &
\cellvalleft{-1.316e-2}{(-23.153)} &
\cellvalright{-58.510}{(-4.26)}\\ % User defined functions to shorten the code length
\addlinespace
\textbf{\emph{Category}} & & \\
\ShiftedWithBaseCase{Male members}{Base case: Female members} & \cellvalleft{0.112}{(2.04)}&
{---}\\
\bottomrule
\end{tabular}
\end{table}
\end{document}