0

I'm trying to come up with some simple tikz based chapter style for memoir.

I've gotten to a point where I'm almost happy with the result but there is a space before the chapter title which I haven't been able to remove yet.

Here's my code (to be compiled with xelatex)

\documentclass{memoir}
\usepackage{tikz}
\usepackage{lipsum}

\newcommand*\tikzchapnum[1]{%
  \begin{tikzpicture}[overlay, inner sep=10pt, outer sep=0]
    \node[draw=white!80!black, fill=white!80!black, white,
    left, anchor=base east, scale=2, inner sep=4pt] (cn) at (\textwidth,0) {\chapnumfont \rmfamily \thechapter};
    \draw[white!80!black] (cn.south east) -- ++(-\textwidth, 0);
    \draw[red] (0,2) -- ++(0,-\textheight);
    \draw[red] (\textwidth,2) -- ++(0,-\textheight);
  \end{tikzpicture}
}

\makechapterstyle{grayhandle}{%
  \renewcommand*{\chapnamefont}{\large\scshape}
  \renewcommand*{\chaptitlefont}{\normalfont\HUGE\scshape\sffamily}
  \setlength{\beforechapskip}{2\baselineskip}
  \setlength{\midchapskip}{0pt}
  \setlength{\afterchapskip}{3\baselineskip}
  \renewcommand*{\chapterheadstart}{}
  \renewcommand*{\printchaptername}{}
  \renewcommand*{\chapternamenum}{}
  \renewcommand*{\afterchapternum}{}
  \renewcommand*{\chapnumfont}{\chaptitlefont}
  \renewcommand*{\printchaptertitle}[1]{\raggedright\chaptitlefont\MakeLowercase{##1}}
  \renewcommand*{\printchapternum}[1]{%
    \tikzchapnum{##1}
  }
}
\chapterstyle{grayhandle}

\begin{document}
\chapter{First chapter}
\lipsum
\end{document}

It gives me this result (red lines, commented out in the mwe, show that chapter title is not flush with the textblock)

extra spacing before chapter

How can I remove that extra spacing before the title?

  • How does those read lines show your issues? How are they made? Please be more specific in your question – daleif Jan 23 '18 at 14:55
  • @daleif the red lines show that "FIRST" is not flush with the textblock. You can obtain them with \draw[red] (0,2) -- ++(0,-\textheight); \draw[red] (\textwidth,2) -- ++(0,-\textheight); inside the tikzpicture block – filippo Jan 23 '18 at 14:57
  • Maybe you are looking for ` \renewcommand*\chapterheadstart{}`. But that looks bad since your is an overlay and thus have no size. BTW: this design is more or less doable without tikz – daleif Jan 23 '18 at 14:57
  • 1
    Isn't it the space after \tikzchapnum{##1} try ending that line with a %. Print chapternum is executed right before printchaptertitle, so if it leaves stuff behind it shows. – daleif Jan 23 '18 at 15:29
  • 2
    @daleif you're right, there's a space there, and one after \end{tikzpicture}! thank you, if you want to add it as an answer I'll accept it. Give me a couple of minutes and I'll update the mwe with a more minimal one. – filippo Jan 23 '18 at 15:34
2

The issue is a sporadic space after this line

 \tikzchapnum{##1}

The \printchapternum is executed before \printchaptertitle, thus everything left by it gets interpreted. Use

 \tikzchapnum{##1}%

instead

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.