
當儲存格 421 和 237(在本範例中)其中之一以任何方式(粗體、彩色等)突出顯示時,儲存格 421 和 237 不會對齊。我只在必要時使用 S 柱。這是一個小例子:
\documentclass{report}
\usepackage{tabu, longtable}
\begin{document}
\begin{longtabu} to \textwidth {X[2, l]X[c]X[c]X[c]X[c]S[table-format=4]X[c]}
& \multicolumn{2}{c}{\textbf{column1}} & \multicolumn{4}{c}{\textbf{column2}} \\
& a & b & c & d & e & f \\
\textbf{round1} & 2.876 & 22 & 5.837 & 2.433 & \textbf{421} & 5.235 \\
& & & & 6.564 & 4.434 & 237 & 1.345 \\
\end{longtabu}
\end{document}
答案1
有包裹siunitx
遺失。e
在第二行中新增大括號,新增detect-weight
至設定S
並使用
\protected\bfseries 421
對齊粗體421
:
\documentclass{report}
\usepackage{tabu, longtable}
\usepackage{siunitx}
\begin{document}
\begin{longtabu} to \textwidth {X[2, l]X[c]X[c]X[c]X[c]S[table-format=4,detect-weight]X[c]}
& \multicolumn{2}{c}{\textbf{column1}} & \multicolumn{4}{c}{\textbf{column2}} \\
& a & b & c & d & {e} & f \\
\textbf{round1} & 2.876 & 22 & 5.837 & 2.433 & \protected\bfseries 421 & 5.235 \\
& & & 6.564 & 4.434 & 237 & 1.345 \\
\end{longtabu}
\end{document}
不幸的是,這似乎\color
不適S
用於tabu
.但你可以使用\tablenum
:
\multicolumn{1}{c}{\tablenum[table-format=4,color=orange]{421}}
代碼:
\documentclass{report}
\usepackage{tabu, longtable}
\usepackage{siunitx}
\usepackage[table]{xcolor}
\begin{document}
\begin{longtabu} to \textwidth {X[2, l]X[c]X[c]X[c]X[c]S[table-format=4,detect-weight]X[c]}
& \multicolumn{2}{c}{\textbf{column1}} & \multicolumn{4}{c}{\textbf{column2}} \\
& a & b & c & d & {e} & f \\
\textbf{round1} & 2.876 & 22 & 5.837 & 2.433 & \multicolumn{1}{c}{\tablenum[table-format=4,color=orange]{421}} & 5.235 \\
& & & 6.564 & 4.434 & 237 & 1.345 \\
\end{longtabu}
\end{document}
或者
\multicolumn{1}{>{\cellcolor{gray}}c}{\tablenum[table-format=4,color=orange]{421}}
\documentclass{report}
\usepackage{tabu, longtable}
\usepackage{siunitx}
\usepackage[table]{xcolor}
\newcommand\specSc{}
\def\specSc#1[#2]#3{%
\multicolumn{1}{>{#1}c}{\tablenum[#2]{#3}}%
}
\begin{document}
\begin{longtabu} to .5\textwidth {X[l]S[table-format=4.1]S[table-format=1.3,detect-weight]}
& {e} & {f} \\
\textbf{round1}
& \specSc{\bfseries}[table-format=4.1,detect-weight]{421.3}
& 5.235 \\
& \specSc{\color{orange}}[table-format=4.1]{237}
& \specSc{}[table-format=1.3,color=purple]{1.34} \\
& \specSc{\cellcolor{lightgray}}[table-format=4.1,color=blue]{237.2}
& \protected\bfseries 1.342 \\
\end{longtabu}
\end{document}