使用 xcolor 表選項時表格環境中的對齊不正確

使用 xcolor 表選項時表格環境中的對齊不正確

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作為核心程式碼。因此,您需要更高階的無限黏合來將物件推到右邊距。

相關內容