章節標題透過文件被竊聽

章節標題透過文件被竊聽

我正在尋找一種新的類似書籍的章節格式,其中章節名稱之前有一個圖像,並通過重新定義來想出一個代碼chapter來做到這一點tikzpicture,但現在的問題是,在整個文檔中,章節名稱每頁的標題是“目錄”,而不是相應章節的標題。有誰知道我該如何糾正它,使標題成為當前章節的標題?

這是我文檔的 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是遵循該類別的預設格式。否則,還有很多其他選擇(例如,書籍、報告)。所以我不建議你使用geometerypackage。如果您確實想在memomir課堂上自訂章節標題,您應該使用memomir.這樣就不會弄亂格式和標題更新。此外,星號版本的章節標題(例如contents)也具有與編號標題相同的格式。使用此方法,您將不需要第二個參數來指定章節影像。這樣就\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}

在此輸入影像描述 在此輸入影像描述 在此輸入影像描述

相關內容