![使用 xcolor 表選項時表格環境中的對齊不正確](https://rvso.com/image/335467/%E4%BD%BF%E7%94%A8%20xcolor%20%E8%A1%A8%E9%81%B8%E9%A0%85%E6%99%82%E8%A1%A8%E6%A0%BC%E7%92%B0%E5%A2%83%E4%B8%AD%E7%9A%84%E5%B0%8D%E9%BD%8A%E4%B8%8D%E6%AD%A3%E7%A2%BA.png)
xcolor=table
在載入影響表格環境中正確對齊的選項時,我遇到了奇怪的行為。
該 MWE 的輸出
\documentclass{beamer}
\usepackage{siunitx,booktabs,multirow}
\begin{document}
\begin{frame}
\centering
\begin{tabular}{@{}l|ccc@{}}
\toprule
\multirow{2}{*}{\huge Parameters} & \multicolumn{3}{c}{Levels}\\
\cmidrule{2-4}
& 1 & 2 & 3 \\
\midrule
Power \hfill \si{\W} & 100 & 200 & 300 \\
\bottomrule
\end{tabular}
\end{frame}
\end{document}
是
但是,當使用該選項時\documentclass[xcolor=table]{beamer}
,我得到這樣的輸出,但最後一行的第一個單元格對齊不正確。
如何在加載此選項時獲得正確的對齊方式xcolor=table
?
答案1
使用兩列而不是一列:
\documentclass[xcolor=table]{beamer}
\usepackage{siunitx,booktabs,multirow}
\begin{document}
\begin{frame}
\centering
\begin{tabular}{@{}lrccc@{}}
\toprule
\multicolumn{2}{@{}c}{\multirow{2}{*}{\huge Parameters}} & \multicolumn{3}{c}{Levels}\\
\cmidrule{3-5}
& & 1 & 2 & 3 \\
\midrule
Power & \si{\W} & 100 & 200 & 300 \\
\bottomrule
\end{tabular}
\bigskip
\begin{tabular}{@{}lrccc@{}}
\toprule
\multicolumn{2}{@{}c}{Parameters} & \multicolumn{3}{c}{Levels}\\
\cmidrule{3-5}
& & 1 & 2 & 3 \\
\midrule
Power & \si{\W} & 100 & 200 & 300 \\
\bottomrule
\end{tabular}
\end{frame}
\end{document}
我建議您考慮第二個表,沒有巨大的\huge
標籤。
或者,在您的程式碼中編寫
Power\hspace{0pt plus 1filll}\si{W}
TeXnical 的原因是colortbl
(載入table
選項 to xcolor
)實作左對齊 with\hfill
而不是 with\hfil
作為核心程式碼。因此,您需要更高階的無限黏合來將物件推到右邊距。