6

I'm trying to make a table with some numbers and a total result, as follows:

Age        Female Male Total
----------------------------
Under 10        5    8    13
10-30          57   61   118
30-60           5    1     6
Over 60         3    0     3
              ---  ---   ---
TOTAL          70   70   140
----------------------------

These three --- lines represent a kind of underline spanning a half of a row.

How can I draw it or specify the length of a tabular line?

2 Answers 2

11

The command \cmidrule has an optional argument in parenthesis where you can specify the side to be reduced.

Here is how your table can be achieved

\documentclass{article}

\usepackage{booktabs}  

\begin{document}

\begin{tabular}{lrrr}
Age        &  Female & Male & Total \\
\midrule
Under 10   &       5 &    8 &    13 \\
10-30      &      57 &   61 &   118 \\
30-60      &       5 &    1 &     6 \\
Over 60    &       3 &    0 &     3 \\
\cmidrule(l){2-2}\cmidrule(l){3-3}\cmidrule(l){4-4}
TOTAL      &      70  &  70 &   140 \\
\bottomrule
\end{tabular}
\end{document} 

enter image description here

Here is another version with fixed columns and where the length of \cmidrule is reduced by a fixed value:

\documentclass{article}

\usepackage{booktabs,array}  

\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}m{#1}}

\begin{document}

\begin{tabular}{l*{3}{R{1.2cm}}}
Age        &  Female & Male & Total \\
\midrule
Under 10   &       5 &    8 &    13 \\
10-30      &      57 &   61 &   118 \\
30-60      &       5 &    1 &     6 \\
Over 60    &       3 &    0 &     3 \\
\cmidrule(l{.7cm}){2-2}\cmidrule(l{.7cm}){3-3}\cmidrule(l{.7cm}){4-4}
TOTAL      &      70  &  70 &   140 \\
\bottomrule
\end{tabular}
\end{document} 

enter image description here

2
  • It doesn't work for me. It doesn't allow me to use paranthesis (it throws an "undefined control sequence" error). Using pdflatex throughout latexmk.
    – ABu
    Commented Mar 26, 2014 at 12:04
  • @Peregring-lk Try to pdflatex the file directly and see if it works. Commented Mar 26, 2014 at 12:10
9

The following example adds a rule above the total sum. The rule is made longer on both sides by the amount of \fboxsep. The MWE is taken from karlkoeller's answer.

\documentclass{article}

\usepackage{booktabs}

\newcommand*{\oline}[1]{%
  \kern-\fboxsep
  \vbox{%
    \hrule
    \kern1ex
    \hbox{%
      \kern\fboxsep
      #1%
      \kern\fboxsep
    }%
  }%
  \kern-\fboxsep
}

\begin{document}

\begin{tabular}{lrrr}
Age        &  Female & Male & Total \\
\midrule
Under 10   &       5 &    8 &    13 \\
10--30     &      57 &   61 &   118 \\
30--60     &       5 &    1 &     6 \\
Over 60    &       3 &    0 &     3 \\
TOTAL      & \oline{70} & \oline{70} & \oline{140} \\
\bottomrule
\end{tabular}
\end{document}

Result

You must log in to answer this question.

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