57

I'm trying to reproduce this table:

table with thick first vertical and horizontal lines

(apologies for the terrible cameraphone pic)

I don't know how to get the slightly thicker leftmost and topmost line.

Here's a minimal example of what I have so far:

\documentclass[a4paper,12pt]{article}

\begin{document}

\begin{tabular}{c|c|c|c|c|c}
    $*$ & $a$ & $b$ & $c$ & $d$ & $e$ \\\hline
    $a$ & $a$ & $b$ & $c$ & $b$ & $d$ \\\hline
    $b$ & $b$ & $c$ & $a$ & $e$ & $c$ \\\hline
    $c$ & $c$ & $a$ & $b$ & $b$ & $a$ \\\hline
    $d$ & $b$ & $e$ & $b$ & $e$ & $d$ \\\hline
    $e$ & $d$ & $b$ & $a$ & $d$ & $c$
\end{tabular}

\end{document}

Is there an easy way to make the leftmost and topmost lines thicker?

0

3 Answers 3

56

You could define a thick version of \hline and a thick | as new column type as I did below. Both are based on the original code, only the thickness got changed from \arrayrulewidth to 1pt.

\documentclass[a4paper,png]{standalone}
\usepackage{array}

\makeatletter
\newcommand{\thickhline}{%
    \noalign {\ifnum 0=`}\fi \hrule height 1pt
    \futurelet \reserved@a \@xhline
}
\newcolumntype{"}{@{\hskip\tabcolsep\vrule width 1pt\hskip\tabcolsep}}
\makeatother


\begin{document}

\begin{tabular}{c"c|c|c|c|c}
    $*$ & $a$ & $b$ & $c$ & $d$ & $e$ \\\thickhline
    $a$ & $a$ & $b$ & $c$ & $b$ & $d$ \\\hline
    $b$ & $b$ & $c$ & $a$ & $e$ & $c$ \\\hline
    $c$ & $c$ & $a$ & $b$ & $b$ & $a$ \\\hline
    $d$ & $b$ & $e$ & $b$ & $e$ & $d$ \\\hline
    $e$ & $d$ & $b$ & $a$ & $d$ & $c$
\end{tabular}

\end{document}

Result


On request here a definition of a thick version of \cline:

\newcommand{\thickcline}[1]{%
    \@thickcline #1\@nil%
}

\def\@thickcline#1-#2\@nil{%
  \omit
  \@multicnt#1%
  \advance\@multispan\m@ne
  \ifnum\@multicnt=\@ne\@firstofone{&\omit}\fi
  \@multicnt#2%
  \advance\@multicnt-#1%
  \advance\@multispan\@ne
  \leaders\hrule\@height1pt\hfill
  \cr
  \noalign{\vskip-1pt}%
}
6
  • I truly love this answer, however, what if I want a thick line but from certain position on the table to another one (not coordinates, good idea anyway) like the usage of cline.
    – Hans
    Commented Apr 25, 2014 at 23:21
  • I mean partial horizontal thick lines.
    – Hans
    Commented Apr 25, 2014 at 23:34
  • 2
    @Hans: I added a definition for a \thickcline now. Note that if you mix it with normal \cline or \hline the lines will be top aligned, which doesn't look that good. Commented Apr 26, 2014 at 7:55
  • I'd really like to use this, but when I do there is a gap between the leftmost line and the left edge of the table and the rightmost line and the right edge of the table so the top line overhangs the lines going down and this looks terrible. What do I do to fix that? Commented Nov 10, 2014 at 15:01
  • 3
    @MartinScharrer Your definition of " gives me display problems when I try to place it as the left and right edge lines, e.g. \begin{tabular}{"c"c"} ... will make the horizontal lines go beyond the vertical ones at the edges. I made the following modification: \newcolumntype{[}{@{\vrule width 1pt\hspace{6pt}}} \newcolumntype{]}{@{\hspace{6pt}\vrule width 1pt}} \newcolumntype{!}{@{\hskip\tabcolsep\vrule width 1pt\hskip\tabcolsep}} which seems to get rid of the problem used as \begin{tabular}{[c!c]} .... My ! is the same as your ": for people using Kile the latter might be annoying.
    – Miguel
    Commented Jul 21, 2015 at 9:11
61

The package tabu provides such a modification by the optional arguments of the vertical line and the command \tabucline

\documentclass[a4paper,12pt]{article}
\usepackage{tabu}
\begin{document}

\begin{tabu}{c|[2pt]c|c|c|c|c}
    $*$ & $a$ & $b$ & $c$ & $d$ & $e$ \\\tabucline[2pt]{-}
    $a$ & $a$ & $b$ & $c$ & $b$ & $d$ \\\hline
    $b$ & $b$ & $c$ & $a$ & $e$ & $c$ \\\hline
    $c$ & $c$ & $a$ & $b$ & $b$ & $a$ \\\hline
    $d$ & $b$ & $e$ & $b$ & $e$ & $d$ \\\hline
    $e$ & $d$ & $b$ & $a$ & $d$ & $c$
\end{tabu}

\end{document}

However to produce nice tables avoid vertical lines and be spare with horizontal lines. For all this I recommend the package booktabs. Via google you will find a lot of examples.

4
  • Thank you for the super-fast and cogent response. I'm going to be typesetting a fair number of these tables which define binary operations on finite sets. Can you elaborate on how you think the appearance could be improved? Should this be a separate question?
    – Harold
    Commented Jan 20, 2012 at 18:49
  • 3
    This is possibly one case where rules may remain, as it's really a lattice and not a formal table. But I would avoid thick rules anyway.
    – egreg
    Commented Jan 20, 2012 at 18:56
  • @Harold: My note depends on normal tables. For your binary tables I would work in the same way but I would also increase the space between the cells. Commented Jan 20, 2012 at 21:18
  • Dear @MarcoDaniel, how can I color one table box in tabu environment? Thanks for help, R.
    – Dawson
    Commented Apr 7, 2015 at 16:27
5

Here is a solution with {NiceTabular} of nicematrix. That environment is similar to the classical {tabular} (of array) but creates PGF/Tikz nodes under the cells, rows and columns. It's possible to use those nodes to draw whatever rule you want with Tikz in the \CodeAfter.

\documentclass{article}
\usepackage{nicematrix,tikz}

\begin{document}

$\begin{NiceArray}{cccccc}[hvlines-except-borders]
    * & a & b & c & d & e \\
    a & a & b & c & b & d \\
    b & b & c & a & e & c \\
    c & c & a & b & b & a \\
    d & b & e & b & e & d \\
    e & d & b & a & d & c
\CodeAfter
    \tikz \draw [thick, line cap = round] (2-|1) -- (2-|last) (1-|2) -- (last-|2) ; 
\end{NiceArray}$

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the first code

With recent version of nicematrix (v. 6.11 of 2022-07-16), it's also possible to define a command (for horizontal rules) and a letter (for vertical rules) with any Tikz charateristic wished.

\documentclass[a4paper,12pt]{article}
\usepackage{nicematrix,tikz}

\begin{document}

\NiceMatrixOptions
  {
    custom-line = 
     {
       letter = I , % for the vertical rules
       command = boldhline , % the horizontal rules 
       total-width = 1 pt , 
       tikz = { line width = 1 pt } 
     }
  }

\begin{NiceTabular}{cIc|c|c|c|c}
    $*$ & $a$ & $b$ & $c$ & $d$ & $e$ \\\boldhline
    $a$ & $a$ & $b$ & $c$ & $b$ & $d$ \\\hline
    $b$ & $b$ & $c$ & $a$ & $e$ & $c$ \\\hline
    $c$ & $c$ & $a$ & $b$ & $b$ & $a$ \\\hline
    $d$ & $b$ & $e$ & $b$ & $e$ & $d$ \\\hline
    $e$ & $d$ & $b$ & $a$ & $d$ & $c$
\end{NiceTabular}

\end{document}

The output is not exactly the same, because, now, a space is reserved for the width of the rules (both horizontally and vertically).

enter image description here

You must log in to answer this question.

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