在下面的 MWE 中,我使用siunitx
包用于对齐表中的数字条目。如何\sim
在不破坏对齐的情况下将符号放在“6”之前?表 A 可以编译;表 B 则不能。
\documentclass[oneside,11pt]{book}
\usepackage[semibold,tt=false]{libertine}
\usepackage{libertinust1math}
\usepackage[
expansion = false ,
tracking = smallcaps ,
letterspace = 40 ,
final
]{microtype}
\usepackage[font={sf,small},labelsep=quad,labelfont=sc]{caption}
\usepackage{mathtools}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
% A
\begin{table}[!h]
\centering
\begin{tabular}{
l
S[table-format=1.1,table-number-alignment=left,table-align-text-post=false]
}
\toprule
& {X}\\
\midrule
A & 6\\
B & 0.1\\
\bottomrule
\end{tabular}
\caption{A}
\end{table}
% B
\begin{table}[!h]
\centering
\begin{tabular}{
l
S[table-format=1.1,table-number-alignment=left,table-align-text-post=false]
}
\toprule
& {X}\\
\midrule
A & \sim 6\\
B & 0.1\\
\bottomrule
\end{tabular}
\caption{B}
\end{table}
\end{document}
答案1
请尝试以下操作:
\documentclass[12pt]{article}
\usepackage[semibold,tt=false]{libertine}
\usepackage{libertinust1math}
\usepackage[expansion = false,
tracking = smallcaps,
letterspace = 40,
final] {microtype}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
\begin{center}
\begin{tabular}{c
S[input-comparators, % <----
table-space-text-pre=$\sim$, % <----
table-format=1.1,
]
}
\toprule
type & {X} \\
\midrule
A & $\sim$ 6 \\
B & 0.1 \\
\bottomrule
\end{tabular}
\caption{A}
\end{table}
\medskip
\medskip
however, in table is better to use
\verb+table-comparator+ instead of \verb+input-comparators+ as suggested in @Bernard's answer:
\medskip
\begin{tabular}{c
S[table-format=1.1,
table-space-text-pre=$\sim$,
table-comparator] % <----
}
\toprule
type & {X} \\
\midrule
A & \sim 6 \\ % <----
B & 0.1 \\
\bottomrule
\end{tabular}
\end{center}
\end{document}
两个例子中的结果相同:
答案2
要添加符号,您需要使用键input-symbols
,但这是一个比较器,因此您只需将开关设置table-comparator
为 true:
\documentclass[oneside,11pt]{book}
\usepackage[semibold,tt=false]{libertine}
\usepackage{libertinust1math}
\usepackage[
expansion = false ,
tracking = smallcaps ,
letterspace = 40 ,
final
]{microtype}
\usepackage[font={sf,small},labelsep=quad,labelfont=sc]{caption}
\usepackage{mathtools}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
\begin{table}[!h]
\centering
\begin{tabular}{
l
S[table-format=1.1,table-number-alignment=left,table-align-text-post=false, table-comparator]
}
\toprule
& {X}\\
\midrule
A & \sim 6\\
B & 0.1\\
\bottomrule
\end{tabular}
\caption{B}
\end{table}
\end{document}
答案3
用 代替\SI{\sim 6}{}
,\sim
它就可以工作了pdfLaTeX
。新年快乐 :-)。请参阅此处的解释:如何正确使用 siunitx 将带序言的数字对齐到表格中心
\documentclass[oneside,11pt]{book}
\usepackage[semibold,tt=false]{libertine}
\usepackage{libertinust1math}
\usepackage[
expansion = false ,
tracking = smallcaps ,
letterspace = 40 ,
final
]{microtype}
\usepackage[font={sf,small},labelsep=quad,labelfont=sc]{caption}
\usepackage{mathtools}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
% A
\begin{table}[!h]
\centering
\begin{tabular}{
l
S[table-format=1.1,table-number-alignment=left,table-align-text-post=false]
}
\toprule
& {X}\\
\midrule
A & 6\\
B & 0.1\\
\bottomrule
\end{tabular}
\caption{A}
\end{table}
% B
\begin{table}[!h]
\centering
\begin{tabular}{
l
S[table-format=1.1,table-number-alignment=left,table-align-text-post=false]
}
\toprule
& {X}\\
\midrule
A & \SI{\sim 6}{}
\\
B & 0.1\\
\bottomrule
\end{tabular}
\caption{B}
\end{table}
\end{document}
通过评论编辑:
\documentclass[oneside,11pt]{book}
\usepackage[semibold,tt=false]{libertine}
\usepackage{libertinust1math}
\usepackage[
expansion = false ,
tracking = smallcaps ,
letterspace = 40 ,
final
]{microtype}
\usepackage[font={sf,small},labelsep=quad,labelfont=sc]{caption}
\usepackage{mathtools}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
% A
\begin{table}[!h]
\centering
\begin{tabular}{
l
S[table-format=1.1,table-number-alignment=left,table-align-text-post=false]
}
\toprule
& {X}\\
\midrule
A & 6\\
B & 0.1\\
\bottomrule
\end{tabular}
\caption{A}
\end{table}
% B
\begin{table}[!h]
\centering
\begin{tabular}{
l
S[table-format=1.1,table-number-alignment=left,table-align-text-post=false]
}
\toprule
& {X}\\
\midrule
A & \!\!\!\SI{\sim 6}{}
\\
B & 0.1\\
\bottomrule
\end{tabular}
\caption{B}
\end{table}
\end{document}