I'm trying to define a \preface command that would be identical to \chapter except that
- It should not increment
\thechaptercounter. - In the TOC, "Preface" should go where "Chapter N" would normally go.
- In the footers, I want "Preface - {chapter title}" instead of "Chapter N - {chapter title}"
Since I'm using titlesec anyway, I figured I'd try out titleclass for the first time. The moment I added the preface titleclass, however, my section level entries disappeared from the TOC!
After a few hours of debugging, I'm not making any headway. Any idea what's going on here?
Here's a MWE:
\documentclass[oneside]{book}
\usepackage{blindtext}
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{hyperref}
\usepackage{xcolor}
% use arabic numbering throughout
\makeatletter
\renewcommand{\frontmatter}{\cleardoublepage \@mainmatterfalse}
\renewcommand{\mainmatter}{\cleardoublepage \@mainmattertrue}
\makeatother
%%%% begin preface defs %%%%
% see http://tex.stackexchange.com/a/17278/2041 and the titlesec manual
\titleclass{\preface}{top}[\part]
\newcounter{preface} % required when defining a new titleclass; accessible via \thepreface
\titleformat{\preface}
{\huge\bfseries}{}{0em}{}
% TODO verify that these dimensions make sense
\titlespacing*{\preface}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
% see autoref in hyperref manual
\newcommand{\prefaceautorefname}{preface}
%%%% end preface defs %%%%
%\setcounter{secnumdepth}{2} % I'm not sure if this is appropriate
\setcounter{tocdepth}{1} % only go down to the section level in TOC
%%%% begin TOC formatting %%%%
\titlecontents{chapter}
[3pt]
{\addvspace{1pc}}%
{\contentsmargin{0pt}%
\bfseries\large%
\llap{\makebox[1.5in]{%
{\color{gray}Chapter~\thecontentslabel}\hfill\textbf{\thecontentspage}\hspace{8pt}%
}}%
}
{\contentsmargin{0pt}\large}
{}
[\addvspace{.5pc}]
\titlecontents{preface}
[3pt]
{\addvspace{1pc}}%
{\contentsmargin{0pt}%
\bfseries\large%
\llap{\makebox[1.5in]{%
{\color{gray}Preface}\hfill\textbf{\thecontentspage}\hspace{8pt}%
}}%
}
{\contentsmargin{0pt}\large}
{}
[\addvspace{.5pc}]
\titlecontents{section}
[3pt]
{\addvspace{1pc}}%
{\contentsmargin{0pt}%
\large
\llap{\makebox[1.5in]{%
\hfill\textbf{\thecontentspage}\hspace{8pt}%
}}%
}
{\contentsmargin{0pt}\large}
{}
[\addvspace{.5pc}]
%%%% end TOC formatting %%%%
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\preface{Will This Work?}
%\chapter{Perhaps This Will Work}
\Blindtext[2]
\section{Under The Preface}
\Blindtext[3]
\subsection{To The Subway}
\Blindtext[2]
\subsection{Then To A Submarine}
\Blindtext[2]
\chapter{My First Chapter}
\blindtext[1]
\section{First Section Under A Chapter}
\Blindtext[2]
\section{Secondi}
\Blindtext[2]
\section{Triad}
\Blindtext[3]
\chapter{How About Another Chapter}
\section{Woot}
\Blindtext[2]
\end{document}

\setcounter{tocdepth}{2}levels are changed: preface=0, chapter=1, section=2,... – touhami Sep 05 '16 at 21:51\prefacean alias for\chapter*? – Bernard Sep 05 '16 at 21:55