番号付けされていない章と節のヘッダーに章と節のタイトルを交互に表示する

番号付けされていない章と節のヘッダーに章と節のタイトルを交互に表示する

論文の最終草稿のフォーマットを整えているのですが、ヘッダーに表示される章と節のタイトルに問題があることに気付きました。

現在、私は fancyhdr を使用して、ヘッダー内の交互のページに章と節のタイトルを表示しています。別の理由から、導入章と結論章に番号を付けたくありませんし、各章の結論セクションに番号を付けたくありません。これを実現するために、\chapter* コマンドと \section* コマンドを使用しました。ただし、これにより、ヘッダーの一部に表示される章/節のタイトルに関して、次の 3 つの望ましくない結果が生じました。

  1. 「目次」は、序文のヘッダーに章のタイトルとして表示されます。

ここに画像の説明を入力してください

しかし、私は「はじめに」と言いたいです。

  1. 前のセクション名は、各章の最後のセクションのヘッダーにセクション タイトルとして表示されます。

ここに画像の説明を入力してください

しかし、私は「結論」と言いたいです。

  1. 前の章のタイトルは、結論の章のヘッダーの章タイトルとして表示されます。

ここに画像の説明を入力してください

もう一度、これを「結論」としたいと思います。

MWE は次のとおりです。

\documentclass[12pt, twoside]{report}

\usepackage[explicit]{titlesec} %adjust titles
\usepackage{lipsum} %random text

%%%%%%%%Chapter and section titles in headers
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{} %clears header
\fancyhead[CE]{\nouppercase{\textit{\leftmark}}} %puts chapter title on even page in lower-case italics
\fancyhead[CO]{\nouppercase{\textit{\rightmark}}} %puts section title on odd page in lower-case italics
\renewcommand{\headrulewidth}{0pt} %gets rid of line
\renewcommand{\chaptermark}[1]{\markboth{#1}{}} %gets rid of chapter number
\renewcommand{\sectionmark}[1]{\markright{#1}} %gets rid of section number
%%%%%%%%%

\titleformat{\chapter}[display]{\LARGE\bfseries\centering}{\thechapter}{10pt}{#1}
\titleformat{\section}{\normalfont\fontsize{20}{20}\centering}{\thesection}{1em}{\MakeUppercase{#1}}
\titleformat{\subsection}{\normalfont\centering}{\thesubsection}{1em}{\textit{{#1}}}

\usepackage{subfiles} %allows multi-file projects

\setcounter{tocdepth}{1} %removes subsubsections from toc

%%%%%%%%%removes dots from toc
\makeatletter 
\renewcommand{\@dotsep}{10000} 
\makeatother
%%%%%%%%%

\begin{document}

\tableofcontents

\chapter*{Introduction}
\addcontentsline{toc}{chapter}{Introduction}

\renewcommand{\thesection}{\arabic{section}}

\section{An Introductory Section}

\lipsum
\lipsum[1]

\section{Another Introductory Section}

\lipsum

\chapter{A Chapter}
\renewcommand{\thesection}{\thechapter.\arabic{section}}


\lipsum[2-3]

\section{A Section}

\lipsum[4-8]

\section*{Conclusion}

\lipsum[8-9]

\chapter{Another Chapter}
\renewcommand{\thesection}{\thechapter.\arabic{section}}


\lipsum[1-2]

\chapter*{Conclusion}
\addcontentsline{toc}{chapter}{Conclusion}

\lipsum

\end{document}

同様の質問が寄せられていることは承知しています(例:目次と見出しに番号のない章) ですが、KOMA-Script に関するもののようです。これは最終ドラフトなので、fancyhdr を使用して、多くの変更を加えずに実行できれば理想的です。ありがとうございます!

答え1

私は、コマンドを定義する のpagestylesオプションと、番号なしのセクションについては、(およびで使用される) を使用した、より単純なコードを提案します。titlesec\chaptermark\pretitlemark\titleformat前に \section*) :

\documentclass[12pt, twoside]{report}

\usepackage[explicit, pagestyles]{titlesec} %adjust titles
\usepackage{lipsum} %random text

\titleformat{\chapter}[display]{\LARGE\bfseries\filcenter}{\thechapter}{10pt}{#1}
\titleformat{name=\chapter, numberless}[display]{\LARGE\bfseries\filcenter}{}{10pt}{\chaptermark{#1}\addcontentsline{toc}{chapter}{#1}#1}

\titleformat{\section}{\normalfont\fontsize{20}{20}\filcenter}{\thesection}{1em}{\MakeUppercase{#1}}
\titleformat{name=\section, numberless}{\normalfont\fontsize{20}{20}\filcenter}{}{0em}{\pretitlemark{section}{#1}\MakeUppercase{#1}}
\renewcommand{\thesection}{\ifthechapter{\thechapter.}{}\arabic{section}}

\titleformat{\subsection}{\normalfont\filcenter}{\thesubsection}{1em}{\textit{{#1}}}

\newpagestyle{myps}{%
\sethead[][\itshape\chaptertitle][]{}{\itshape\sectiontitle}{}
\setfoot{}{\thepage}{}
}
%%%%%%%%%Chapter and section titles in headers
\pagestyle{myps}
\usepackage{subfiles} %allows multi-file projects

\setcounter{tocdepth}{1} %removes subsubsections from toc

%%%%%%%%%removes dots from toc
\makeatletter
\renewcommand{\@dotsep}{10000}
\makeatother
%%%%%%%%%

\begin{document}

\tableofcontents

\chapter*{Introduction}

\section{An Introductory Section}

\lipsum
\lipsum[1]

\section{Another Introductory Section}

\lipsum

\chapter{A Chapter}

\lipsum[2-5]

\section{A Section}

\lipsum[6-8]

\pretitlemark{section}{Conclusion}
\section*{Conclusion}

\lipsum[9-15]

\chapter{Another Chapter}

\lipsum[13-16]

\chapter*{Conclusion}

\lipsum[17-20]

\end{document} 

関連情報