78

In a normal table, you can use the \hline command to draw a horizontal line. I am trying to make this line a dashed horizontal line.

I have found the package dashrule via this answer, but this only works for \rule situations; i.e. it can't be directly used as a line in a table, and LaTeX won't compile it. Conversely, I've tried wrapping the \hdashrule in a multicolumn:

\multicolumn{5}{|c|}{\hdashrule{130mm}{1pt}{4pt}} \

However, the padding around the table cell breaks the flow of the table, and the horizontal rule is not aligned with the other \hlines of the table. (It also means that the rule width must be specified manually.)

Is there any way to make a \hline dashed without resorting to tables-in-tables? Can you force a single table cell to have no vertical or horizontal margins and padding?

jevon
  • 1,190
  • Maybe you can help on this question: http://tex.stackexchange.com/questions/171518/how-to-create-vertical-and-horizontal-dotted-lines-in-a-matrix? – wonderich Apr 14 '14 at 23:24
  • Does it help? https://tex.stackexchange.com/a/629520/38244 (2nd solution) – hola Jan 09 '22 at 06:27

3 Answers3

123

The arydshln package offers you the \hdashline and \cdashline commands which are the dashed counterparts of \hline and \cline, respectively. A little example (including also a vertical dashed line):

\documentclass{report}
\usepackage{arydshln}

\begin{document}

\begin{tabular}{c:cc}
   column1a & column2a & column3a \\
   column1b & column2b   & column3b\\ \hdashline
   column1c & column2c & column3c \\ \cdashline{1-2}
   column1d & column2d & column3d \\
\end{tabular}

\end{document}

You can also specify how wide the dashes should be by specifying a ratio. For a dotted line write

\hdashline[0.5pt/5pt]
Moriambar
  • 11,466
Gonzalo Medina
  • 505,128
  • 18
    It seems like that \usepackage{arydshln} is not compatible with \usepackage{tabularx}. They cannot coexist. Is there any resolution for this? – wonderich Apr 14 '14 at 22:46
  • 1
    Maybe you can help on this question: http://tex.stackexchange.com/questions/171518/how-to-create-vertical-and-horizontal-dotted-lines-in-a-matrix? – wonderich Apr 14 '14 at 23:23
  • spacing never comes our right when I use \hdashline, not sure what the deal is. – travelingbones Nov 02 '16 at 01:00
  • @wonderich At least just having both packages loaded doesn't seem to cause any problems (in 2022) – kuropan Mar 10 '22 at 10:18
  • 1
    Note that \usepackage{arydshln} also breaks in-table colouring with \colour{}{} – user35443 Jul 12 '22 at 15:19
  • arydshln also conflicts with longtable – Pygmalion May 15 '23 at 15:49
  • @user35443 I had the same problem. What worked for me was calling \usepackage[table]{xcolor} and then \usepackage{arydshln}, and to colour a table cell use \cellcolor. – Mew Dec 02 '23 at 16:10
5

An alternative solution for dash lines with tblr environment of tabularray package:

\documentclass{report}

\usepackage{tabularray}

\begin{document}

\begin{tblr}{c|[dashed]cc} column1a & column2a & column3a \ column1b & column2b & column3b \ \hline[dashed] column1c & column2c & column3c \ \cline[dashed]{1-2} column1d & column2d & column3d \ \end{tblr}

\end{document}

enter image description here

L.J.R.
  • 10,932
1

With the package nicematrix, you can create tools which will draw rules in your environment {NiceTabular} (of nicematrix) with Tikz: all the styles of Tikz may be used...

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

\NiceMatrixOptions { custom-line = { letter = : , command = dashedline , ccommand = cdashedline , tikz = dashed } }

\begin{document}

\renewcommand{\arraystretch}{1.4}

\begin{NiceTabular}{c:cc} column1a & column2a & column3a \ column1b & column2b & column3b \ \dashedline column1c & column2c & column3c \ \cdashedline{1-2} column1d & column2d & column3d \ \end{NiceTabular}

\end{document}

Output of the above code

F. Pantigny
  • 40,250