Page LayoutDots in contents

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
tdc
Posts: 34
Joined: Fri Sep 12, 2008 1:52 am

Dots in contents

Post by tdc »

Hi there, i've been working with a friend teaching them latex, and some thing we came up against was trying to include a series of dots between an entry in the table of contents and the page number.

I.e

Chapter 1. First Chapter..............................1

We're working in the amsbook class, and here's a MWE :)

Code: Select all

\documentclass{amsbook}

% \usepackage{titletoc}
% \contentsmargin{2.55em}
% \dottedcontents{chapter}[1.5em]{}{2.3em}{1pc}
% \dottedcontents{section}[1.5em]{}{2.3em}{1pc}
% \dottedcontents{subsection}[3.8em]{}{3.2em}{1pc}

%\usepackage{tocloft}

\begin{document}
\tableofcontents

\chapter{Better Title}
	\section{Lower title}
		\subsection{Longer Title}
\chapter{next title} 

\end{document}



Also, does anyone know how, instead of getting

Code: Select all

1.1 This is a picture                          1
to get

Code: Select all

Figure 1.1 This is a picture                          1
in the list of figures?

Cheers, Tim

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Dots in contents

Post by gmedina »

Hi,

the titletoc package gives you solutions for both problems.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
tdc
Posts: 34
Joined: Fri Sep 12, 2008 1:52 am

Re: Dots in contents

Post by tdc »

Sorry, forgot to say that i've tried both Titletoc and tocloft both of which give errors (the code i'm using is given in the MWE above, with the two versions commented out)

the errors are about having missing } and then it complains that there are too many!???!!
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Dots in contents

Post by frabjous »

I'm afraid the amsbook class seems to be incompatible with tocloft. The following, for example, works fine:

Code: Select all

\documentclass{book}

\usepackage{tocloft}
\renewcommand{\cftchapdotsep}{\cftdotsep}

\begin{document}
\tableofcontents

\chapter{Better Title}
   \section{Lower title}
      \subsection{Longer Title}
\chapter{next title}

\end{document}
The package would also have a solution to your issues with the list of figures.

Is the amsbook class necessary?
tdc
Posts: 34
Joined: Fri Sep 12, 2008 1:52 am

Dots in contents

Post by tdc »

ish, partly because there's lots of errors cropping up when i change the class, partly due to the formatting of things like the chapter headings which i'm not sure how to recreate.

(interestingly, i'm coming across and error i've never seen anything like before

Code: Select all

Something's wrong--perhaps a missing \item. ...e {chapter}{\numberline {1}Introduction}{1}
)
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Dots in contents

Post by Juanjo »

It seems that, in the amsbook documentclass, toc lines are produced by the macro \@tocline, which has the following definition:

Code: Select all

\def\@tocline#1#2#3#4#5#6#7{\relax
  \ifnum #1>\c@tocdepth % then omit
  \else
    \par \addpenalty\@secpenalty\addvspace{#2}%
    \begingroup \hyphenpenalty\@M
    \@ifempty{#4}{%
      \@tempdima\csname r@tocindent\number#1\endcsname\relax
    }{%
      \@tempdima#4\relax
    }%
    \parindent\z@ \leftskip#3\relax \advance\leftskip\@tempdima\relax
    \rightskip\@pnumwidth plus4em \parfillskip-\@pnumwidth
    #5\leavevmode\hskip-\@tempdima #6\nobreak\relax
    \hfil\hbox to\@pnumwidth{\@tocpagenum{#7}}\par
    \nobreak
    \endgroup
  \fi}
If you replace \hfil (4th line from below) by, say, \dotfill, you get dots in the every toc entry. Perhaps it would be necessary a more involved macro to put dots only for certain entries (say, for example, for sections, subsections,..., but not for parts and chapters). To this end, one could take into account the first argument of \@tocline, which is the level entry ( -1 for part, 0 for chapter and so on).
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
tdc
Posts: 34
Joined: Fri Sep 12, 2008 1:52 am

Re: Dots in contents

Post by tdc »

Thanks for this, i tried adding the definition in with the change from hfil to dot fill however it doesn't seem to be picked up when i compile :(
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Dots in contents

Post by Juanjo »

The following example should work. Every TOC entry, except parts, has a dotted line.

Code: Select all

\documentclass{amsbook}

\makeatletter
\def\@tocline#1#2#3#4#5#6#7{\relax
  \ifnum #1>\c@tocdepth % then omit
  \else
    \par \addpenalty\@secpenalty\addvspace{#2}%
    \begingroup \hyphenpenalty\@M
    \@ifempty{#4}{%
      \@tempdima\csname r@tocindent\number#1\endcsname\relax
    }{%
      \@tempdima#4\relax
    }%
    \parindent\z@ \leftskip#3\relax \advance\leftskip\@tempdima\relax
    \rightskip\@pnumwidth plus4em \parfillskip-\@pnumwidth
    #5\leavevmode\hskip-\@tempdima #6\nobreak\relax
    \ifnum#1<0\hfill\else\dotfill\fi\hbox to\@pnumwidth{\@tocpagenum{#7}}\par
    \nobreak
    \endgroup
  \fi}
\makeatother


\begin{document}
\stepcounter{tocdepth} %include subsections in TOC
\tableofcontents

\part{Learning \LaTeX}
\chapter{Boxes}
\section{Horizontal boxes}
\section{Vertical boxes}
\chapter{The table of contents}
   \section{Dotted lines are not so difficult to obtain}
      \subsection{Really?}
      \subsection{Yes, of course}
\chapter{Other stuff} 

\end{document}
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
tdc
Posts: 34
Joined: Fri Sep 12, 2008 1:52 am

Re: Dots in contents

Post by tdc »

I forgot the makeatother / makeatletter oops :)


Thanks very much, this is perfect!!
tdc
Posts: 34
Joined: Fri Sep 12, 2008 1:52 am

Re: Dots in contents

Post by tdc »

I was wondering whether there was a similar edit to add the word "figure" in front of the numbering in the LOF?

Cheers,
Tim
Post Reply