151

The title says it all:

In LaTeX tables: How do I make bold horizontal lines (typically \hline)?

8 Answers 8

108

Your question suggests that you might be interested in setting tabular rules (\hline's) of different weight in order to improve your typography rather than for the purposes of some simple "one-off" adjustment. If so, you should consider the booktabs package (if you haven't already done so). It provides canned weighted rules (\toprule, \midrule, etc) which, for typographical reasons, are defined in terms of fractions of em's rather than pt's, although these are very easy to define in pt's as well. Each rule can be locally or globally parameterised for your own specific weighting requirements. The package also provides macros like \heavyrulewidth and \lightrulewidth which you can use "as is" or can redefine to suit your particular needs. (Just as the author uses the term 'rule' where others might call it 'line', the author also uses the term 'width' where others might prefer to use 'thickness'.) The package is exceptionally easy to use. As a side-benefit, the documentation contains some very insightful guidelines about the ins and outs of good tabular typography.

4
  • I think this is the cleanest solution, however for this document I was already using tabularx tables and do not have the time to switch to booktabs :(
    – levesque
    Commented Sep 24, 2010 at 14:43
  • 10
    @JCL: strange, tabularx and booktabs should co-habitate quite well. Commented Sep 24, 2010 at 15:21
  • 3
    @levesque: Geoffrey is right — it's important to note that booktabs is not a new tabular environment; it provides "rules" to use in whatever tabular you're currently using. Commented Nov 29, 2010 at 23:18
  • 1
    After having really experimented with booktabs, I see that you both were right ;) It really does not imply much work to start using them!
    – levesque
    Commented Apr 4, 2011 at 15:44
72
\usepackage{makecell}

and use e.g.

\Xhline{2\arrayrulewidth}

instead of \hline

6
  • 1
    This works wrong for longtable. Commented Apr 2, 2012 at 12:35
  • @IvanBychkov: This does work for longtable. You should use makecell after longtable.
    – Leo Liu
    Commented Apr 3, 2012 at 10:23
  • 3
    @LeoLiu - great...this solution was the only one working straightforward!
    – Matteo
    Commented Nov 24, 2012 at 9:05
  • 3
    It does not work well with longtable: the bold line does not reach the border, it stops before and continues with a normal line. Odd. Commented Jan 15, 2015 at 14:42
  • for {tabular} env it worked great as I was already using the {makecell} pkg
    – alisa
    Commented Mar 6, 2020 at 3:25
46

You can also fix the default tickness of \hline or use a\specialrule also from booktabs or ctable package. (Since the ctable package imports booktabs packages, all commands from this package are available as well). This is a MWE:

MWE

\documentclass{article}
\usepackage{ctable} % for \specialrule command

\begin{document}
\centering

Default \texttt{\textbackslash hline}: 
\begin{tabular}{ccc}
\hline
1 & 2 & 3 \\ 
\hline
\end{tabular}
\bigskip

Thicker \texttt{\textbackslash hline}: 
\setlength{\arrayrulewidth}{.3em}
\bigskip
\begin{tabular}{ccc}
\hline
1 & 2 & 3 \\ 
\hline
\end{tabular}
\bigskip

Custom \texttt{special rule}s with  \texttt{ctable} package: 

\begin{tabular}{ccc}
\specialrule{.05em}{1em}{0em} 
 1 & 2 & 3 \\ 
\specialrule{.1em}{.05em}{.05em} 
1 & 2 & 3 \\ 
\specialrule{.2em}{.1em}{.1em} 
1 & 2 & 3 \\ 
\specialrule{.3em}{.2em}{.2em}
 1 & 2 & 3 \\
\specialrule{.4em}{.3em}{.3em}
1 & 2 & 3 \\    
\specialrule{.5em}{.4em}{.4em}
1 & 2 & 3 \\
\specialrule{.6em}{.5em}{0em}
\end{tabular}
\end{document}
1
  • It s useful for me right now!
    – Mikasa
    Commented May 25, 2022 at 13:39
17
\def\hlinewd#1{%
\noalign{\ifnum0=`}\fi\hrule \@height #1 %
\futurelet\reserved@a\@xhline} 

and then use \hlinewd{2pt} in your tables, for instance.

This should compile:

\documentclass[a4paper,10pt]{article}
\usepackage{tabularx}
\makeatletter
\def\hlinewd#1{%
\noalign{\ifnum0=`}\fi\hrule \@height #1 %
\futurelet\reserved@a\@xhline}
\makeatother
\begin{document}
\begin{tabular}{ccc}
\hlinewd{2pt}
plo & plo & plo\\ \hlinewd{2pt}
plo & plo & plo\\ \hlinewd{5pt}
plo & plo & plo
\end{tabular}
\end{document}
7
  • 1
    I get the following error message :" ! You can't use `\spacefactor' in internal vertical mode. <recently read> \spacefactor ". Is there a package that I need to include?
    – levesque
    Commented Sep 24, 2010 at 13:57
  • 1
    where did you put this definition? don't forget \makeatletter \makeatother when necessary.
    – pluton
    Commented Sep 24, 2010 at 14:03
  • With my other environment (re)definitions, before the begin document. I don't use the @ character anywhere else in my document than in that definiton.
    – levesque
    Commented Sep 24, 2010 at 14:07
  • I just edited the message above.
    – pluton
    Commented Sep 24, 2010 at 14:12
  • 2
    This works wrong for longtable. Commented Apr 2, 2012 at 12:32
13

I suggest you use the \specialrule command of the booktabs package, but should read the containing paragraph in the manual. Such a thick rule is generally frowned upon (especially in scientific texts).

An example could be:

\documentclass{article}
\usepackage{booktabs}

\begin{document}
\begin{table}
    \centering
    \begin{tabular}{rccc}
        \toprule
        Thing & Value & Value & Value\\
        \midrule
        A & 1 & 2 & 3\\
        B & 1 & 2 & 3\\
        C & 1 & 2 & 3\\
        \specialrule{2.5pt}{1pt}{1pt}
        D & 1 & 2 & 3\\
        E & 1 & 2 & 3\\
        \bottomrule
    \end{tabular}
\end{table}
\end{document}
8

A simple solution for completeness sake: setting the length register \arrayrulewidth with \setlength allows you to globally set the width of the line produced by \hline if you place it outside of the tabular environment.

Changing \arrayrulewidth inside tabular however doesn't seem to work.


Example document:

\documentclass{article}

\begin{document}
\setlength{\arrayrulewidth}{2pt}
\begin{tabular}{llll}
  \hline
  A & B & C & D
  \\\hline
  1 & 2 & 3 & 4    
\end{tabular}

\end{document}

Example document output:

Sample document output

1
  • If you put it outside tabular but within table, i.e. between begin{table} and begin{tabular}, it works fine
    – Alfonso
    Commented Jul 6, 2021 at 16:03
2

An alternative solution with tblr and booktabs environments of tabularray package: you can set widths and colors for hlines.

\documentclass{article}

\usepackage{xcolor}

\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}

\begin{tblr}{rccc}
    \hline[2pt,red5]
    Thing & Value & Value & Value\\
    \hline[1pt]
    A & 1 & 2 & 3\\
    B & 1 & 2 & 3\\
    C & 1 & 2 & 3\\
    \hline[1pt]
    D & 1 & 2 & 3\\
    E & 1 & 2 & 3\\
    \hline[2pt,blue5]
\end{tblr}

\bigskip

\begin{booktabs}{colspec={rccc},row{odd}={blue9}}
    \toprule
    Thing & Value & Value & Value\\
    \midrule
    A & 1 & 2 & 3\\
    B & 1 & 2 & 3\\
    C & 1 & 2 & 3\\
    \specialrule{2.5pt,teal5}{1pt}{1pt}
    D & 1 & 2 & 3\\
    E & 1 & 2 & 3\\
    \bottomrule
\end{booktabs}

\end{document}

enter image description here

-3

use longtblr like in the example below:

\usepackage{tabularray}


\begin{document}
\begin{longtblr}{colspec={|l|l|l|l|}}
\hline
Col 1 & Col 2 & Col 3 \\ \hline[5pt]
R2 & l & m & n \\ \hline
R3 & p & q & e \\ \hline
\end{longtblr}
\end{document}
3
  • 2
    Welcome! But sorry, this is not a new answer, because it already has been shown in L.J.R.'s answer above.
    – cabohah
    Commented Jun 3 at 11:50
  • hello. the package is the same but the method is different i guess Commented Jun 3 at 12:21
  • 3
    No, the first tblr example in that answer already shows the optional argument of \hline (and not only for the line thickness but also for the color). There is not need to use longtblr instead of tblr. And the concept is the same for both. BTW: L. J. R.'s example has the additional advantage, that it is a MWE. Yours is only a code snippet.
    – cabohah
    Commented Jun 3 at 12:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .