受到以下帖子的启发\bfseries 和表格对齐,我想创建一个表格,其中一些条目以粗体突出显示,并且数字应在点上对齐。我按照帖子中的描述定义了 boldentry 命令,但由于某种原因,在这种情况下数字没有完全对齐。下面的代码有什么问题?
\documentclass[b5paper,10pt,authoryear,longnamesfirst]{memoir}
\usepackage{booktabs,siunitx}
\usepackage[flushleft]{threeparttablex}
\newcommand{\MS}[1] {
\multicolumn{1}{c}{#1}}
\newcommand{\boldentry}[2]{%
\multicolumn{1}{S[table-format=#1,
mode=text,
text-rm=\fontseries{b}\selectfont
]}{#2}}
\begin{document}
\sisetup{detect-weight=true,detect-inline-weight=math}
\begin{table}
\scriptsize
\caption{A caption}
\begin{threeparttable}
\begin{tabular*}{\textwidth}{l@{\extracolsep{\fill}}*{9}{S[table-
format=1.3]}}
\toprule
& \MS{A} & \MS{B} & \MS{C} & \MS{D} & \MS{E} & \MS{F} & \MS{G} &
\MS{H} & \MS{I}\\
\midrule
A & \boldentry{1.3}{1.004}&\boldentry{1.3}{1.000}&\boldentry{1.3}
{1.008}&\boldentry{1.3}{1.000}&\boldentry{1.3}{0.989}&\boldentry{1.3}
{1.008}&1.070 & \boldentry{1.3}{0.981}&1.025\\
B & 1.025 & 1.012 & 1.016 & \boldentry{1.3}{1.000}&\boldentry{1.3}
{0.967}&\boldentry{1.3}{0.968}&\boldentry{1.3}{0.982}&\boldentry{1.3}
{0.961}&1.077\\
C& 1.009 & 1.001 & 1.002 & 1.000 & 0.986 & 0.985 & 0.991 &
\boldentry{1.3}{0.973}&0.998\\
D & 1.009 & 1.010 & 1.001 & 1.000 & 0.951 & 0.959 & 0.975 &
\boldentry{1.3}{0.931}&1.015\\
\bottomrule
\end{tabular*}
\begin{tablenotes}
\setlength\labelsep{0pt}
\scriptsize
\item A footnote
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}
答案1
我删除了您的定义,添加了用于指示具有粗体数字的单元格的强大新命令\newcommand{\boldentry}[2]{...}
包。 LL 与您的 mwe 相比的变化在代码中表示为:etoolbox
\B
% <--
\documentclass[b5paper,10pt,authoryear,longnamesfirst]{memoir}
\usepackage{booktabs}
\newcommand\mcc[1]{\multicolumn{1}{c}{#1}} % instead of \MS. you can still use your command ...
\usepackage{siunitx}
\usepackage[flushleft]{threeparttablex}
\usepackage{etoolbox} % <--
\renewcommand{\bfseries}{\fontseries{b}\selectfont} % <--
\robustify\bfseries % <--
\newrobustcmd{\B}{\bfseries} % <--
\begin{document}
\begin{table}
\small
\caption{A caption}
\setlength\tabcolsep{0pt}
\begin{threeparttable}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}
l
*{9}{S[detect-weight, % <--
mode=text, % <--
table-format=1.3]}}
\toprule
& \mcc{A} & \mcc{B} & \mcc{C} & \mcc{D} & \mcc{E}
& \mcc{F} & \mcc{G} & \mcc{H} & \mcc{I} \\
\midrule
A & \B 1.004 & \B 1.000 & \B 1.008 & \B 1.000 & \B 0.989
& \B 1.008 & 1.070 & \B 0.981 & 1.025 \\
B & 1.025 & 1.012 & 1.016 & \B 1.000 & \B 0.967
& \B 0.968 & \B 0.982 & \B 0.961 & 1.077 \\
C & 1.009 & 1.001 & 1.002 & 1.000 & 0.986
& 0.985 & 0.991 & \B 0.973 & 0.998 \\
D & 1.009 & 1.010 & 1.001 & 1.000 & 0.951
& 0.959 & 0.975 & \B 0.931 & 1.015 \\
\bottomrule
\end{tabular*}
\begin{tablenotes}
\setlength\labelsep{0pt}
\scriptsize
\item A footnote
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}