5

I'm working on a table with underlined headings, where each heading spans over two columns.

I'm trying to understand how to use the \extracolsep function to create space between the lines for every second coloumn.

Can someone help?

Here is the relevant part of my code:

\begin{table}[htbp]\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{Price model effects}
\begin{tabular}{l*{6}{c}}

\hline\hline

             &\multicolumn{2}{c}{{Residual waste}}&\multicolumn{2}{c}{{Plastic}}&\multicolumn{2}{c}{{Paper}} \\ \cline{2-3} \cline{4-5} \cline{5-6} \cline{6-7}

            &\multicolumn{1}{c}{Kg per capita}&\multicolumn{1}{c}{Ratio}&\multicolumn{1}{c}{Kg per capita}&\multicolumn{1}{c}{Ratio}&\multicolumn{1}{c}{Kg per capita}&\multicolumn{1}{c}{Ratio}\\

Thanks a lot!

2
  • 1
    Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. Apr 5, 2019 at 11:44
  • Consider wswitching to the booktabs packages and its special lines, they have much better build in spacing.
    – daleif
    Apr 5, 2019 at 11:57

2 Answers 2

5

Using \extracolsep doesn't make much sense when using a tabular environment. You should be using a tabular* environment.

enter image description here

\documentclass{article}
\usepackage{array}  % for "\extrarowheight" macro
\usepackage[skip=0.333\baselineskip]{caption} % optional
\begin{document}
\begin{table}[htbp]
    %% \centering
    \setlength\tabcolsep{0pt}
    \setlength\extrarowheight{2pt} for a more open "look"
    \caption{Price model effects}

    \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}*{6}{c}}

    \hline 
    \multicolumn{2}{c}{Residual waste} & 
    \multicolumn{2}{c}{Plastic} & 
    \multicolumn{2}{c}{Paper} \\ 
    \cline{1-2} \cline{3-4} \cline{5-6} 
    Kg per capita & Ratio & 
    Kg per capita & Ratio & 
    Kg per capita & Ratio \\
    \hline
    \end{tabular*}
\end{table}
\end{document}
1
  • 1
    Thanks a lot! This was super helpful.
    – Mia Hansen
    Apr 5, 2019 at 12:20
0

I would use cmidrule from the booktabs package. It has argument trim which allows you to make the line slightly shorter:

\documentclass{article}
\usepackage{booktabs}

\begin{document}
    \begin{tabular}{ll ll ll}
    \hline 
    \multicolumn{2}{c}{Residual waste} & 
    \multicolumn{2}{c}{Plastic} & 
    \multicolumn{2}{c}{Paper} \\ 
      \cmidrule(lr){1-2}  % trim from left/right
      \cmidrule(lr){3-4}  % note: in parenthesis, not brackets
      \cmidrule(lr){5-6}
    Kg per capita & Ratio & 
    Kg per capita & Ratio & 
    Kg per capita & Ratio \\
    \hline
    \end{tabular*}
\end{document}

This will give you

enter image description here

Obviously, you can use other packages to fine-tune the look.

2
  • Welcome to tex.sx. Jan 31 at 22:07
  • The above solution by @Ott Toomet works. It is very straightforward, considering that \cmidrule(lr){s-e} is not much inconvenient compared to \cline{s-e}, and we can avoid the cryptic \extracolsep. May 3 at 10:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .