Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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

share|improve this answer
    
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. –  Peregring-lk Mar 26 at 12:04
    
@Peregring-lk Try to pdflatex the file directly and see if it works. –  karlkoeller Mar 26 at 12:10

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.