1

I am currently trying to work on a latex table to report data on different categories and have countered text alignment issues. I have tried to use two multicolumn environments and combination of multrow and multicolumn with no success.

\begin{table}
    \caption{demo}
    \label{tbl:demo}
    \begin{tabular}{ ccccc }
            \hline
            \multirow{2}{*}{name} &
            \begin{tabular}{c}
                    Category1 \\
                    column1 \\
            \end{tabular}
            &
            \multicolumn{2}{c}{Category2}\\ %\cline{3-4}
            && column1 &column2  \\
            \hline
            n1 & 1 &  7 & 5 \\
            n2  &- & 6 & 4 \\
            n3 & 2 & 9 & 3 \\
            \hline
    \end{tabular}
\end{table}

Table with incorrect heading alignment

Any pointers on how I can fix the alignment of the headers?

Kenneth

  • Welcome to TeX.SX! Use different rows. – TeXnician Oct 14 '17 at 9:20
0

Here's a version with booktabs and correct alignment.

table

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{table}
    \centering
    \caption{demo}
    \label{tbl:demo}
    \begin{tabular}{ ccccc }
            \toprule
             & Category1 & \multicolumn{2}{c}{Category 2}\\\cmidrule(lr){2-2}\cmidrule(lr){3-4}
            name & column1 & column1 &column2 \\
            \midrule
            n1 & 1 &  7 & 5 \\
            n2  &- & 6 & 4 \\
            n3 & 2 & 9 & 3 \\
            \bottomrule
    \end{tabular}
\end{table}
\end{document}
| improve this answer | |

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.