TeX - LaTeX Asked by Templar on August 18, 2021
I am pretty new to LaTeX and i’m struggling with multicolumn/multirow tables. I have a table that has two empty boxes on the inside of it. I want to remove those boxes without changing the layout of the table in anyway. I know it’s a really simple question, but for some reason i can’t managed to find a solution 🙁
Here is the code i have for the table
begin{table}[h!]
centering
caption{A Confusion Matrix for the J48 Baseline}
begin{tabular}{|c|c|c|c|c|}
hline
multicolumn{5}{|c|}{Confusion Matrix}
hline
&multicolumn{4}{|c|}{Predicted}
hline
&Category& 0-1 & 2-10 & 11-200 [0.5ex]
hline
multirow{4}{*}{Truth Data}
&0-1&17964 & 2437& 1210
&2-10&5093 & 11334 & 5209
&11-200 &1519& 3302 & 16638 [1ex]
hline
end{tabular}
label{table:3}
end{table}
Is this what you want? It does not look that nice.
documentclass[10pt]{report}
usepackage{multirow}
usepackage{multicol}
usepackage{hhline}
begin{document}
begin{table}[h!]
centering
caption{A Confusion Matrix for the J48 Baseline}
begin{tabular}{|c|c|c|c|c|}
hline
multicolumn{5}{|c|}{Confusion Matrix}
hline
multicolumn{1}{c}{}&multicolumn{4}{|c|}{Predicted}
hhline{~|----|}
multicolumn{1}{c|}{}&Category& 0-1 & 2-10 & 11-200 [0.5ex]
hline
multirow{4}{*}{Truth Data}
&0-1&17964 & 2437& 1210
&2-10&5093 & 11334 & 5209
&11-200 &1519& 3302 & 16638 [1ex]
hline
end{tabular}
label{table:3}
end{table}
end{document}
This is better but not that great either
documentclass[10pt]{report}
usepackage{multirow}
usepackage{multicol}
usepackage{hhline}
begin{document}
begin{table}[h!]
centering
caption{A Confusion Matrix for the J48 Baseline}
begin{tabular}{|c|c|c|c|c|}
hhline{~|----|}
multicolumn{1}{c}{}&multicolumn{4}{|c|}{Confusion Matrix}
hhline{~|----|}
multicolumn{1}{c}{}&multicolumn{4}{|c|}{Predicted}
hhline{~|----|}
multicolumn{1}{c|}{}&Category& 0-1 & 2-10 & 11-200 [0.5ex]
hline
multirow{4}{*}{Truth Data}
&0-1&17964 & 2437& 1210
&2-10&5093 & 11334 & 5209
&11-200 &1519& 3302 & 16638 [1ex]
hline
end{tabular}
label{table:3}
end{table}
end{document}
Correct answer by Michel Janssens on August 18, 2021
I'd make some small, but important, adjustments in order to reduce ugliness.
documentclass{IEEEtran}
usepackage{showframe} % just for the picture
usepackage{multirow}
usepackage{makecell}
begin{document}
begin{table}[!htp]
centering
caption{A Confusion Matrix for the J48 Baseline}
label{table:3}
setcellgapes{3pt}
makegapedcells
begin{tabular}{|c|c|c|c|c|}
cline{2-5}
multicolumn{1}{c|}{} & multicolumn{4}{c|}{Confusion Matrix}
cline{2-5}
multicolumn{1}{c|}{} &multicolumn{4}{c|}{Predicted}
cline{2-5}
multicolumn{1}{c|}{} & smash{Category} & 0--1 & 2--10 & 11--200
hline
multirow{3.5}{*}{Truth Data}
& 0--1 & 17964 & 2437 & 1210
& 2--10 & 5093 & 11334 & 5209
& 11--200 & 1519 & 3302 & 16638
hline
end{tabular}
end{table}
begin{table}[!htp]
centering
caption{A Confusion Matrix for the J48 Baseline}
label{foo}
setcellgapes{3pt}
makegapedcells
begin{tabular}{c|cccc|}
multicolumn{1}{c}{} & multicolumn{4}{c}{Confusion Matrix}
cline{2-5}
multicolumn{1}{c}{} &multicolumn{4}{c}{Predicted}
%cline{2-5}
multicolumn{1}{c}{} & smash{Category} & 0--1 & 2--10 & multicolumn{1}{c}{11--200}
cline{2-5}
multirow{3.5}{*}{makebox[0pt][r]{Truth Data}}
& 0--1 & 17964 & 2437 & 1210
& 2--10 & 5093 & 11334 & 5209
& 11--200 & 1519 & 3302 & 16638
cline{2-5}
end{tabular}
end{table}
end{document}
I also added a different version that you may find more appealing.
The black corner in the second picture shows the left margin. Remove usepackage{showframe}
for the production version.
Answered by egreg on August 18, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP