2

In the table below, the heading of the first column is slightly off for some reason. Why is this happening? How do I further make it look better overall?

enter image description here

\documentclass{article}
\usepackage{booktabs}

\begin{document}

\begin{table}[h]
\begin{tabular}{@{}ccccccc@{}}
\toprule
\multicolumn{2}{c}{\begin{tabular}[c]{@{}c@{}}Present\\State\end{tabular}} & \multicolumn{2}{c}{Input} & \multicolumn{2}{c}{\begin{tabular}[c]{@{}c@{}}Next\\ State\end{tabular}} & Output \\
\cmidrule(l){1-2} \cmidrule(lr){5-6} \cmidrule(lr){3-4} \cmidrule(l){7-7}
A          & B            & x & y        & A          & B          & z      \\ \midrule
0          & 0            & 0 & 0          & 0           & 0          & 0      \\
0          & 0            & 0 & 1          & 0           & 0          & 0      \\
0          & 0            & 1 & 0          & 1           & 1          & 0      \\
0          & 0            & 1 & 1          & 0           & 1          & 0      \\ [1ex]
0          & 1            & 0 & 0          & 0           & 0          & 0      \\
0          & 1            & 0 & 1          & 0           & 0          & 0      \\
0          & 1            & 1 & 0          & 1           & 0          & 0      \\
0          & 1            & 1 & 1          & 1           & 0          & 0      \\[1ex]
1          & 0            & 0 & 0          & 0           & 0          & 1      \\
1          & 0            & 0 & 1          & 0           & 0          & 1      \\
1          & 0            & 1 & 0          & 1           & 1          & 1      \\
1          & 0            & 1 & 1          & 0           & 1          & 1      \\[1ex]
1          & 1            & 0 & 0          & 0           & 0          & 1      \\
1          & 1            & 0 & 1          & 0           & 0          & 1      \\
1          & 1            & 1 & 0          & 1           & 1          & 1      \\
1          & 1            & 1 & 1          & 1           & 1          & 1      \\ \bottomrule
\end{tabular}
\end{table}
\end{document}

1 Answer 1

1

Since \begin{tabular}{@{}ccccccc@{}} is used as column specifiers, this must be done with

\multicolumn{2}{@{}c}{....

too, i.e. remove the horizontal space for the first column by saying @{}c.

\documentclass{article}
\usepackage{booktabs}

\begin{document}

\begin{table}[h]
\begin{tabular}{@{}ccccccc@{}}
\toprule
\multicolumn{2}{@{}c}{\begin{tabular}[c]{@{}c@{}}Present\\State\end{tabular}} & \multicolumn{2}{c}{Input} & \multicolumn{2}{c}{\begin{tabular}[c]{@{}c@{}}Next\\ State\end{tabular}} & Output \\
\cmidrule(r){1-2} \cmidrule(lr){5-6} \cmidrule(lr){3-4} \cmidrule(l){7-7}
A          & B            & x & y        & A          & B          & z      \\ \midrule
0          & 0            & 0 & 0          & 0           & 0          & 0      \\
0          & 0            & 0 & 1          & 0           & 0          & 0      \\
0          & 0            & 1 & 0          & 1           & 1          & 0      \\
0          & 0            & 1 & 1          & 0           & 1          & 0      \\ [1ex]
0          & 1            & 0 & 0          & 0           & 0          & 0      \\
0          & 1            & 0 & 1          & 0           & 0          & 0      \\
0          & 1            & 1 & 0          & 1           & 0          & 0      \\
0          & 1            & 1 & 1          & 1           & 0          & 0      \\[1ex]
1          & 0            & 0 & 0          & 0           & 0          & 1      \\
1          & 0            & 0 & 1          & 0           & 0          & 1      \\
1          & 0            & 1 & 0          & 1           & 1          & 1      \\
1          & 0            & 1 & 1          & 0           & 1          & 1      \\[1ex]
1          & 1            & 0 & 0          & 0           & 0          & 1      \\
1          & 1            & 0 & 1          & 0           & 0          & 1      \\
1          & 1            & 1 & 0          & 1           & 1          & 1      \\
1          & 1            & 1 & 1          & 1           & 1          & 1      \\ \bottomrule
\end{tabular}
\end{table}
\end{document}

enter image description here

9
  • 3
    I would also change \cmidrule(l){1-2} to \cmidrule(r){1-2} Commented Mar 8, 2015 at 10:08
  • @karlkoeller: Thanks, I did not notice that the first \cmidrule is out of place.
    – user31729
    Commented Mar 8, 2015 at 10:09
  • For a better looking I would also suggest removing @{} globally and use \cmidrule(lr)... everywhere. Commented Mar 8, 2015 at 10:11
  • Any other suggestions for making it look better?
    – Surag
    Commented Mar 8, 2015 at 10:12
  • @Surag Not by my side. :-) Commented Mar 8, 2015 at 10:13

You must log in to answer this question.

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