[Tex/LaTex] How to change hline thickness in tabular

formattingrulestables

I am just trying to get the table to look like the picture in the LaTeX Wiki book:

Table example

In this example shown, the very top and bottom \hline are thicker and darker than the ones in the middle of the table. The example does not show any special formatting, but when I do this in my document they all have the same thickness and darkness (the lines are all identical). I want the horizontal \hline to be thinner and lighter in the middle of the table as shown in the picture. Playing with the height and width had no discernible effect on this from what I could tell. How do I do this?

Best Answer

You can define your own \thickhline which is based on \hline, but with a different \arrayrulewidth:

enter image description here

\documentclass{article}

\makeatletter
\def\thickhline{%
  \noalign{\ifnum0=`}\fi\hrule \@height \thickarrayrulewidth \futurelet
   \reserved@a\@xthickhline}
\def\@xthickhline{\ifx\reserved@a\thickhline
               \vskip\doublerulesep
               \vskip-\thickarrayrulewidth
             \fi
      \ifnum0=`{\fi}}
\makeatother

\newlength{\thickarrayrulewidth}
\setlength{\thickarrayrulewidth}{2\arrayrulewidth}

\begin{document}

\begin{tabular}{ l | c | r }
  \hline
  1 & 2 & 3 \\
  \hline
  4 & 5 & 6 \\
  \hline
  7 & 8 & 9 \\
  \hline
\end{tabular}
\qquad
\begin{tabular}{ l | c | r }
  \thickhline
  1 & 2 & 3 \\
  \hline
  4 & 5 & 6 \\
  \hline
  7 & 8 & 9 \\
  \thickhline
\end{tabular}

\end{document}

In the above example, \thickhline inserts an \hrule that has a width double that of \arrayrulewidth. The latter has a default of 0.4pt. You can change \thickhline's width to whatever you want by adjusting \thickarrayrulewidth.

Related Question