
У меня есть следующее WME:
\documentclass[twoside]{book}
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,headheight=28pt,bindingoffset=6mm]{geometry}
\usepackage[pagestyles]{titlesec}
\usepackage{lipsum}
\usepackage{fancyhdr}
\titleformat{\chapter}[display]
{\normalfont\bfseries}{}{10pt}{\Huge\thechapter.\quad}
\fancypagestyle{mypagestyle}{%
\fancyhf{}% Clear header/footer
\fancyhead[OC]{\thechapter.\quad\chaptertitle}% Author on Odd page, Centred
\fancyhead[EC]{\thechapter.\quad\chaptertitle}% Title on Even page, Centred
\fancyfoot[C]{\thepage}%
\renewcommand{\headrulewidth}{.4pt}% Header rule of .4pt
}
\pagestyle{mypagestyle}
\begin{document}
\pagestyle{mypagestyle}
\chapter{Introduction}
\lipsum[1-40]
\end{document}
Используя этот WME, заголовки отображают только номер главы. Как мне заставить заголовки отображать название главы?
решение1
Вы можете сделать это с помощью \leftmark
.
\documentclass[twoside]{book}
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,headheight=28pt,bindingoffset=6mm]{geometry}
\usepackage[pagestyles]{titlesec}
\usepackage{lipsum}
\usepackage{fancyhdr}
\titleformat{\chapter}[display]
{\normalfont\bfseries}{}{10pt}{\Huge\thechapter.\quad}
\fancypagestyle{mypagestyle}{%
\fancyhf{}% Clear header/footer
\fancyhead[OC]{\leftmark}% Author on Odd page, Centred
\fancyhead[EC]{\leftmark}% Title on Even page, Centred
\fancyfoot[C]{\thepage}%
\renewcommand{\headrulewidth}{.4pt}% Header rule of .4pt
}
\pagestyle{mypagestyle}
\begin{document}
\pagestyle{mypagestyle}
\chapter{Introduction}
\lipsum[1-40]
\end{document}
Вот версия без «ГЛАВЫ»:
\documentclass[twoside]{book}
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,headheight=28pt,bindingoffset=6mm]{geometry}
\usepackage[pagestyles]{titlesec}
\usepackage{lipsum}
\usepackage{fancyhdr}
\titleformat{\chapter}[display]
{\normalfont\bfseries}{}{10pt}{\Huge\thechapter.\quad}
\usepackage{expl3,xparse}
\ExplSyntaxOn
\cs_generate_variant:Nn \tl_set:Nn {Nx}
\NewDocumentCommand{\replace}{mmm}
{
\pintodoido_replace:nnn {#1} {#2} {#3}
}
\tl_new:N \l_pintodoido_input_text_tl
\tl_new:N \l_pintodoido_search_tl
\tl_new:N \l_pintodoido_replace_tl
\cs_new_protected:Npn \pintodoido_replace:nnn #1 #2 #3
{
\tl_set:Nf \l_pintodoido_input_text_tl { #1 }
\tl_set:Nn \l_pintodoido_search_tl { #2 }
\tl_set:Nn \l_pintodoido_replace_tl { #3 }
\regex_replace_all:nnN { \b\u{l_pintodoido_search_tl}\b } { \u{l_pintodoido_replace_tl} } \l_pintodoido_input_text_tl
\tl_use:N \l_pintodoido_input_text_tl
}
\ExplSyntaxOff
\fancypagestyle{mypagestyle}{%
\fancyhf{}% Clear header/footer
\fancyhead[OC]{\replace{\leftmark}{Chapter}{}}% Author on Odd page, Centred
\fancyhead[EC]{\replace{\leftmark}{Chapter}{}}% Title on Even page, Centred
\fancyfoot[C]{\thepage}%
\renewcommand{\headrulewidth}{.4pt}% Header rule of .4pt
}
\pagestyle{mypagestyle}
\begin{document}
\pagestyle{mypagestyle}
\chapter{Introduction}
\lipsum[1-40]
\end{document}
решение2
Вы можете использовать
\AtBeginDocument{%
\renewcommand*\chaptermark[1]{\markboth{\thechapter.\quad#1}{}}%
}
чтобы удалить название главы из заголовка.
\documentclass[twoside]{book}
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,headheight=28pt,bindingoffset=6mm]{geometry}
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\normalfont\bfseries}{}{10pt}{\Huge\thechapter.\quad}
\usepackage{fancyhdr}
\AtBeginDocument{%
\renewcommand*\chaptermark[1]{\markboth{\thechapter.\quad#1}{}}%
}
\fancypagestyle{mypagestyle}{%
\fancyhf{}% Clear header/footer
\fancyhead[C]{\leftmark}%
\fancyfoot[C]{\thepage}%
\renewcommand{\headrulewidth}{.4pt}% Header rule of .4pt
}
\pagestyle{mypagestyle}
\usepackage{lipsum}% for dummy text
\begin{document}
\chapter{Introduction}
\lipsum[1-40]
\end{document}
Или, может быть, нет необходимости в дополнительном стиле страницы и вы можете использовать стиль fancy
:
\documentclass[twoside]{book}
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,headheight=28pt,bindingoffset=6mm]{geometry}
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\normalfont\bfseries}{}{10pt}{\Huge\thechapter.\quad}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand*\chaptermark[1]{\markboth{\thechapter.\quad#1}{}}
\fancyhf{}% Clear header/footer
\fancyhead[C]{\leftmark}%
\fancyfoot[C]{\thepage}%
\usepackage{lipsum}% for dummy text
\begin{document}
\chapter{Introduction}
\lipsum[1-40]
\end{document}
Результат тот же, что и выше.