Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm using the \dotfill command in a nomenclature to add units at the end of each line. Here is the code I'm using:

\usepackage[refpage]{nomencl}
\newcommand{\nomunit}[1]{%
   \renewcommand{\nomentryend}{\unskip\dofill[#1]}}
\renewcommand*{\pagedeclaration}[1]{\unskip, \hyperpage{#1}}

That works correctly, but in my table of contents where there is also automatic dot filling, spacing in not the same. So how could I modify the \dotfill spacing ? (to match the one of the table of contents actually)

share|improve this question

3 Answers 3

up vote 15 down vote accepted

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
share|improve this answer
    
Thanks that's perfect! And I've also discovered the \makeatletter and \makeatother commands by the way... And just for my information, where can I find the \dotfill definition ? –  Remy F Dec 3 '12 at 15:49
    
@RemyF who knows? I went to the chat and typed a message !!/texdef -t latex dotfill but texdef -t latex dotfill should work in your commandline somehow... –  tohecz Dec 3 '12 at 16:27

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

share|improve this answer
    
Great answer! How can I insert space after \mydots? For such result: A ... B? –  Poe Apr 28 at 9:25

@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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.