Example: Fancy chapter headings

Published 2008-10-12 | Author: Stefan Kottwitz

An example of how you can use TikZ and absolute positioning to create fancy chapter headings.

Source:TeXblog: Fancy chapter headings with TikZ

Download as: [PDF] [TEX]  •  [Open in writeLaTeX]

Fancy chapter headings

Do you have a question regarding this example, TikZ or LaTeX in general? Just ask in the LaTeX Forum.
Oder frag auf Deutsch auf TeXwelt.de.

\documentclass[svgnames]{report}

\usepackage{tikz}
\usepackage{kpfonts}
\usepackage[explicit]{titlesec}
\newcommand*\chapterlabel{}

\titleformat{\chapter}
  {\gdef\chapterlabel{}
   \normalfont\sffamily\Huge\bfseries\scshape}
  {\gdef\chapterlabel{\thechapter\ }}{0pt}

  {\begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-3cm] at (current page.north west)
      {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=LightSkyBlue] (0,0) rectangle
          (\paperwidth,3cm);
        \node[anchor=east,xshift=.9\paperwidth,rectangle,
              rounded corners=20pt,inner sep=11pt,
              fill=MidnightBlue]
              {\color{white}\chapterlabel#1};
       \end{tikzpicture}

      };
   \end{tikzpicture}
  }
\titlespacing*{\chapter}{0pt}{50pt}{-60pt}

\begin{document}
\tableofcontents
\chapter{Introduction}
Text
\chapter{Main}

\section{Section}
Text
\begin{thebibliography}{99}
\bibitem{Test} test reference

\end{thebibliography}
\end{document}

Comments

  • #1 Kjell Magne Fauske, October 21, 2008 at 12:37 p.m.

    A related example is the Modifying the current page node. It shows how to hack the current page node to support printing on stock paper larger than the page size.

  • #2 Sasha, November 21, 2008 at 6:23 a.m.

    This is nice! But what about parts and title in the same style?

  • #3 Kjell Magne Fauske, November 21, 2008 at 8:32 a.m.

    Parts and title in the same style should not be that difficult to implement. I recommend asking this question on Stefan Kottwitz's blog. He created the example and he is remarkable knowledgeable about everything TeX-related.

  • #4 Kwo, May 1, 2010 at 3:33 p.m.

    Hello. I feel interested by the example and try to run the code. However, it pops up the following error: !pdfTeX error: pdflatex (file jkpbn8r): Font jkpbn8r at 864 not found ==> Fatal error occurred, no output PDF file produced! I tried to down load jkpbn8r.tfm and put it into the relevant folder.It could not sovle the problem. Could you please offer some help? Thank you very mcuh.

  • #5 kwo, May 2, 2010 at 4:03 p.m.

    I have sorted the problem out. After I upgraded MikTeX, and the code just ran smoothly and no problem anymore. Thank you very much.

  • #6 Flo, July 1, 2013 at 1:25 p.m.

    The example worked in WinShell several times but changing the rectangle resulted in completely unpredictable behaviour and now I get this:

    ("...\MiKTeX 2.9\tex\latex\titlesec\titlesec.sty") Runaway argument? ! Paragraph ended before \ttl@format@ii was complete. \par l.12

    ! You can't use `macro parameter character #' in restricted horizontal mode. l.21 {\color{white}\chapterlabel# 1};

    ! LaTeX Error: Missing \begin{document}.

Adding comments is currently not enabled.