TransWikia.com

Why table lines not right (multicolumn, multirow?)

TeX - LaTeX Asked by jrjrjr on June 1, 2021

I have used the code below to produce a table, however, it does not look correct. The regions that are causing issue are circled in red. Are the multicolumn/multirow packages not working in sync with tabular? Any suggestions to fix these issues?

Thanks in advance!

enter image description here

documentclass{article}
usepackage[utf8]{inputenc}

usepackage{boldline}

begin{table}[b!]
    caption{.}
 renewcommand{arraystretch}{1.15}%
centering
setlength{tabcolsep}{5.45pt}
begin{tabular}{l c || c c c | c c c | c c} % 
hlineB{2}
multirow{3}{*}{} & multirow{3}{*}{Year} & multicolumn{3}{c|}{Technique}   &  multicolumn{3}{c|}{Type}   & multicolumn{2}{c}{Detail}
          &   & multirow{2}{*}{Type}  &$tau$ & multirow{2}{*}{Idea}   & multicolumn{3}{c|}{$bar{u}$}   & multicolumn{2}{c}{Idea}
    &   &  & [$-$] & &  $a$ & $b$ & $c$ & 1 & 2   hline hline
& 2020 & -- & -- & -- & -- & -- & -- & -- & --  
hlineB{2}
end{tabular}
end{table}
end{document}

Since the answers refer to the original code of this question, it is provided here for reference. The above code has been edited by the OP.

enter image description here

documentclass{article}
usepackage[utf8]{inputenc}

begin{document}
begin{table}[b!]
    caption{.}
 renewcommand{arraystretch}{1.15}
centering
setlength{tabcolsep}{5.45pt}
begin{tabular}{l c || c c c | c c c | c c} 
toprule
        multirow{3}{*}{} & multirow{3}{*}{Year} & multicolumn{3}{c}{Technique}   &  multicolumn{3}{c}{Type}   & multicolumn{2}{c}{Detail}
          &   & multirow{2}{*}{Type}  &$tau$ & multirow{2}{*}{Idea}   & multicolumn{3}{c}{$bar{u}$}   & multicolumn{2}{c}{Idea}
    &   &  & [$-$] & &  $a$ & $b$ & $c$ & 1 & 2   hline hline
& 2020 & -- & -- & -- & -- & -- & -- & -- & --  
bottomrule
end{tabular}
end{table}
end{document}

2 Answers

As already pointed out in the comments, if you want vertical rules, you should not use the booktabs package and stick to the regular hline macro.

Also, if you use multicols, you need to tell them in the column definition that you want to have a vertical rule. So, instead of multicolumn{3}{c}{...}, you should write multicolumn{3}{c|}{...} where appropriate.

documentclass{article}
usepackage[utf8]{inputenc}

usepackage{multirow}

begin{document}
begin{table}[b!]
caption{.}
renewcommand{arraystretch}{1.15}
centering
setlength{tabcolsep}{5.45pt}
begin{tabular}{l c || c c c | c c c | c c} 
hline
multirow{3}{*}{} & multirow{3}{*}{Year} & multicolumn{3}{c|}{Technique} &  multicolumn{3}{c|}{Type} & multicolumn{2}{c}{Detail} 
 &  & multirow{2}{*}{Type} & $tau$ & multirow{2}{*}{Idea} & multicolumn{3}{c|}{$bar{u}$} & multicolumn{2}{c}{Idea} 
 &  &  & [$-$] & &  $a$ & $b$ & $c$ & 1 & 2   hline hline
 & 2020 & -- & -- & -- & -- & -- & -- & -- & --  
hline
end{tabular}
end{table}
end{document}

enter image description here

Correct answer by Jasper Habicht on June 1, 2021

If you actually want to use vertical rules with the horizontal rules of booktabs (which is not at all in the spirit of booktabs), you should use {NiceTabular} of nicematrix.

documentclass{article}
usepackage{caption}
usepackage{nicematrix}
usepackage{booktabs}

begin{document}
begin{table}[b!]
caption{My Caption}
renewcommand{arraystretch}{1.15}
centering
setlength{tabcolsep}{5.45pt}
begin{NiceTabular}{c || c c c | c c c | c c} 
toprule
& Block{1-3}{Technique} &&&  Block{1-3}{Type} &&& Block{1-2}{Detail} 
Year & Block{2-1}{Type} & $tau$ & Block{2-1}{Idea} & Block{1-3}{$bar{u}$} &&& Block{1-2}{Idea} 
&  & [$-$] & &  $a$ & $b$ & $c$ & 1 & 2   
hlinehline
2020 & -- & -- & -- & -- & -- & -- & -- & --  
bottomrule
end{NiceTabular}
end{table}
end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

Answered by F. Pantigny on June 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP