TeX - LaTeX Asked by vctu on December 27, 2020
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?
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
setlengthdashlinedash{0.2pt}
setlengthdashlinegap{1.5pt}
setlengtharrayrulewidth{0.3pt}
begin{tabular}{ll}
hline
This is yet & another nice table
hdashline
end{tabular}
end{document}
Edit: In a previous version I hadusepackage{array}
-- this package is not needed, so I removed it from the code.
Correct answer by user31729 on December 27, 2020
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}
newlengthreplength
newcommandrepfrac{.33}
newcommanddashfrac[1]{renewcommandrepfrac{#1}}
setlengthreplength{1.5pt}
newcommandrulewidth{.6pt}
newcommandtdashfill[1][repfrac]{cleadershbox to replength{%
smash{rule[arraystretchhtstrutbox]{repfracreplength}{rulewidth}}}hfill}
newcommandtabdashline{%
makebox[0pt][r]{makebox[tabcolsep]{tdashfillhfil}}tdashfillhfil%
makebox[0pt][l]{makebox[tabcolsep]{tdashfillhfil}}%
[-arraystretchdimexprhtstrutbox+dpstrutboxrelax]%
}
newcommandtdotfill[1][repfrac]{cleadershbox to replength{%
smash{raisebox{arraystretchdimexprhtstrutbox-.1exrelax}{.}}}hfill}
newcommandtabdotline{%
makebox[0pt][r]{makebox[tabcolsep]{tdotfillhfil}}tdotfillhfil%
makebox[0pt][l]{makebox[tabcolsep]{tdotfillhfil}}%
[-arraystretchdimexprhtstrutbox+dpstrutboxrelax]%
}
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=.4exrelaxdashfrac{0.7}tabdashline
bottom & and a replength of .4ex
hline
end{tabular}
With arraystretch of 1.3:
defarraystretch{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}
Answered by Steven B. Segletes on December 27, 2020
The environment {NiceTabular}
of nicematrix
provides (among other features) a command hdottedline
to draw horizontal dotted lines and a spcificier :
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.
Answered by F. Pantigny on December 27, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP