3

I want to get a form like this: tu

\documentclass{beamer}
\usepackage{multirow} 
\usepackage{makecell} 

\begin{document}
    \begin{frame}
    \begin{tabular}{cccccccc}
    \hline
    \multirow{2}{*}{A} & \multirow{2}{*}{B} &
    \multicolumn{3}{c}{C} &
    \multicolumn{3}{c}{D} &\\
    \cline{3-5}
    &x&y&z
    \cline{6-8}
    &x&y&z \\ \hline
    \end{tabular}
    \end{frame}
\end{document}

But when using multicolumn twice, you will get an error:

Extra alignment tab has been changed to \cr. \end{frame}

What should I do?

2

1 Answer 1

6

There are two syntax errors in your code. To get rid of them, you need to

  • remove the & particle from \multicolumn{3}{c}{D} &\\

  • not alternate between \cline directives and column contents. Hence, do replace

         \cline{3-5}
          &x&y&z
         \cline{6-8}
          &x&y&z \\ \hline
    

    with

         \cline{3-5} \cline{6-8}
         && x&y&z & x&y&z \\ \hline
    

With these changes, your code will compile. However, the resulting "look" may not be to your liking, as the two \clines will be joined together.

I'd like to suggest that you switch to using the line-drawing macros of the booktabs package instead of using \hline and \cline.

enter image description here

Note that I can see no compelling need for the \multirow directives in the OP's code.

\documentclass{beamer}
\usepackage{booktabs}

\begin{document}
\begin{frame}

\begin{tabular}{@{} *{8}{c} @{}}
   \toprule
   A & B & \multicolumn{3}{c}{C} & \multicolumn{3}{c@{}}{D} \\
   \cmidrule(lr){3-5} \cmidrule(l){6-8} 
   && u&v&w & x&y&z \\
   \midrule
   \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots \\
   \bottomrule
\end{tabular}

\end{frame}
\end{document}
2
  • 2
    Thank you very much for your help, I corrected it Commented Sep 3, 2023 at 6:59
  • @ZhaoDazhuang - You're most welcome.
    – Mico
    Commented Sep 3, 2023 at 7:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .