
내 질문은 다음과 관련이 있습니다.이 질문그리고이것도. 나는하고 싶다소수점을 기준으로 값을 완벽하게 정렬하십시오.. 나 또한 원해최적의 열 너비로 내용을 맞춥니다.공간이 낭비되지 않도록.
현재 문제에 대한 솔루션은 더 큰 테이블(열이 10개 이상, 행이 20개 이상)을 준비하는 데 사용됩니다.
예상되는 출력 형식:현재 문제는 소수점을 기준으로 완벽하게 정렬된 아래 이미지(MS Word에서 만든)와 같은 형식의 테이블을 만드는 것입니다.
괄호 안의 값은티-모수 추정을 위한 통계입니다.
편집하다:
소수점 정렬 문제를 해결할 수 있습니다. 그러나 이제 아래 그림과 같은 몇 가지 다른 정렬 문제에 직면해 있습니다.
나는 다음을 원한다:
- 녹색 화살표로 표시된 간격을 줄입니다.
- 빨간색 화살표로 표시된 간격을 제거하세요.
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}