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 Overleaf]
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.
En français: TeXnique.fr.
\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
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.This is nice! But what about parts and title in the same style?
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.
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.
I have sorted the problem out. After I upgraded MikTeX, and the code just ran smoothly and no problem anymore. Thank you very much.
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.