55

I am trying to get a dotted line in the table instead of \hline, but I can't get the output.

arydshln and dashrule packages are available to get the dashed line, but I can't find any packages to get a dotted line in table.

Is any package available for this style?

RCV
  • 2,030
  • take a look at this : http://tex.stackexchange.com/a/10261/26074 – Hakan Apr 02 '14 at 11:44
  • yes i looked that page, they used arydshln package for getting the dashed line (---------------), but i need dotted lines (...........) – RCV Apr 02 '14 at 11:47

4 Answers4

55

The package arydshln by Hiroshi Nakashima provides dashed lines, but they can be changed to look like dots, somehow, by reducing the dash length and increasing the gap a little bit (both default to 4pt)

Change the lengths \dashlinedash, \dashlinegap accordingly and \arrayrulewidth eventually.

\documentclass{book}

\usepackage{arydshln}

\setlength{\dashlinedash}{0.2pt}
\setlength{\dashlinegap}{4.5pt}
\setlength{\arrayrulewidth}{0.2pt}

\begin{document}
\begin{tabular}{ll}
\hline
& \\
This is a & nice table \\
& \\
\hdashline
& \\
\end{tabular}


% Another combination of values
\setlength\dashlinedash{0.2pt}
\setlength\dashlinegap{1.5pt}
\setlength\arrayrulewidth{0.3pt}

\begin{tabular}{ll}
\hline
This is yet & another nice table \\
\hdashline
\end{tabular}


\end{document}  

enter image description here

Edit: In a previous version I had\usepackage{array} -- this package is not needed, so I removed it from the code.

29

Just playing around, I came up with a way to add dashed and [true] dotted horizontal lines to tabular entities. It could be made more robust, in that it assumes one has \tabcolsep border on each side of a column (which of course can be overridden by @{} macros). That aside, it automatically works for different font sizes and different values of \arraystretch.

it provides \tabdashline and \tabdotline which are kind of like \hline, but it only works on a single column (which means it can be changed from column to column). Parameters include \rulewidth, the thickness of the dash line, \replength, a repetition length for each dash/dot on the line, and a macro \dashfrac{}, for setting the dash length as fraction of \replength. Note that \rulewidth and \dashfrac{} have no effect on the \tabdotline, since it is using a period as the repeated glyph. However, the spacing of the dots is controlled by \replength.

\documentclass[10pt]{article}
\newlength\replength
\newcommand\repfrac{.33}
\newcommand\dashfrac[1]{\renewcommand\repfrac{#1}}
\setlength\replength{1.5pt}
\newcommand\rulewidth{.6pt}
\newcommand\tdashfill[1][\repfrac]{\cleaders\hbox to \replength{%
  \smash{\rule[\arraystretch\ht\strutbox]{\repfrac\replength}{\rulewidth}}}\hfill}
\newcommand\tabdashline{%
  \makebox[0pt][r]{\makebox[\tabcolsep]{\tdashfill\hfil}}\tdashfill\hfil%
  \makebox[0pt][l]{\makebox[\tabcolsep]{\tdashfill\hfil}}%
  \\[-\arraystretch\dimexpr\ht\strutbox+\dp\strutbox\relax]%
}
\newcommand\tdotfill[1][\repfrac]{\cleaders\hbox to \replength{%
  \smash{\raisebox{\arraystretch\dimexpr\ht\strutbox-.1ex\relax}{.}}}\hfill}
\newcommand\tabdotline{%
  \makebox[0pt][r]{\makebox[\tabcolsep]{\tdotfill\hfil}}\tdotfill\hfil%
  \makebox[0pt][l]{\makebox[\tabcolsep]{\tdotfill\hfil}}%
  \\[-\arraystretch\dimexpr\ht\strutbox+\dp\strutbox\relax]%
}
\begin{document}

Compare tabdashline to tabdotline to hline

\begin{tabular}{|c|}
\hline
top\\
\tabdashline
bottom\\
\hline
\end{tabular}
 vs.
\begin{tabular}{|c|}
\hline
top\\
\tabdotline
bottom\\
\hline
\end{tabular}
 vs.
\begin{tabular}{|c|}
\hline
top\\
\hline
bottom\\
\hline
\end{tabular}

Compare multiple columns:

\begin{tabular}{|c|c|}
\hline
top & column with 0.7 dashfrac\\
\tabdashline & \replength=.4ex\relax\dashfrac{0.7}\tabdashline
bottom & and a replength of .4ex\\
\hline
\end{tabular}

With arraystretch of 1.3:

\def\arraystretch{1.3}
\begin{tabular}{|c|}
\hline
top\\
\tabdashline
bottom\\
\hline
\end{tabular}
 vs.
\begin{tabular}{|c|}
\hline
top\\
\hline
bottom\\
\hline
\end{tabular}

\end{document}

enter image description here

2

The environment {NiceTabular} of nicematrix provides (among other features) a command \hdottedline to draw horizontal dotted lines and a specifier : in the preamble for the vertical rules.

\documentclass{article}
\usepackage{nicematrix}

\begin{document} \renewcommand{\arraystretch}{1.3} \begin{NiceTabular}{|c:c|} \hline first & second \ \hdottedline third & last \ \hline \end{NiceTabular} \end{document}

You need several compilations because nicematrix uses PGF/Tikz nodes.

Output of the above code

F. Pantigny
  • 40,250
1

An alternative solution with tblr environment of tabularray package:

\documentclass{article}

\usepackage{tabularray}

\begin{document}

\begin{tblr}{|c|[dotted]c|[dotted]c|} \hline Alpha & Beta & Gamma \ \hline[dotted] Epsilon & Zeta & Eta \ \hline[dotted] Iota & Kapp & Lambdaa \ \hline \end{tblr}

\end{document}

enter image description here

L.J.R.
  • 10,932