我已经编写了一个自定义章节命令,它使用蒂克兹绘制标题框,添加图片和其他内容。到目前为止,一切都按预期进行,但章节标题未更新。它保留了最后一个常规章节的标题,就我而言List of figures
。有没有简单的方法可以修复它?
代码
\documentclass{scrreprt}
\usepackage{scrhack}
\usepackage[twoside, margin=20mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{tikzpagenodes}
\usepackage{xifthen}
\usepackage[headsepline=yes]{scrlayer-scrpage}
\automark[section]{chapter}
\ihead{\headmark}
\chead[]{}
\ohead{\pagemark}
\ifoot[]{}
\cfoot[]{}
\ofoot[]{}
\newcommand{\mfc}[6][]%[short] title, pic, pic caption, lof caption, description
{ \cleardoublepage
\thispagestyle{empty}
\refstepcounter{chapter}
\addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}#2}
\begin{tikzpicture}
[ overlay,
remember picture
]
\draw[rounded corners=5mm,thick] ($(current page text area.south west)!0.5!(current page text area.north west)$) rectangle ($(current page text area.south east)!0.6!(current page text area.north east)$);
\node (c-\thechapter) at ($(current page text area.south west)!0.55!(current page text area.north west)+(1.5,0)$) {\fontsize{50}{60}\selectfont \textsf{\textbf{\thechapter}}};
\draw[thick] ($(current page text area.south west)!0.5!(current page text area.north west)+(3,0)$) -- ($(current page text area.south west)!0.6!(current page text area.north west)+(3,0)$);
\node[right,align=left,text width=12cm,font=\Huge] at ($(current page text area.south west)!0.55!(current page text area.north west)+(3.5,0)$) {#2};
%\node[draw,line width=3mm,blue!50!gray,inner sep=0pt,rounded corners=2mm] at ($(current page text area.north east)+(-5,-5)$) {AAAAAARG};
\begin{scope}[shift={($(current page text area.south west)!0.62!(current page text area.north west)+(6,0)$)}]
#3
\end{scope}
\ifthenelse{\isempty{#5}}
{ \node[above right, text width=5.5cm, align=left] at ($(current page text area.south west)!0.62!(current page text area.north west)+(0,0)$) {\captionof{figure}{#4}};
}
{ \node[above right, text width=5.5cm, align=left] at ($(current page text area.south west)!0.62!(current page text area.north west)+(0,0)$) {\captionof{figure}[#5]{#4}};
}
\end{tikzpicture}
\vspace{13cm}
\begin{minipage}{0.97\textwidth}
\begin{minipage}{0.1\textwidth}
\hspace{1cm}
\end{minipage}
\begin{minipage}[t][0.4\textheight]{0.87\textwidth}
#6
\end{minipage}
\end{minipage}
\clearpage
}
\usepackage{lipsum}
\begin{document}
\listoffigures
\foreach \c in {1,...,5}
{ \mfc{chapter \c}{\draw (0,0) rectangle (5,5) node[pos=0.5] {picture \c};}{pic \c caption}{lof \c caption}{Some description of chapter \c.}
\lipsum[\c]
\foreach \s in {1,...,3}
{ \section{Section \s}
\lipsum
}
}
\end{document}
输出
红框内的文字应为章节标题,因此应为“2 chapter 2”,而不是“List of figures”。单击图片可查看大图。
答案1
您的\mfc
宏没有为页眉设置任何标记。因此您必须添加类似以下内容的内容
\markboth{\chaptermarkformat #2}{}
后\refstepcounter{chapter}
。
以下是不同的建议,也适用于长度超过一行的章节标题。还可以使用可选参数在目录和/或标题中使用短标题。
\documentclass[twoside]{scrreprt}
\usepackage[margin=20mm]{geometry}
\usepackage{lmodern}% scalable font
\usepackage{tikz}
\usepackage{tikzpagenodes}
\usepackage[automark,headsepline]{scrlayer-scrpage}
\clearpairofpagestyles
\ihead{\headmark}
\ohead{\pagemark}
\makeatletter
\renewcommand\chapterlinesformat[3]{%
\ifstr{#2}{}
{\@hangfrom{#2}{#3}}% normal format for unnumbered chapters
{\mfc{#2}{#3}}% special format for numbered chapters
}
\makeatother
\renewcommand\chapterformat{\thechapter}
\newcommand{\mfc}[2]{%
\begin{tikzpicture}[
overlay,
remember picture,
thick
]
\path
(current page text area.north west)++(0,-.4\textheight)
node[
minimum height=.1\textheight,
minimum width=3cm,
anchor=north west,
font=\normalfont\fontsize{50}{60}\selectfont\bfseries
](mfcnr)
{#1}% chapter number
;
\node[
minimum height=.1\textheight,
text width=12cm,
align=left,
right=.5cm,
anchor=west,
font=\normalfont\Huge
](mfctitle)
at (mfcnr.east)
{#2}% chapter title
;
\draw(mfcnr.east|-mfctitle.north)--(mfcnr.east|-mfctitle.south);
\draw[rounded corners=5mm]
(mfcnr.west|-mfctitle.south)
rectangle % border
(\textwidth-\pgflinewidth,0|-mfctitle.north)
;
\node[anchor=south west]
at ([shift={(6,.02\textheight)}]mfcnr.west|-mfctitle.north)
{\mfcpicture}% chapter picture
;
\node[
anchor=south west,
text width=5.5cm,
align=left
]
at ([yshift=.02\textheight]mfcnr.west|-mfctitle.north)
{%
%\setcapindent{0pt}
\mfccaption% chapter picture caption
}
;
\path
(mfcnr.west|-mfctitle.south)
++(1cm,-\normalbaselineskip)
node[
anchor=north west,
inner sep=0pt,
node font=\normalfont\normalsize
]
{%
\begin{minipage}[t]{.87\textwidth}
\mfcdescription% chapter descriptionh
\end{minipage}%
}
;
\end{tikzpicture}%
% reset picture and description
\global\renewcommand\mfcpicture{}%
\global\renewcommand\mfccaption{}%
\global\renewcommand\mfcdescription{}%
\clearpage
}
\newcommand\mfcpicture{}
\newcommand\setmfcpicture[1]{\renewcommand\mfcpicture{#1}}
\newcommand\mfccaption{}
\newcommand\mfccaptiontest{}
\newcommand\setmfccaption[2][\mfccaptiontest]{%
\edef\mfccaptiontest{#2}
\ifstr{#1}{\mfccaptiontest}
{\renewcommand\mfccaption{\captionof{figure}[#2]{\raggedright #2}}}
{\renewcommand\mfccaption{\captionof{figure}[#1]{\raggedright #2}}}%
}
\newcommand\mfcdescription{}
\newcommand\setmfcdescription[1]{\renewcommand\mfcdescription{#1}}
\usepackage{lipsum}
\begin{document}
\tableofcontents
\listoffigures
\foreach \c in {1,...,5}
{% chapters with pictures, captions and descriptions
\setmfcpicture{\includegraphics[width=5cm]{example-image}}
\setmfccaption[LOF entry for picture \c]{Caption for picture \c}
\setmfcdescription{Some description of chapter \c.\par \lipsum[1]}
\chapter{Chapter \c}
% some contents for the chapters
\lipsum[\c]
\foreach \s in {1,...,3}{\section{Section \s}\lipsum}
}
\setmfcpicture{\includegraphics[width=7cm]{example-image-A}}
\setmfccaption{example}
\setmfcdescription{Test for a long chapter title with short entry in TOC and headings.}
\chapter[Short TOC and header entry]{A chapter with a long, long, long title that needs more than one line}
\section{A section}
\lipsum\lipsum
\end{document}