# What's the dotted line equivalent of \rule?

I'm looking for the dotted line equivalent of :

\rule[<height>]{<width>}{<thickness>}


Something that looks like :

.........................

• You can have an approximation with the dashrule package. – Bernard Aug 23 '18 at 13:10
• \hbox to 10pc {\dotfill} – MadyYuvi Feb 11 '19 at 9:46

There is a canonical TeX command: \leaders

For example \hbox to 5cm{\leaders\hbox to 10pt{\hss . \hss}\hfil}

UPD: example explanation

1. \hbox to 5cm{} creates horizontal box. Here 5cm is the total length of the point line
2. \leaders is a command to create leaders. Leaders can create a horizontal or vertical redublication of any box. See more about leaders in Knuth's TeXBook, ch. 21 p 223.
3. \hbox to 10pt{\hss . \hss} is a TeX box - the first parameter of the leader. In this box: to 10pt is the size of the box - change it to make dots thicker or thinner, \hss . \hss means "use a dot . as a box content, but surround it with glue with infinite stretching and compression" - so, there will be no underfull or overfull warnings.
4. \hfil is a glue - the second parameter of the leader. It says how long the leader will be - till the end of the outer box.

TL;DR: to change the total width change the 5cm parameter, to change the width of one element change the 10pt parameter, to make not a dot but any other symbols (one or many) change . parameter

• An alternative with standard spacing is \dotfill, cf. tex.stackexchange.com/q/332122/15925 – Andrew Swann Feb 11 '19 at 8:27
• I didn't know about \leaders, could you elaborate a little more your answer? For example, how can you do the dots biggers? – CarLaTeX Feb 11 '19 at 8:32
• @CarLaTeX I tried. Can you check, is it better now? – Anton Lioznov Feb 11 '19 at 9:21
• The coolest thing about \leaders is that dots on different lines always line up as if it was “a window that lets you see part of an infinite row of boxes” (which is e.g. useful for the table of contents). If this is not important there's also \cleaders (for horizontally centred dots) and \xleaders (for slightly spaced out dots). – Circumscribe Feb 11 '19 at 9:30
• Very good, upvoted! – CarLaTeX Feb 11 '19 at 10:15

\hdashrule is only an approximation because the dots are little squares, but you can easily do what you need with TikZ.

I have created two commands, \dhorline (for horizontal rules) and \dvertline (for vertical ones), with the same syntax as \rule, where the dots are actual dots.

Here some examples:

\documentclass{article}
\usepackage{dashrule}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\newcommand{\dhorline}[3][0]{%
\tikz[baseline]{\path[decoration={markings,
mark=between positions 0 and 1 step 2*#3
with {\node[fill, circle, minimum width=#3, inner sep=0pt, anchor=south west] {};}},postaction={decorate}]  (0,#1) -- ++(#2,0);}}
\newcommand{\dvertline}[3][0]{%
\tikz[baseline]{\path[decoration={markings,
mark=between positions 0 and 1 step 2*#2
with {\node[fill, circle, minimum width=#2, inner sep=0pt, anchor=south west] {};}},postaction={decorate}] (0, #1) -- ++(0,#3);}}
\begin{document}
With \verb|\rule{10em}{4pt}| \rule{10em}{4pt}

With \verb|\hdashrule{10em}{4pt}{4pt}|
\hdashrule{10em}{4pt}{4pt}

With \verb|\dhorline{10em}{4pt}| \dhorline{10em}{4pt}

\vspace{4pt}
With \verb|\rule[-4ex]{40pt}{1em}| \rule[-4ex]{40pt}{1em}

\vspace{4pt}
With \verb|\dhorline[-4ex]{40pt}{1em}| \dhorline[-4ex]{40pt}{1em}

With \verb|\rule{4pt}{10em}| \rule{4pt}{10em}
with \verb|\dvertline{4pt}{10em}|
\dvertline{4pt}{10em}

\vspace{4pt}
With \verb|\rule[3ex]{4pt}{10em}| \rule[3ex]{4pt}{10em}
with \verb|\dvertline[3ex]{4pt}{10em}|
\dvertline[3ex]{4pt}{10em}
\end{document}