Page LayoutWhat is wrong with tocloft ?

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

What is wrong with tocloft ?

Post by Cham »

I'm having troubles just for adding dots in the ToC, using the tocloft package. It's clashing with my header. Here's a MWE that reproduces my problem :

Code: Select all

\documentclass[11pt,letterpaper,twoside]{article}
\usepackage[total={6in,10in},left=1.5in,top=0.5in,includehead,includefoot]{geometry}
% For the ToC :
\usepackage{tocloft}
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}  % Add . . . for sections.
% For headers :
\usepackage[pagestyles,medium]{titlesec}
\titleformat*{\subsubsection}{\bfseries\sffamily}

% Header :
\newpagestyle{principal}{
	\sethead[\thepage][][\slshape\footnotesize\MakeUppercase{Name on right}]{\slshape{\footnotesize{Name on left}}}{}{\thepage}
	\headrule
}

\begin{document}

\pagestyle{principal}

\tableofcontents

\newpage
\section{Title 1}

\newpage
\section{Title 2}

\newpage
\section{Title 3}

\end{document}
Compiling this code gives an error : "Undefined control sequence".

What is wrong with this code ?

EDIT : Hmm, changing the order of \pagestyle{principal} and \tableofcontents appears to solve the issue, but I don't understand what is happening here.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

What is wrong with tocloft ?

Post by Johannes_B »

Use the package that is shipped with titlesec.

Code: Select all

\documentclass[11pt,letterpaper,twoside]{article}
\usepackage[total={6in,10in},left=1.5in,top=0.5in,includehead,includefoot]{geometry}
% For the ToC :
\usepackage{titletoc}
\dottedcontents{section}[3.8em]{}{2.3em}{1pc}

\usepackage[pagestyles,medium]{titlesec}
\titleformat*{\subsubsection}{\bfseries\sffamily}

% Header :
\newpagestyle{principal}{
\sethead[\thepage][][\slshape\footnotesize\MakeUppercase{Name on right}]{\slshape{\footnotesize Name on left}}{}{\thepage}
\headrule
}

\begin{document}

\pagestyle{principal}

\tableofcontents

\newpage
\section{Title 1}

\newpage
\section{Title 2}

\newpage
\section{Title 3}

\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

What is wrong with tocloft ?

Post by Cham »

Why titletoc ? The ToC style is now vastly different. The spacing is too dense, and the section titles should be in bold.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

What is wrong with tocloft ?

Post by Stefan Kottwitz »

Something is not perfect with tocloft, but here's a quick fix for your preamble:

Code: Select all

\makeatletter
\let\ttl@savemark\relax
\makeatother
It just creates the still undefined macro so that error does not happen, as a workaround.

Stefan
LaTeX.org admin
Post Reply