ドキュメント全体の章ヘッダーがバグっている

ドキュメント全体の章ヘッダーがバグっている

私は、章の名前の前に画像がある新しい本のような章の形式を作成しようとしており、chapterを通じてそれを実行するためのコードを再定義しましたtikzpictureが、問題は、ドキュメント全体で、各ページのヘッダーの章の名前が「Contents」であり、対応する章のタイトルではないことです。ヘッダーが現在の章のタイトルになるように修正する方法を知っている人はいますか?

これが私の文書の MWE です。

\documentclass[letterpaper]{memoir}

\usepackage{lipsum,tikz}
\usepackage{geometry}
    \geometry{top=2cm,bottom=2cm,left=2cm,right=2cm}

\renewcommand{\chapter}[2]{
    \clearforchapter
    \addtocounter{chapter}{1}
    \chapterheadstart
    \begin{tikzpicture}[remember picture, overlay, path image/.style={
            path picture={
                \node[xshift=-1cm] at (path picture bounding box.center) {
                \includegraphics{#2}
        };}}]
        \draw [path image=#2] (current page.north west) rectangle (\paperwidth, 0);
        \draw (-1.5,0) circle (0pt) node [right, rectangle, rounded corners=8pt, fill=blue]
            {\Huge\bfseries\color{yellow}\thechapter\; #1};
    \end{tikzpicture}
    \addcontentsline{toc}{chapter}{\thechapter\hspace{0.5em} #1}
    \par\vspace{1cm}
    }
 
\begin{document}
\tableofcontents*

\chapter{First}{nilum}

\lipsum[1]\newpage
\lipsum[2]

\chapter{Second}{nilum}

\lipsum[3]
\end{document}

答え1

コマンドを再定義する方法により、\chapterデフォルトのフォーマットとヘッダーの更新が台無しになります。memomirクラスを使用する理由は、このクラスのデフォルトのフォーマットに従うためだと思います。そうでなければ、他にもたくさんの選択肢があります (例: book、report)。したがって、geometeryパッケージの使用はお勧めしません。 クラスの章見出しを本当にカスタマイズしたい場合はmemomir、 で定義済みのコマンドを使用する必要がありますmemomir。この方法では、フォーマットとヘッダーの更新が台無しになることはありません。また、章見出しのスターバージョン (などcontents) も、番号付きバージョンと同じフォーマットになります。この方法を使用すると、章の画像を指定する 2 番目の引数がなくなります。そのため、 コマンドが\chapterimage定義されます。新しい章に入る前にコマンドを更新することで、章のイメージを変更できます\chapterimage。次の方法でも目的は達成できますが、お勧めできません。

\documentclass[letterpaper]{memoir}
\usepackage{lipsum,tikz}
\usepackage{geometry}
\geometry{top=2cm,bottom=2cm,left=2cm,right=2cm}

\renewcommand{\printchaptername}{}
\renewcommand{\chapternamenum}{}
\renewcommand{\printchapternum}{\def\chapnumcontents{\thechapter\; }}
\renewcommand{\printchapternonum}{\def\chapnumcontents{}}
\renewcommand{\afterchapternum}{}
\renewcommand{\printchaptertitle}[1]{
\chaptitlefont\begin{tikzpicture}[
remember picture, 
overlay, 
path image/.style={
path picture={
\node at (path picture bounding box.center) {\includegraphics{\chapterimage}};
}
}
]

\draw [path image=\chapterimage](current page.north west) rectangle (\paperwidth-2cm-1pt, 0);

\node [rectangle, rounded corners=8pt, fill=blue,anchor=west] at (-1,0) {\color{yellow}\chapnumcontents#1};
\end{tikzpicture}
}
\setlength{\afterchapskip}{1cm}
\newcommand\chapterimage{example-image}
 
\begin{document}
\tableofcontents*

\renewcommand\chapterimage{example-image-a}
\chapter{First}

\lipsum[1]\newpage
\lipsum[2]

\renewcommand\chapterimage{example-image-b}
\chapter{Second}

\lipsum[3]
\end{document}

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

関連情報