2

I want a table that looks similar to this one where Present State and Next State aren't aligned so close to each other and have their own respective columns.

enter image description here

The code I have right now:

        \begin{tabular}{@{}c c c | c c c@{}} \toprule
            \multicolumn{6}{c}{Present State Next State} \\ \cmidrule(r){1-6}
            A & B & C & A & B & C\\ \midrule
            0 & 0 & 0 & 0 & 1 & 0\\
            0 & 0 & 1 & 0 & 1 & 0\\
            0 & 1 & 0 & 0 & 1 & 0\\
            0 & 1 & 1 & 0 & 1 & 0\\ 
            1 & 0 & 0 & 0 & 1 & 0\\
            1 & 0 & 1 & 0 & 1 & 0\\
            1 & 1 & 0 & 0 & 1 & 0\\
            1 & 1 & 1 & 0 & 1 & 0\\
            \bottomrule
        \end{tabular}

What I get from doing the above:

enter image description here

I've looked into the tabular documentation, and there's no explanation for having two columns that have three child columns. Oh, I forgot to mention; I'm using the booktabs package.

2
  • Please also keep in mind that horizontal lines from the booktabs package are intended to be used without vertical lines, so you might also want to replace {@{}c c c | c c c@{}} with {@{}c c c c c c@{}} or {@{} *{6}{c} @{}}.
    – leandriis
    Apr 22, 2021 at 21:54
  • Replace \multicolumn{6}{c}{Present State Next State} with \multicolumn{3}{@{}c}{Present State} & \multicolumn{3}{c@{}}{Next State} and \cmidrule(r){1-6} with \cmidrule(r){1-3} \cmidrule(l){4-6}.
    – leandriis
    Apr 22, 2021 at 21:58

1 Answer 1

1
\documentclass[a4paper,11pt]{article}
\usepackage[a4paper]{geometry}
\usepackage{booktabs}
\usepackage{array}

\begin{document}

\begin{tabular}{*{6}{wc{7mm}}} \toprule
    \multicolumn{3}{c}{Present State} & 
    \multicolumn{3}{c}{Next State} \\ \cmidrule(lr){1-3}\cmidrule(lr){4-6}
    A & B & C & A & B & C\\ \midrule
    0 & 0 & 0 & 0 & 1 & 0\\
    0 & 0 & 1 & 0 & 1 & 0\\
    0 & 1 & 0 & 0 & 1 & 0\\
    0 & 1 & 1 & 0 & 1 & 0\\ 
    1 & 0 & 0 & 0 & 1 & 0\\
    1 & 0 & 1 & 0 & 1 & 0\\
    1 & 1 & 0 & 0 & 1 & 0\\
    1 & 1 & 1 & 0 & 1 & 0\\
    \bottomrule
\end{tabular}

\end{document}

Output of the above code

1
  • now that is beautiful Apr 22, 2021 at 22:02

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.