# Problem with a custom chapter definition and scrlayer-scrpage

I have written a custom chapter command that uses tikz to draw a box for the title, add a picture and other stuff. So far everything works as expected, but the marking for the chapter of the headline is not updated. It stays the heading of the last conventional chapter, in my case List of figures. Is there an easy way to fix it?

## Code

\documentclass{scrreprt}
\usepackage{scrhack}

\usepackage[twoside, margin=20mm]{geometry}

\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{tikzpagenodes}

\usepackage{xifthen}

\automark[section]{chapter}
\ifoot[]{}
\cfoot[]{}
\ofoot[]{}

\newcommand{\mfc}[6][]%[short] title, pic, pic caption, lof caption, description
{ \cleardoublepage
\thispagestyle{empty}
\refstepcounter{chapter}
\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}


## Output

The text in the red box should be the chapter title, so "2 chapter 2" and not "List of figures". Click on the picture to see a larger version.

• Add \markboth{\chaptermarkformat #2}{} after \refstepcounter{chapter}. – esdd May 28 '16 at 20:22
• Or adapt the \chapter macro appropriately? I guess this is the obvious solution, so presumably you have some reason not to do it ... – cfr May 28 '16 at 20:52
• @esdd: Works like a charm. Would you care to add this as an answer? – Tom Bombadil May 28 '16 at 22:50
• @cfr: I adapted the chapter macro to suit the need for a custom "fancy" look, but couln't add the behaviour described above, that's why I asked this question. Or perhaps I don't understand the intention behind your comment? – Tom Bombadil May 28 '16 at 22:52
• More likely I don't really understand what you're trying to do. – cfr May 28 '16 at 22:57

Your \mfc macro does not set any marks for the page header. So you have to add something like

\markboth{\chaptermarkformat #2}{}


after \refstepcounter{chapter}.

Here is different suggestion that also works for chapter titles which are longer than one line. And it is also possible to use the optional argument for a short title in TOC and/or header.

\documentclass[twoside]{scrreprt}
\usepackage[margin=20mm]{geometry}
\usepackage{lmodern}% scalable font

\usepackage{tikz}
\usepackage{tikzpagenodes}

\clearpairofpagestyles

\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\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{}

\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}