I am writing a memoir
document and I'd like to customize the visual appearance of the chapter title with Tikz1. This works so far, as shown by this MWE2:
\documentclass[a4paper,11pt]{memoir}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{calc}
\renewcommand{\chapterheadstart}{}
\renewcommand{\printchaptername}{}
\renewcommand{\chapternamenum}{}
\renewcommand{\printchapternum}{}
\renewcommand{\afterchapternum}{}
\renewcommand{\printchaptertitle}[1]{\noindent\Huge\begin{tikzpicture}
\clip (0,0) rectangle (\textwidth,\baselineskip);
\node (bottomleft) at (0,0) {};
\node (topright) at (\textwidth,\baselineskip) {};
\draw[red] (bottomleft.center) -- (topright.center);
\node at ($(bottomleft)!0.5!(topright)$) {\textbf{#1}};
\node at (.1\textwidth, .5\baselineskip) {\thechapter};
\end{tikzpicture}}
\begin{document}
\chapter{First}
\lipsum[1-10]
\chapter*{Extra}
\lipsum[11-20]
\chapter{Last}
\lipsum[21-30]
\end{document}
This outputs the chapter name and chapter number at the beginning of each chapter in such a way that both pieces of information are embedded into the graphic.
Unfortunately (albeit unsurprisingly), the middle unnumbered chapter (\chapter*
) reuses the number of the previous chapter. I would like to hide that number. Therefore, my question is:
How can I find out whether or not the current chapter is numbered? Is there any function that returns such a value, or a function that only prints its argument if the current chapter is numbered?
1: My actual graphic is quite a bit more complex and more appealing. The simple graphical chapter title in the MWE here are just for demonstration purposes.
2: Unlike my actual document, this MWE draws its contents from the lipsum
package.
\chapter
and/or\chapter*
to set a value to the chapter number of blank. Alternatively keep a count of the previous chapter number and compare that to the current reported value in your figure generating routine. Just a couple of thoughts in case no better way appears.