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

1
  • 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) Commented Jul 4, 2016 at 12:24

2 Answers 2

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

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} 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.