20

I hope this isn't a silly question, the thing is that I want to create a table with a midrule applied in just some cells, I mean something like that (just between Item, Animal and Description):

enter image description here

I've always used the comand midrule in order to insert a horizontal line in the table, but it is always applied to the whole row and thats just what I don't want to.

I hope somebody could help me out.

  • 6
    The code for this is in the booktabs documentation (texdoc booktabs) at the top of page 5. You use \cmidrule instead of \midrule. – Andrew Swann May 28 '13 at 8:02
  • @AndrewSwann, this question is still marked as unanswered but you solved the problem. Could you convert your comment in answer? – Fran Jun 29 '13 at 20:31
35

booktabs provides the command \cmidrule for rules that extend over only certain columns. One example would be:

Sample output

\documentclass{article}

\usepackage{booktabs}

\begin{document}

\begin{tabular}{lcr}
  \toprule
  A & B & C \\
  \cmidrule{1-2}
  D & E & F\\
  \cmidrule(lr{1em}){2-3}
  G & H & I\\
  \cmidrule[2pt](lr){1-1}
  J & H & K\\
  \bottomrule
\end{tabular}

\end{document}

The general syntax is

\cmidrule[thickness](shortening){colstart-colend}

where shortening specifies which end(s) l left or r right should be shortened. As standerd the shortening amount is 0.5em when l or r is specified; it can be changed for a given end by writing e.g. r{1em} instead of r.

The table in your example is exactly one of the examples in the booktabs manual, which also contains the code to generate it, see the top of page 5.

  • +1! Is there a similar command \ctoprule and/or \cbottomrule? – Jimmy R. Nov 11 '18 at 11:32
  • 1
    @JimmyR. Thank you. No these don't exist. For full width you can pass a thickness argument to all rules, e.g. \toprule[5pt]. For partial width I would want to see a sensible use case before suggesting a solution. – Andrew Swann Nov 11 '18 at 11:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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