7

I want to make the dot separations I get using \dotfill in the glossaries package to match the dot separation I get in the tocloft package. The image below shows an entry from the table of contents on the top and an entry from the glossary on the bottom:

compare

According to this answer, I can create a command called \Dotfill which has different spacing than \dotfill. Below is the definition for \Dotfill where the space between dots in .33em.

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

I can then use \Dotfill to add dots after the description in my glossary:

renewcommand*\glspostdescription{\Dotfill}

I can manually change .33em until the dot spacing appears to match, but is there a better way to do this? According to the documentation for tocloft, the value describing the space between the dots in the table of contents is given by \@dotsep which has default value 4.5. I am not sure how to utilize this in what is given above.

Here is a minimal working example:

\documentclass{report}

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

\usepackage{tocloft}
\renewcommand{\cftchapleader}{\cftdotfill{\cftsecdotsep}}

\usepackage[toc]{glossaries}
\makeglossaries
\renewcommand*\glspostdescription{\Dotfill}

\begin{document}

\newglossaryentry{Cab}{name={$C[a,b]$},sort=C,description={The space of continuous functions defined on $[a,b]$}}

\tableofcontents

\printglossary

\chapter{Chap 1}

\gls{Cab}

\end{document}

To compile, you must run makeglossaries in between calls to latex.

2 Answers 2

5

You don't need to know the lengths or give them explicitly (which is surely prone to error). Simply use the settings from tocloft in your definition of \Dotfill:

\documentclass{report}
\usepackage[toc]{glossaries}
\usepackage{tocloft}

\newcommand\Dotfill{\cftdotfill{\cftsecdotsep}}
    \renewcommand{\cftchapleader}{\cftdotfill{\cftsecdotsep}}

\makeglossaries
\renewcommand*\glspostdescription{\Dotfill}

\begin{document}

\newglossaryentry{Cab}{name={$C[a,b]$},sort=C,description={The space of continuous functions defined on $[a,b]$}}

\tableofcontents

\printglossary

\chapter{Chap 1}

\gls{Cab}

\end{document}

You can even do without the \Dotfill command:

\documentclass{report}
\usepackage[toc]{glossaries}
\usepackage{tocloft}

\renewcommand{\cftchapleader}{\cftdotfill{\cftsecdotsep}}

\makeglossaries
\renewcommand*\glspostdescription{\cftdotfill{\cftsecdotsep}}

\begin{document}

\newglossaryentry{Cab}{name={$C[a,b]$},sort=C,description={The space of continuous functions defined on $[a,b]$}}

\tableofcontents

\printglossary

\chapter{Chap 1}

\gls{Cab}

\end{document}

The ToC

enter image description here

The entry in the glossary:

enter image description here

1

You can convert the value 4.5 to em to get the correct number. As is in the documentation, the 4.5 is in math units. There are 18 math units to 1 em.

18 / 4.5 = 4, so 4.5 math units is 1/4 * 1 em = 0.25 em.

Using the value 0.25 em will give you the correct standard spacing used by tocloft.

2
  • When I use .25em in the MWE above, it makes the dots even closer together than if I just used \dotfill. Jun 6, 2013 at 22:21
  • That might be, but then for whatever reason the default values of tocloft are not being used. According to the documentation, the default is 4.5 mu = 0.25 em. If the spacing than is not correct, the default values are altered somehow. However, Gonzalo's answer is definitely a better solution, even though it doesn't answer to question on how to use the 4.5 value :-)
    – Mythio
    Jun 9, 2013 at 14:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .