How to merge cells with multirow in LaTeX?

How to merge cells with multirow in LaTeX?

The solution to your problem is very simple. You should use cline{4-7} instead of hline. Namely hline makes a horizontal line over the complete width of the table, while cline{4-7} will only make a horizontal line from column 4 until 7, and thus not crossing the first ones.

To get the text in front of the repeated words centered and merged, you can use multirow{}{}, again in combination with cline{}. More info about these commands at this link.

An example of the code is given below:

begin{table}[]
centering
caption{My caption}
label{my-label}
begin{tabular}{|l|l|l|l|l|l|l|}
hline
multirow{2}{*}{Oprave} & multirow{2}{*}{Zkratka} & multirow{2}{*}{Alg.} & multicolumn{4}{l|}{Chybovost %} \ cline{4-7} 
  &  &  & MAE & RSE & RMSE & RRSE \ hline
multirow{4}{*}{velikosti} & multirow{4}{*}{vel.} & NBM &  &  &  &  \ cline{3-7} 
 &  & c4.5 &  &  &  &  \ cline{3-7} 
 &  & kNN &  &  &  &  \ cline{3-7} 
 &  & SMO &  &  &  &  \ hline
multirow{4}{*}{bilateralne} & multirow{4}{*}{bilat.} & NBM &  &  &  &  \ cline{3-7} 
 &  & c4.5 &  &  &  &  \ cline{3-7} 
 &  & kNN &  &  &  &  \ cline{3-7} 
 &  & SMO &  &  &  &  \ hline
multirow{4}{*}{oprava} & multirow{4}{*}{zkratka} & NBM &  &  &  &  \ cline{3-7} 
 &  & c4.5 &  &  &  &  \ cline{3-7} 
 &  & kNN &  &  &  &  \ cline{3-7} 
 &  & SMO &  &  &  &  \ hline
multirow{4}{*}{oprava} & multirow{4}{*}{zkratka} & NBM &  &  &  &  \ cline{3-7} 
 &  & c4.5 &  &  &  &  \ cline{3-7} 
 &  & kNN &  &  &  &  \ cline{3-7} 
 &  & SMO &  &  &  &  \ hline
end{tabular}
end{table}

Resulting into:

Result

Note: if you have struggles with table generation, or you want a more quick way to easily make tables as you would do in Excel, you can use an online table generator for Latex.
I often use http://www.tablesgenerator.com/

How to merge cells with multirow in LaTeX?

Leave a Reply

Your email address will not be published.