2

I've got the following table:

\documentclass{article}

\usepackage{booktabs}

\begin{document}
    \begin{tabular}{cccccccc}
        \toprule
        \multicolumn{2}{c}{Letzter Zustand} & \multicolumn{4}{c}{Nächster Zustand} & \multicolumn{2}{c}{Ausgang}            \\
            &                               & \multicolumn{2}{c}{$x = 0$} & \multicolumn{2}{c}{$x = 1$} & $x = 0$ & $x = 1$ \\
        \cmidrule(lr){3-6}\cmidrule(lr){7-8}
        $A$ & $B$                           & $A$     & $B$               & $A$ & $B$                    & $y$     & $y$    \\
        \cmidrule(lr){1-2}\cmidrule(lr){3-4}\cmidrule(lr){5-6}\cmidrule(lr){7-8}
        0   & 0                             & 0       & 0                 & 0   & 1                      & 0       & 0      \\
        0   & 1                             & 1       & 1                 & 0   & 1                      & 0       & 0      \\
        1   & 0                             & 1       & 0                 & 0   & 0                      & 0       & 1      \\
        \bottomrule
    \end{tabular}
\end{document}

Unfortunately, the cells below the multicolumns are no longer centering correctly, but rather they appear to be left-aligned. This is most clearly seen in the two columns on the left (First A B), and is also quite noticeable in the 5th-6th column (Third A B).

My Table

What's causing this issue, and how can I resolve it?

1
  • it is centred but the heading is making the last spanned column in each group over-wide., the first column is just the width of A – David Carlisle Jun 1 '19 at 12:54
2

What's causing this issue, and how can I resolve it?

The issue arises because of the 2- and 4-column \multicolumn items are wider than the combined natural widths of the underlying columns.

To resolve it, I suggest you use a tabularx environment, set its overall width to something like 0.9\textwidth -- the optimal value will depend on things like the fontsize and the width of the text block -- and use a centered version of the X column type for all eight columns.

enter image description here

Note also that I've reorganized some of the horizontal rules in the header portion of the table.

\documentclass{article}
\usepackage{booktabs,tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}

\begin{document}
\begin{center}
    \begin{tabularx}{0.9\textwidth}{@{}*{8}{C}@{}}
    \toprule
    \multicolumn{2}{@{}c}{Letzter Zustand} & 
    \multicolumn{4}{c}{Nächster Zustand} & 
    \multicolumn{2}{c@{}}{Ausgang} \\
    \cmidrule(r){1-2} \cmidrule(lr){3-6} \cmidrule(l){7-8}
    & & \multicolumn{2}{c}{$x = 0$} 
      & \multicolumn{2}{c}{$x = 1$} 
      & $x = 0$ & $x = 1$ \\
    \cmidrule(lr){3-4}\cmidrule(lr){5-6}
    \cmidrule(lr){7-7}\cmidrule(l){8-8}
    $A$ & $B$ & $A$ & $B$ & $A$ & $B$ & $y$ & $y$    \\
    \midrule
    0 & 0 & 0 & 0 & 0 & 1 & 0 & 0      \\
    0 & 1 & 1 & 1 & 0 & 1 & 0 & 0      \\
    1 & 0 & 1 & 0 & 0 & 0 & 0 & 1      \\
    \bottomrule
    \end{tabularx}
\end{center}
\end{document}
2

Is this better?

\documentclass{article}

\usepackage{array, makecell, booktabs}

\begin{document}

    \begin{tabular}{*{8}{c}}
        \toprule
        \multicolumn{2}{c}{\smash{\makecell[t]{Letzter\\ Zustand}}} & \multicolumn{4}{c}{\makebox[0pt]{Nächster Zustand}} & \multicolumn{2}{c}{Ausgang} \\
            & & \multicolumn{2}{c}{$x = 0$} & \multicolumn{2}{c}{$x = 1$} & $x = 0$ & $x = 1$ \\
        \cmidrule(lr){3-6}\cmidrule(lr){7-8}
        $A$ & $B$ & $A$ & $B$ & $A$ & $B$ & $y$ & $y$ \\
        \cmidrule(lr){1-2}\cmidrule(lr){3-4}\cmidrule(lr){5-6}\cmidrule(lr){7-8}
        0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\
        0 & 1 & 1 & 1 & 0 & 1 & 0 & 0 \\
        1 & 0 & 1 & 0 & 0 & 0 & 0 & 1 \\
        \bottomrule
    \end{tabular}

\end{document} 

enter image description here

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.