我有一张使用\numrange
该siunitx
包的表格。我想将该列在范围短语处居中对齐。如果我将其左对齐,它还可以,但如果我将其居中对齐,则效果不佳。我该如何解决这个问题?
\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage{siunitx}
\begin{document}
\begin{table}
\caption{All measured and their estimated outcome variables during 30 minutes of chair exercises}
\label{table:outcomes}
\sisetup{
range-phrase = --
}
\begin{tabular}{
l
c
c
c
%S[parse-numbers = false,input-decimal-markers={-},output-decimal-marker = \text{--}]
S[table-format=3.1, table-text-alignment=center]
}
\multicolumn{1}{l}{}&
\multicolumn{1}{c}{Mean}&
\multicolumn{1}{c}{SD}&
\multicolumn{1}{c}{Median}&
\multicolumn{1}{c}{Range}\
\hline
\%vo2max (mL/min) & 66.0 & 16.5 & 66.9 & \numrange{30.3}{115.8}\\
&&& 54.6 & \numrange{30.3}{77.7}\\
&&& 69.9 & \numrange{43.8}{115.8} \
\hline
\end{tabular}
\end{table}
\end{document}
答案1
以下内容不是您要解决的问题的直接解决方案。相反,我建议您考虑寻求不同的解决方案。为什么?就我个人而言,我认为如果试图在一列中显示整个数字范围,则太多的数字信息会被塞进一个有限的空间中。为了让读者有机会真正解析和吸收您呈现的数据,您可能最好将最小值和最大值列在单独的列中——当然,通过一个标有“范围”的总标题连接起来。以下 MWE 说明了我想要表达的内容。
MWE 还使用软件包的\toprule
、\midrule
、\cmidrule
和\bottomrule
宏booktabs
来生成间距适当且粗细不一的“规则”(水平线)。与使用 和\hline
(\cline
基本的 LaTeX 规则绘制命令)实现的效果相比,这些宏可立即使表格看起来更加专业。
\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage{siunitx,booktabs}
% booktabs package for well-spaced horizontal rules
\begin{document}
\begin{table}
\caption{All measured and their estimated outcome variables during 30 minutes of chair exercises}
\label{table:outcomes}
\medskip\centering
\sisetup{table-format=2.1}
\begin{tabular}{l SSSS S[table-format=3.1]}
\toprule
& {Mean}&{SD} & {Median}& \multicolumn{2}{c}{Range}\\
\cmidrule{5-6}
& & & & {Lower} & {Upper}\\
\midrule
\%vo2max (mL/min) & 66.0 & 16.5 & 66.9 & 30.3 & 115.8\\
&&& 54.6 & 30.3 & 77.7\\
&&& 69.9 & 43.8 & 115.8 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
我也有同样的情况问题我尝试了很多方法,所以我的解决方法是:
1.将最后一列拆分为 3 个不同的列
2.最后 3 列必须采用以下格式S
:c
S
3.减少柱子之间的间隙1ex
4.在最后 3 列中写下您的范围:一列中写下较低的值,range-phrase
另一列中写下您的值,最后一列中写下较高的值
您的 MWE:
\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage{siunitx}
\begin{document}
\begin{table}
\caption{All measured and their estimated outcome variables during 30 minutes of chair exercises}
\label{table:outcomes}
\sisetup{
range-phrase = --
}
\begin{tabular}{%
l
c
c
c
S[table-format=3.1, table-text-alignment=center] %<-- Columns splited
@{\hspace{1ex}} %<-- Column separation
c %<-- Columns splited
@{\hspace{1ex}} %<-- Column separation
S[table-format=3.1, table-text-alignment=center] %<-- Columns splited
}
& Mean & SD & Median & \multicolumn{3}{c}{Range}\\ %I just used multicolumn for the splited columns
\hline
\%vo2max \si{\mL/\minute} & 66.0 & 16.5 & 66.9 & 30.3 & -- & 115.8 \\ %<- I use the \si option for the units
& & & 54.6 & 30.3 & -- & 77.7 \\ %<- Ranges splited and separated by your own range-phrase
& & & 69.9 & 43.8 & -- & 115.8 \\
\hline
\end{tabular}
\end{table}
\end{document}