
私は以下の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}
「CHAPTER」のないバージョンは次のとおりです。
\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}
結果は上記と同じです。