Как удалить заголовок из титульного листа

Как удалить заголовок из титульного листа

У меня есть заголовок, созданный с помощью fancyhdr. Он повторяется на всех страницах, включая разделы «Оглавление» и «Предисловие». Я пытался использовать \thispagestyle{empty}, но он работает только на первой странице, а мне нужно очистить его вfrontmatter

\documentclass[11pt]{book}
\usepackage{lipsum}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[RE]{\nouppercase{\leftmark}}
\fancyhead[LO]{\nouppercase{\rightmark}}

\renewcommand\headrulewidth{1.5pt}
\makeatletter
\def\headrule{{\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi
        \hrule\@height\headrulewidth\@width\headwidth
        \vskip 2pt% 2pt between lines
        \hrule\@height.5pt\@width\headwidth% lower line with .5pt line width
        \vskip-\headrulewidth
        \vskip-1.5pt}}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\thispagestyle{empty}
\frontmatter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Table of contents

\tableofcontents
\chapter{Preface}
\lipsum
\lipsum
\mainmatter
\chapter{Ch1}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\lipsum
\section{test}
\chapter{ch2}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}

\end {document}

решение1

изменить это

\thispagestyle{empty}

к

\pagestyle{empty}

и вставьте \pagestyle{fancy} здесь

\mainmatter
\chapter{Ch1}

Теперь это будет выглядеть так

\mainmatter
\pagestyle{fancy}
\chapter{Ch1}

решение2

Это то, что вам нужно? В вводной части есть только заголовок главы (Содержание/Предисловие), страницы первой главы и белые страницы имеют пустой стиль (для всего документа). Я добавил опцию twosideи использовал пакеты emptypageи xpatcheдля достижения этого.

\documentclass[11pt, twoside]{book}
\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage{xpatch, emptypage}%
 \pagestyle{fancy}
\fancyhf{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[RE]{\nouppercase{\leftmark}}
\fancyhead[LO]{\nouppercase{\rightmark}}

\renewcommand\headrulewidth{1.5pt}
\makeatletter
\def\headrule{{\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi
        \hrule\@height\headrulewidth\@width\headwidth
        \vskip 2pt% 2pt between lines
        \hrule\@height.5pt\@width\headwidth% lower line with .5pt line width
        \vskip-\headrulewidth
        \vskip-1.5pt}}
\makeatother

%%
\xpatchcmd{\chapter}{%
\thispagestyle{plain}}{%
\thispagestyle{empty}}{}{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\frontmatter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Table of contents
\tableofcontents
\chapter*{Preface}
\markboth{Preface}{Preface}
\addcontentsline{toc}{chapter}{Preface}
\lipsum
\lipsum[1-4]
\mainmatter
\pagestyle{fancy}
\chapter{Ch1}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\lipsum
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}

\chapter{ch2}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\lipsum
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}
\section{test}

\end {document} 

введите описание изображения здесь введите описание изображения здесь введите описание изображения здесь

Связанный контент