5

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?

9

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.

  • This is very close, but the default \hrule width is still much thicker than that shown in the example. The standard \hrule is already thick enough, I need an even thinner one in between. I tried just reversing 2\arrayrulewidth to arrayrulewidth\2 but that won't compile. – Dan Jan 4 '18 at 22:42
  • @Dan: Then adjust \arrayrulewidth to something smaller than 0.4pt. Note that your viewer might snap to certain widths, making things appear thicker/thinner than they truly are. – Werner Jan 4 '18 at 22:44
  • I tried 0.1 and 0.01 and neither is thin enough. It barely made any change. It almost looks like maybe the inner lines are in a lighter gray in that image, maybe that will help. Not sure why their example appears to use formatting but they use it as a basic example without showing that formatting. – Dan Jan 4 '18 at 22:47
  • @Dan: Try this paste. Output: Adobe Reader; SumatraPDF, both @ 400% zoom. – Werner Jan 4 '18 at 23:08
  • 1
    @Dan -- i haven't followed the links, but \arrayrulewidth/2 isn't the correct syntax. if you want a fractional value, you have to use a decimal: .5\arrayrulewidth. (or 0.5 if you're really fastidious.) – barbara beeton Jan 4 '18 at 23:17
6

Three other possibilities:

  • the makecell package, in addition to allowing linebreaks in standard cells, defines the \Xhline and \Xcline commands which have the rule thickness as a mandatory argument.
  • the boldline package (from the shipunov bundle) defines \hlineB and clineB which take a numeric argument (how many times \arrayrulewidth, which defaults to 0.4pt). In addition, you can have varying thickness vertical rules, with V{some number} in the table preamble, in the place of |.
  • booktabs – which isn't really designed for that ;o) – allows to have thick horizontal rules compatible with vertical lines, with the \specialrule command, which takes three arguments: its thickness and the padding above and below. So I defined a shortcut for which the padding is set to 0. Advantage of booktabs: it's compatible with \arrayrulecolor whereas the first two are not.

Demo:

\documentclass{article}
\usepackage{array, boldline, makecell, booktabs}
\newcommand\btrule[1]{\specialrule{#1}{0pt}{0pt}}
\usepackage[svgnames, table]{xcolor}

\begin{document}

\begin{tabular}{l!{\vline width 1pt}c | r }
  \arrayrulecolor{IndianRed} \Xhline{1pt}
  1 & 2 & 3 \\
  \hline
  4 & 5 & 6 \\
  \hline
  7 & 8 & 9 \\
  \Xhline{1pt}
\end{tabular}
\qquad
\begin{tabular}{ lV{2.5}c | r }
  \hlineB{2.5}
  1 & 2 & 3 \\
  \hline
  4 & 5 & 6 \\
  \hline
  7 & 8 & 9 \\
  \hlineB{2.5}
\end{tabular}
\qquad
\begin{tabular}{ l!{\color{IndianRed}\vline width 1pt}c | r }
  \arrayrulecolor{IndianRed}
  \btrule{1pt}
  1 & 2 & 3 \\
  \arrayrulecolor{black} \hline
  4 & 5 & 6 \\
  \hline
  7 & 8 & 9 \\
  \arrayrulecolor{IndianRed}\btrule{1pt}
\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.