5

I am trying to format a table using multirow and multicolumn. Most of it seems ok except that I am missing some borders and I would a line separator between row "Binary Classifier" and the row immediately beneath it (1 vs. 2) etc. I cannot seem to figure it out.

\begin{tabular}{|l|c|c|c|c|c|}
\hline
\multirow{2}{*}{Category} & \multicolumn{3}{c|}  {Binary Classifier} &  \multirow{2}{*}{Votes}    & \multirow{2}{*}{Result}\\

           &  1 vs. 2  &  1 vs. 3   & 2 vs. 3\\
\hline Class 1 & Win & Win & X & 2 & Win \\ 
\hline Class 2 & X & X & Win & 1 & X \\ 
\hline Class 3 & X & X & X & 0 & X \\ 
\hline  
\end{tabular}

enter image description here

  • 2
    First, you will get quicker assistance with a compilable MWE. Search this site for MWE for more information. Second, change line 5 to read ' & 1 vs. 2 & 1 vs. 3 & 2 vs. 3& &\\ ' because in each row you must account for all specified columns (you declared there would be six) – R. Schumacher Jul 4 '16 at 12:24
6

Just add a \cline for the missing horizontal line and add the missing cells for the second row.

% arara: pdflatex

\documentclass{article}
\usepackage{multirow}
\usepackage{array}

\begin{document}
    \begin{tabular}{|l|*{5}{c|}}
        \hline
        \multirow{2}{*}{Category} & \multicolumn{3}{c|}{Binary Classifier} & \multirow{2}{*}{Votes} & \multirow{2}{*}{Result} \\\cline{2-4} 
                & 1 vs.\ 2 & 1 vs.\ 3 & 2 vs.\ 3 &   &     \\\hline 
        Class 1 & Win      & Win      & X        & 2 & Win \\\hline 
        Class 2 & X        & X        & Win      & 1 & X   \\\hline
        Class 3 & X        & X        & X        & 0 & X   \\\hline  
    \end{tabular}
\end{document}

enter image description here

|improve this answer|||||
10

Save yourself some trouble while making it look more beautiful. Here are some general advice on printing tables.

  • Don't use vertical lines, unless your table is meant to be read vertically.
  • Use some different widths of horizontal lines. The booktabs-package has som nice predefined lengths(along with some very good advice), namely \toprule,\midrule and \bottomrule.
  • Use a caption on top. (for figures, the caption can below it).
  • Don't write \begin{tabular}{|l|c|c|c|c|c|} with that many repeating items. use \begin{tabular}{|l|*{5}{c|}} if you reall want vertical lines, or \begin{tabular}{l*{5}{c}} without vertical lines. That way, you specify the number of columns you want of type c, instead of typing one by one.

Output

enter image description here

Code

\documentclass[11pt]{article}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{multirow}
\begin{document}

\begin{table}
    \centering
    \caption{Some binary stuff\ldots}
    \begin{tabular}{l*{5}{c}}
        \toprule
        \multirow{2}{*}{Category} & \multicolumn{3}{c}  {Binary Classifier} &  \multirow{2}{*}{Votes}    & \multirow{2}{*}{Result}\\

                   &  1 vs. 2  &  1 vs. 3   & 2 vs. 3\\
        \midrule
         Class 1 & Win & Win & X & 2 & Win \\ 
         Class 2 & X & X & Win & 1 & X \\ 
        Class 3 & X & X & X & 0 & X \\ 
        \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.