How can I add the current chapter and section to the node?
\node[color=white, anchor=west] at ($(current page.north west) - (-10ex,3.5ex)$)
{\ifnum\value{chapter}>0 \thechapter.~\chaptermark\fi};
\chaptermark
or \sectionmark
doesn't work here.
\documentclass{scrbook}
\usepackage[
a4paper, top=25mm, bottom=30mm,
inner=20mm, outer=70mm,
marginparsep=7mm, marginparwidth=45mm,
]{geometry}
\usepackage{xcolor}
\definecolor{myviolet}{HTML}{4c0068}
\usepackage{microtype}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\renewcommand\headrulewidth{0pt}
\fancyhead[ER]{%
\begin{tikzpicture}[overlay,remember picture]
\draw[fill=myviolet!90, draw=none] ($(current page.north west) + (8.5ex,7ex)$) rectangle ($(current page.north east) - (0ex,7ex)$);
\draw[fill=myviolet, draw=none] ($(current page.north west) + (8ex,7ex)$) rectangle ($(current page.north west) - (0ex,7ex)$);
\node[color=white] at ($(current page.north west) - (-4ex,3.5ex)$) {\textbf{\Large\thepage}};
\node[color=white, anchor=west] at ($(current page.north west) - (-10ex,3.5ex)$) {\ifnum\value{chapter}>0 \thechapter.\fi};
\end{tikzpicture}%
}
\fancyhead[OL]{%
\begin{tikzpicture}[overlay,remember picture]
\draw[fill=myviolet!90, draw=none] ($(current page.north west) + (0,7ex)$) rectangle ($(current page.north east) - (8.5ex,7ex)$);
\draw[fill=myviolet, draw=none] ($(current page.north east) - (8ex,7ex)$) rectangle ($(current page.north east) + (0ex,7ex)$);
\node[color=white] at ($(current page.north east) - (4ex,3.5ex)$) {\textbf{\Large\thepage}};
\node[color=white, anchor=east] at ($(current page.north east) - (10ex,3.5ex)$) {\ifnum\value{section}>0 \thesection.\fi};
\end{tikzpicture}%
}
\usepackage{lipsum}
\begin{document}
\chapter{Test Chapter}
\section{Test Section}
\lipsum[1-3]
\newpage
\section{Test Section 2}
\lipsum[1-3]
\newpage
\section{Test Section 3}
\lipsum[1-3]
\end{document}
Best Answer
\chaptermark
sets\markboth
and then you can use\leftmark
for the chapter in the header. Similarly,\sectionmark
sets\markright
. So\rightmark
can be used for the section entry in the header.But I think it is better to use
scrlayer-scrpage
(or the olderscrpage2
) together withscrbook
instead offancyhdr
.