我想製作一個連續有兩個價格的表格,使用 siunitx 來實現令人愉悅且一致的數字顯示。為了避免在資料行中重複貨幣符號,我將其作為後綴插入相關列中。這適用於每行一個價格標籤;然而,對於第二個,siunitx 似乎增加了為每行每次出現的後綴保留的空間。這是一個非常簡單的例子:
\documentclass{scrartcl}
\usepackage{polyglossia}
\usepackage{siunitx}
\sisetup{table-number-alignment=right}
\newcolumntype{E}[0]{S[
table-figures-decimal=0,
table-align-text-post=true,
table-space-text-post={€}]<{€}}
\begin{document}
\begin{tabular}{EE}
63 & 126 \\
49 & 49 \\
\end{tabular}
\end{document}
如果第一列的格式正確,則第二列的空格過多。如果第二個正確,則將貨幣符號移至第一列的數字中。
(以防萬一:我使用的是 Debian texlive 軟體包中的 lualatex,版本 2015.20160117-1。)
有什麼建議我可以如何讓它工作嗎?
答案1
% arara: lualatex
\documentclass{scrartcl}
\usepackage{polyglossia}
\usepackage{siunitx}
\newcolumntype{E}[1]{S[%
,table-format=#1
,table-space-text-post={\,€}]<{\,€}
}
\begin{document}
% Quote taken from the manual page 71
When processing tables, \verb|siunitx| will expand anything stored
inside a macro, unless it is long or protected. \LaTeXe{} robust
commands are also detected and are not expanded.
Values which would otherwise be expanded
can be protected by wrapping them in a set of braces. As \TeX{} itself
will expand the first token in a table cell before \verb|siunitx|
can act on it, using the $\varepsilon$-\TeX{} protected mechanism is the
recommended course of action to prevent expansion of macros in
table cells. (As is shown in the table, \TeX's expansion of
\LaTeXe{} robust commands can lead to unexpected results.)
\bigskip
\begin{tabular}{E{2.0}E{3.0}}
63 & 126 \cr
49 & 49 \cr
\end{tabular}
\end{document}