
Premisa: soy nuevo en fancyhdr. Definí el siguiente estilo elegante:
\lhead{}
\chead{\slshape\leftmark}
\rhead{}
\lfoot{}
\cfoot{\thepage}
\rfoot{}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
que dibujan correctamente el número y nombre del capítulo, la línea superior, la línea inferior y el número de página, en toda la página excepto la primera de cada capítulo.
Entonces, redefiní el estilo simple de la siguiente manera:
\fancypagestyle{plain}{
\lhead{}
\chead{}
\rhead{}
\lfoot{}
\cfoot{\thepage}
\rfoot{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0.4pt}}
que dibujan correctamente la línea superior, la línea inferior y el número de página en la primera página de cada capítulo (nota: el estilo simple omite el número de capítulo y el nombre del estilo elegante)
Ahora tengo un problema con la tabla de contenidos. La primera página del toc tiene un estilo sencillo (sin el número y el nombre del capítulo), pero las siguientes páginas tienen un estilo elegante (con el número y el nombre del capítulo). ¿Cómo puedo aplicar el estilo simple a TODA la página del toc?
Respuesta1
Dado que estás usando la book
clase, supongo que todo lo que aparece en el texto inicial debe estar bajo el plain
estilo de página:
\documentclass[a4paper,oneside]{book}
\usepackage{fancyhdr}
\usepackage{etoolbox}
\usepackage{lipsum} % just for the example
\pagestyle{fancy}
\fancypagestyle{main}{%
\fancyhf{}%
\fancyhead[C]{\slshape\leftmark}%
\fancyfoot[C]{\thepage}%
\renewcommand{\headrulewidth}{0.4pt}%
\renewcommand{\footrulewidth}{0.4pt}%
}
\fancypagestyle{plain}{%
\fancyhf{}%
\fancyfoot[C]{\thepage}%
\renewcommand{\headrulewidth}{0pt}%
\renewcommand{\footrulewidth}{0.4pt}%
}
\appto\frontmatter{\pagestyle{plain}}
\appto\mainmatter{\pagestyle{main}}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
%%% fill with some mock text
\def\testsec{\section{B}\lipsum}
\def\test{\chapter{A}
\testsec
\testsec
\testsec
\testsec
\testsec
\testsec
\testsec
\testsec
\testsec
\testsec
}
\test
\test
\test
\test
\test
\test
\test
\test
\end{document}
Sin embargo, recomendaría no seguir la regla.
Respuesta2
Pruebe esto en el preámbulo de su documento real.
\usepackage{etoc}
\renewcommand{\etocaftertitlehook}{\pagestyle{plain}}
\renewcommand{\etocaftertochook}{\thispagestyle{plain}}
(la edición se reemplaza \pagestyle
con \thispagestyle
en la línea de arriba)
MWE:
\documentclass{book}
\usepackage{fancyhdr}
\lhead{}
\chead{\slshape\leftmark}
\rhead{}
\lfoot{}
\cfoot{\thepage}
\rfoot{}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
\fancypagestyle{plain}{
\lhead{}
\chead{}
\rhead{}
\lfoot{}
\cfoot{\thepage}
\rfoot{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0.4pt}}
\usepackage{etoc}
\renewcommand{\etocaftertitlehook}{\pagestyle{plain}}
\renewcommand{\etocaftertochook}{\thispagestyle{plain}}
\begin{document}
\tableofcontents
\chapter{ONE}
\section {A}
\chapter{TW0}
\section {B}
\newcount\cnta
\loop
\chapter{\the\cnta}
\ifnum\cnta<50
\advance\cnta 1
\repeat
\end{document}