Dotted line instead of \hline in table environment
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}
Edit: In a previous version I had\usepackage{array}
-- this package is not needed, so I removed it from the code.
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}