# Chapter style using chaptername and chapter number inside TikZ

I am trying to define my own chapter style for my thesis. I am using memoir, and want to put the part that says e.g. "Chapter 3" or "Appendix C" inside a single TikZ figure. My code so far is the following, but naturally it doesn't work for appendices, because they will also just read e.g. "Chapter C" and not "Appendix C". I have been looking around the web and the memoir documentation, and I found that I might be able to use \@chapapp, but I got nowhere with that.. Can you help?

\makechapterstyle{nicechap}
{
\setlength{\beforechapskip}{0cm}    % Distance from top of page to chapter headings
\setlength{\afterchapskip}{1cm}     % Distance from chapter text to body
\setlength{\midchapskip}{0cm}       % Distance between chapter number and heading

\renewcommand*{\chapnamefont}{\huge\scshape}
\renewcommand*{\printchaptername}{}
\renewcommand*{\chaptitlefont}{\huge\scshape\bfseries}
\renewcommand\printchapternum
{
\makebox[0pt][l]
{
%\tikzset{external/remake next}
\begin{tikzpicture}[->, thick]
\node[draw, minimum height=3em] at (0,0) (chap) {\chapnamefont {\bfseries Chapter~\thechapter}};
% other TikZ drawing stuff here..
\end{tikzpicture}
}
}
}

-
You should wrap the entire \makechapterstyle{nicechap}{...} inside a \makeatletter ... \makeatother pair, and replace Chapter with \@chapapp. Why? Because when you issue \appendix in memoir it redefines \@chapapp to be \appendixname (which expands to Appendix), in addition to some other things (including the chapter counter representation). Have you tried that? I guess I don't really know what you mean by "I got nowhere with that..." –  Werner Jul 9 '12 at 19:28
Ah, thanks. The problem was I didn't use \makeatletter .. \makeatother. Whatever error I was getting, it didn't make sense to me. How would I make it work for whatever is in the backmatter and frontmatter too? Also, do you wanna post an answer so I can give credits? –  Martin Lauridsen Jul 9 '12 at 19:39

You should wrap the entire \makechapterstyle{nicechap}{...} inside a \makeatletter ... \makeatother pair, and replace Chapter with \@chapapp:

\makeatletter
\makechapterstyle{nicechap}
{
\setlength{\beforechapskip}{0cm}    % Distance from top of page to chapter headings
\setlength{\afterchapskip}{1cm}     % Distance from chapter text to body
\setlength{\midchapskip}{0cm}       % Distance between chapter number and heading

\renewcommand*{\chapnamefont}{\huge\scshape}
\renewcommand*{\printchaptername}{}
\renewcommand*{\chaptitlefont}{\huge\scshape\bfseries}
\renewcommand\printchapternum
{
\makebox[0pt][l]
{
%\tikzset{external/remake next}
\begin{tikzpicture}[->, thick]
\node[draw, minimum height=3em] at (0,0) (chap) {\chapnamefont {\bfseries\@chapapp~\thechapter}};
% other TikZ drawing stuff here..
\end{tikzpicture}
}
}
}
\makeatother


Why? Because you're using an @ symbol inside a macro definition. See What do \makeatletter and \makeatother do? Also, because when you issue \appendix in memoir it redefines \@chapapp to be \appendixname (which expands to Appendix), in addition to some other things (including the chapter counter representation).

The above suggestion should work regardless of where it's used (\frontmatter, \mainmatter or \backmatter). Note that you need to issue \appendix before your appendices so that \@chapapp is updated accordingly.

-
Very nice, however, it doesnt work for stuff in frontmatter and backmatter. I found a suggestion from Lars Madsen here, saying to use \renewcommand\printchapternonum[1]{\begin{tikzpicture} ... ##1 \end{tikzpicture}}, but doing that I get an error saying "Argument of \@nameuse has an extra }" –  Martin Lauridsen Jul 9 '12 at 19:59
@MartinLauridsen: Yes, within \frontmatter and \backmatter, \chapter is used in its starred-form. When I include your references \renewcommand, it works fine (centering the chapter name). If you're still having problems, edit your question and add the relevant detail. –  Werner Jul 9 '12 at 21:24
Yeah, the stuff in the reference works, but if you remove that and put the ##1 inside even simple tikz, it doesnt work for me anymore.. –  Martin Lauridsen Jul 9 '12 at 22:15