How to change dot spacing in \dotfill?

The definition of \dotfill is

\leavevmode \cleaders \hb@xt@ .44em{\hss .\hss }\hfill \kern \z@

The spacing is given by .44em, so you can put this in your preamble:

\makeatletter
\renewcommand \dotfill {\leavevmode \cleaders \hb@xt@ .33em{\hss .\hss }\hfill \kern \z@}
\makeatother

I would, however, suggest that you create your own command called e.g. \Dotfill, like this, so that the spacing is modified only when you want (\dotfill is used by LaTeX in various places):

\makeatletter
\newcommand \Dotfill {\leavevmode \cleaders \hb@xt@ .33em{\hss .\hss }\hfill \kern \z@}
\makeatother

This isn't really an answer, but I don't see how to add a link in the comments.

Look at Want to fill line with repeating string. That solution might work for you.

I took at look at The Advanced TeXbook suggested by that link. You could write something like \def\mydots{\xleaders\hbox to1em{\hfil.\hfil}\hfil}. You can change the 1em to a measure you'd prefer. BUT when I did my own sample of this, it didn't quite fill the page. Sigh. :(

\documentclass{article}
\usepackage{calc}
\usepackage{lipsum}
\pagestyle{empty}
\def\mydots{\xleaders\hbox to0.25em{\hfil.\hfil}\hfil}
\begin{document}

\lipsum[1]

A \mydots B

\lipsum[2]

\end{document}

enter image description here

I think the problem is with the final \hfil but when I try to get rid of it, I get an error.

Overfull \hbox (0.27779pt too wide) detected at line 10
 \OT1/cmr/m/n/10 . 
! Leaders not followed by proper glue.
<to be read again> 
                   B
l.10 A \mydots B

? 

When I rewrote \mydots as

\def\mydots{\leavevmode\xleaders\hbox to 0.25em{\hfil.\hfil}\hfill\kern0pt}

I got the result that I wanted. (Was I being too faithful to TeX within a LaTeX context?)

enter image description here


@tohecz has shown what you need to do, just a further comment on why your version didn't work.

You defined it with fil stretch (one l) which in the standard classes is the same as the \parfillskip glue used to allow the last line of a paragraph to be short. thus your paragraph

A \mydots B

had 2 fil worth of stretch, one coming from \mydots and one coming from \parfillskip. these will stretch the same amount thus B was pushed to the centre of the space between A and the right margin with dots to the left and glue to the right.

Tags:

Macros

Spacing