I need to produce a PDF document in which I need some "chapters" (along with its sections and subsections) to be non-numbered but still included in the ToC.
This is for my master thesis. I'm using the book document class, because I don't like memoir defaults.
If I use \chapter*
, then LaTeX remove the chapter from the ToC. But I'm required to have those as well in the ToC. Furthermore, the headings (fancy) are not changed with \chapter*
.
The overall structure of the thesis is:
\maketitle %% A custom one \frontmatter \tableofcontents \listoftables \listoffigures \chapter*{Abstract} \chapter*{Introduction} %% This "chapter" presents the whole thesis \mainmatter %% Here the real chapters are written \appendix %% Appendixes here %% bibliography
How can I make \chapter*
, \section*
, and \subsection*
to appear in the ToC and to modify the headers?
I think I may be using some packages that interfere with the way headers and footers are generated. The answer of smilingthax gets the first part of the question responded: I have now my \chapter*s on the TOC.
This is my full preamble:
\usepackage[sort&compress,round,semicolon]{natbib} \usepackage{babel} \usepackage{setspace} %% inputenc so we can write in spanish \usepackage[utf8]{inputenc} \usepackage{fixltx2e} % LaTeX patches, \textsubscript \usepackage{cmap} % fix search and cut-and-paste in PDF \usepackage{ifthen} %% \usepackage{float} % float configuration %% \floatplacement{figure}{TH} % place figures here definitely %% fontenc so we can use TrueType fonts \usepackage[T1]{fontenc} \usepackage{lmodern} \usepackage{garamond} \usepackage{graphicx} \usepackage{titlesec} \usepackage[table]{xcolor} %% Custom colors \definecolor{blue}{rgb}{0.2,0.2,0.95} \definecolor{green}{rgb}{0.2,0.95,0.2} \definecolor{red}{rgb}{0.95,0.2,0.2} \definecolor{cyan}{rgb}{0,0,0.95} \definecolor{ligthred}{rgb}{1, 0, 0} \definecolor{black}{rgb}{0, 0, 0} \definecolor{shade}{HTML}{D4D7FE} %light blue shade % Margins \usepackage[left=0.9in,top=1in,right=0.7in,bottom=1in]{geometry} \usepackage[pdftex, colorlinks=true, citecolor=ligthred, urlcolor=blue]{hyperref} \widowpenalty9000 \clubpenalty7000 \usepackage{titlesec} \newcommand{\bigrule}{\titlerule[0.5mm]} \renewcommand{\rmdefault}{bch} \titleformat{\chapter}[display] {\bfseries\Huge} {\garamond % DESCOMENTAR PARA SUBIR LOS CAPITULOS \vspace{-1.125in} \titlerule \filleft \Large\chaptertitlename\ \Large\thechapter}{0mm} {\filleft}[\vspace{0.5mm} \bigrule] \let\cite=\citep \usepackage{fancyhdr} \pagestyle{fancy} \fancyhf{} %% Clears all headers % admonition (specially marked topic) \providecommand{\DUadmonition}[2][class-arg]{% % try \DUadmonition#1{#2}: \ifcsname DUadmonition#1\endcsname% \csname DUadmonition#1\endcsname{#2}% \else \begin{center} \fbox{\parbox{0.9\textwidth}{#2}} \end{center} \fi } % title for topics, admonitions and sidebar \providecommand*{\DUtitle}[2][class-arg]{% % call \DUtitle#1{#2} if it exists: \ifcsname DUtitle#1\endcsname% \csname DUtitle#1\endcsname{#2}% \else \smallskip\noindent\textbf{#2}\smallskip% \fi } % error admonition title \providecommand*{\DUtitleerror}[1]{\DUtitle{\color{red}#1}} % fieldlist environment \ifthenelse{\isundefined{\DUfieldlist}}{ \newenvironment{DUfieldlist}% {\quote\description} {\enddescription\endquote} }{} % legend \ifthenelse{\isundefined{\DUlegend}}{ \newenvironment{DUlegend}{\small}{} }{} %%% Fallback definitions for Docutils-specific commands % numeric or symbol footnotes with hyperlinks \providecommand*{\DUfootnotemark}[3]{% \hyperlink{#2}{\textsuperscript{#3}}\raisebox{1em}{\label{#1}}% } \providecommand{\DUfootnotetext}[4]{% \begingroup% \renewcommand{\thefootnote}{% \protect\hyperlink{#2}{#3}}% \protect\raisebox{1em}{\protect\label{#1}}% \footnotetext{#4}% \endgroup% } \usepackage{booktabs} \usepackage{multirow} \usepackage{longtable} \newlength{\DUtablewidth} % internal use in tables \usepackage{tikz} \usepackage{bbding} \usetikzlibrary{arrows,fit} \usepackage{amsmath,bm,times} \newcommand{\mx}[1]{\mathbf{\bm{#1}}} % Matrix command \newcommand{\vc}[1]{\mathbf{\bm{#1}}} % Vector command
I don't think an specialized command exists for that. But you can use
\addcontentsline{toc}{chapter}{#1}
to add it to the TOC. BTW, I didn't have problems with \chapter* and fancy, so I used:
\newcommand\chap[1]{% \chapter*{#1}% \addcontentsline{toc}{chapter}{#1}}
Variations on this question have been asked and answered several times on the TeX-specific sister site:
\tableofcontents
does not list the unnumbered chapter\section*{something}
without removing it from the Table of Contents?\section*
so it behaves exactly as \section
except leaves out the numberI'm going to copy over Werner's answer to the last of those, because it demonstrates a different technique from any of the existing answers to this question: redefine \section
so that the only effect of \section*
is to skip printing the section numbers. This will work even when sectioning commands are being issued from the guts of packages you don't control.
[...] Redefine \section
to capture and condition on when the starred-version is used. Upon finding \section*
, issue it just like you would \section
, but remove the number-printing mechanism through an appropriate setting of the counter secnumdepth
.
xparse
provides an easy interface for (re)defining commands that may have a s
tarred version, as well as an o
ptional argument.
\usepackage{xparse} \let\oldsection\section \makeatletter \newcounter{@secnumdepth} \RenewDocumentCommand{\section}{s o m}{% \IfBooleanTF{#1} {\setcounter{@secnumdepth}{\value{secnumdepth}}% Store secnumdepth \setcounter{secnumdepth}{0}% Print only up to \chapter numbers \oldsection{#3}% \section* \setcounter{secnumdepth}{\value{@secnumdepth}}}% Restore secnumdepth {\IfValueTF{#2}% \section {\oldsection[#2]{#3}}% \section[.]{..} {\oldsection{#3}}}% \section{..} } \makeatother
(To do the same thing to \chapter
, \subsection
, etc., search-and-replace section
appropriately, and adjust the temporary value used for secnumdepth
.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With