Dotted Line Equivalent of \rule – How to Create Dotted Lines in LaTeX

line

I'm looking for the dotted line equivalent of :

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

Something that looks like :

…………………….

Best Answer

There is a canonical TeX command: \leaders

https://www.tug.org/utilities/plain/cseq.html#leaders-rp

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