6

I came across weird behavior when loading xcolor=table option that affects the proper alignement in the tabular environment.

The output of this 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}

is

enter image description here

However, when using the option \documentclass[xcolor=table]{beamer}, I got the output like this with improper alignment in the first cell of the last row.

enter image description here

How can I got the proper alignment with loading this option xcolor=table?

9

Use two columns instead of one:

\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}

I suggest you to consider the second table, without the humongous \huge label.

enter image description here

Alternatively, in your code, write

Power\hspace{0pt plus 1filll}\si{W}

The TeXnical reason is that colortbl (loaded with the table option to xcolor) realizes left alignment with \hfill rather than with \hfil as the core code. Thus you need a higher order infinite glue to push the object to the right margin.

  • Many thanks for your simple solution. I just used \huge to magnify the gap before the vertical rule. – Diaa Jun 8 '16 at 23:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.