Search code examples
latex

Use segmented horizontal line to indicate column groups in a table


I am looking to break the horizontal lines in a Table to indicate grouping of several columns.

A picture for horizontal lines with breaks

Is there an elegant solution in Latex?


Solution

  • The package booktabs is the suitable option for achieving what you desire, coupled with the command \multicolumns.

    booktabs lets you use the cmidrule command: the first argument is, in this case, lr which means that you want to trimmer the left and the right part of the line, while the second argument refers to the columns you want to spam with this line. Check here for further information.

    The command multirow allows a text to span multiple columns: the first argument is the number of columns to be spanned, the second is the alignement and the third the text of the cell.

    \documentclass{article}
    \usepackage{booktabs}
    \usepackage{multirow}
    
    \begin{document}
    
    
    \begin{tabular}{ccccccccc}
    \multicolumn{3}{c}{XXX} & \multicolumn{3}{c}{XXX} & \multicolumn{3}{c}{XXX}\\
    \cmidrule(lr){1-3}\cmidrule(lr){4-6}\cmidrule(lr){7-9}
    xx & xx & xx & xx & xx & xx &  xx & xx & xx \\
    xx & xx & xx & xx & xx & xx &  xx & xx & xx \\
    xx & xx & xx & xx & xx & xx &  xx & xx & xx \\
    xx & xx & xx & xx & xx & xx &  xx & xx & xx \\
    xx & xx & xx & xx & xx & xx &  xx & xx & xx \\
    \end{tabular}
    
    
    \end{document}