6

I have a table that looks like

\documentclass{article}

\usepackage{booktabs}

\begin{document}
\begin{tabular}{cc}
\toprule
A   &   B   \\
\midrule
Q   &   M   \\
W   &   N   \\
E   &   B   \\
R   &   V   \\
T   &   C   \\

Y   &   X   \\
U   &   L   \\
I   &   K   \\
O   &   J   \\
P   &   H   \\

A   &   5   \\
S   &   7   \\
D   &   8   \\
F   &   2   \\
G   &   4   \\
\bottomrule
\end{tabular}
\end{document}

The code has five-line blocks, which can be made distinguishable in the output with \midrule, but I consider that to be too distracting, as would be to number each row. I'd like to have a lighter rule, with tweakable space above and below it. I added some grey lines with Paint to a \midrule-less table.

Forcing a color onto \midrule with either \textcolor or \color produces errors, while using \rule allows coloring but requires making measurements to get the correct width.

L: Goal, R: <code>\midrule</code> attempt

  • 1
    \specialrule{width}{abovespace}{belowspace}. – Johannes_B Jun 28 '16 at 20:39
7

You can use \arrayrulecolor{<colour>} from colortbl to change the colour, and \specialrule{<width>}{<above>}{<below>} to set a rule of specific dimensions:

enter image description here

\documentclass{article}

\usepackage[table]{xcolor}
\usepackage{booktabs}

\begin{document}

\begin{tabular}{ c c c }
  \toprule
  A   &   B   \\
  \midrule
  Q   &   M   \\
  W   &   N   \\
  E   &   B   \\
  R   &   V   \\
  T   &   C   \\
  \arrayrulecolor{black!30}\midrule
  Y   &   X   \\
  U   &   L   \\
  I   &   K   \\
  O   &   J   \\
  P   &   H   \\
 \arrayrulecolor{black!50}\specialrule{3pt}{2\jot}{1pc}
  A   &   5   \\
  S   &   7   \\
  D   &   8   \\
  F   &   2   \\
  G   &   4   \\
  \arrayrulecolor{black}\bottomrule
\end{tabular}

\end{document}

Note that the rule colour change is global, so you'll have to reset to black if it's been changed before.

  • 1
    From this answer, I defined \newcommand{\greyrule}{\arrayrulecolor{black!30}\midrule\arrayrulecolor{black}} so that I can easily use \greyrule within tables. – Micah Smith Feb 2 at 23:16
4

For colours you have to use \arrayrulecolor{…} at the beginning of a row. For the thickness of \midrules, you can change the value of\lightrulewidth` or change the thickness of a specific rule with the optional argument. Demo:

\documentclass{article}

\usepackage{booktabs}
\usepackage[x11names, table]{xcolor}
\setlength\lightrulewidth{0.3pt}
\begin{document}

\begin{tabular}{ccc}
\toprule
A & B \\
\arrayrulecolor{Grey0!60!RoyalBlue3}\midrule[0.5pt]
Q & M \\
W & N \\
E & B \\
R & V \\
T & C \\
\arrayrulecolor{OrangeRed1! 50}\midrule
Y & X \\
U & L \\
I & K \\
O & J \\
P & H \\
\midrule
A & 5 \\
S & 7 \\
D & 8 \\
F & 2 \\
G & 4 \\
\arrayrulecolor{black}\bottomrule
\end{tabular}

\end{document} 

enter image description here

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.