32

I need to add a fancy looking chapter start page to a book. We're using the memoir class and make use of tikz for fancy section and chapter headings. Now, I need to add a list of the sections that occur in the chapter, on the chapter's start page. I've tried using something like:

\documentclass[oneside]{memoir}
\usepackage{tikz}
\usepackage{titletoc}
\usepackage{lipsum}

\begin{document}
\tableofcontents
\chapter{A chapter}
\startcontents[chapters]
\begin{tikzpicture}[overlay]
    \node[fill=blue] {\printcontents[chapters]{}{1}{}};
\end{tikzpicture}
\section{Section}
\lipsum[1]
\section{Section 2}
\lipsum
\chapter{Second chapter}
\startcontents[chapters]
\printcontents[chapters]{}{1}{}
\section{Section}
\lipsum[2]
\section{Another section}
\lipsum
\end{document}

but this doesn't seem to work well. My actual code redefines the \chapter command and inserts the tikzpicture as part of the chapter page. I'm aiming for something like this: The goal

I'd appreciate a pointer as to how I can get a mini toc inside a TikZ node OR how to get access to a list of the sections that allows me to loop through them OR any other way to accomplish my goal.

1 Answer 1

38

You can use a minipage for this.

Example

Here an example:

\documentclass[oneside]{memoir}

\usepackage{tikz}
\usetikzlibrary{shadows.blur}

\usepackage{titletoc}
\usepackage{lipsum}

\usepackage{calc}

\definecolor{yourcolor}{HTML}{008bb2}

%define new chapter style (just for a nicer look)
\makechapterstyle{mystyle}{%
  \chapterstyle{default}
  \renewcommand*{\chapnumfont}{\normalfont\Huge\sffamily\bfseries}
  \renewcommand*{\chaptitlefont}{\normalfont\huge\sffamily\itshape\color{yourcolor}}
  \settowidth{\chapindent}{\chapnumfont 111}
  \renewcommand*{\chapterheadstart}{}
  \renewcommand*{\chapnamefont}{\hfill\color{yourcolor}\normalfont\Huge\sffamily\bfseries}
  \renewcommand*{\printchapternum}{%
  \begin{tikzpicture}[baseline={([yshift=-.6ex]current bounding box.center)}]
  \node[fill=yourcolor,circle,text=white] {\thechapter};
  \end{tikzpicture}\\[1ex]
  \hrule height 1.5pt}
  \renewcommand*{\printchaptertitle}[1]{%
    {\chaptitlefont ##1}}
}

%use new chapter style
\chapterstyle{mystyle}

%command to print the acutal minitoc
\newcommand{\printmyminitoc}{\noindent\hspace{-2cm}\begin{tikzpicture}
    \node[rounded corners,align=left,fill=yourcolor, blur shadow={shadow blur steps=5}, inner sep=5mm]{%
        \color{white}%
        \begin{minipage}{8cm}%minipage trick
        \printcontents[chapters]{}{1}{}
        \end{minipage}};
    \end{tikzpicture}}

\begin{document}
\tableofcontents
\chapter{A chapter}
\startcontents[chapters]
%print minitoc
\printmyminitoc



\section{Section}
\lipsum[1]
\section{Section 2}
\section{test}
\section{abc}
\lipsum
\chapter{Second chapter}
\end{document}

Here a quick demo with the book class. You might want to adjust the page borders. To color the page numbers in the mini toc, I used the method described at https://tex.stackexchange.com/a/186757/10117.

\documentclass[twoside]{book}

\usepackage{tikz}
\usetikzlibrary{shadows.blur}

\usepackage{titletoc}
\usepackage{lipsum}

\usepackage{calc}

\usepackage[]{titlesec} 
\definecolor{yourcolor}{HTML}{008bb2}

\colorlet{chpnumbercolor}{black}
\makeatletter
\let\oldl@chapter\l@chapter
\def\l@chapter#1#2{\oldl@chapter{#1}{\textcolor{chpnumbercolor}{#2}}}

\let\old@dottedcontentsline\@dottedtocline
\def\@dottedtocline#1#2#3#4#5{%
\old@dottedcontentsline{#1}{#2}{#3}{#4}{{\textcolor{chpnumbercolor}{#5}}}}
\makeatother

\titleformat{\chapter}[display]
  {\normalfont\color{yourcolor}}
  {\filleft\Huge\sffamily\bfseries\chaptertitlename\hspace*{2mm}%
  \begin{tikzpicture}[baseline={([yshift=-.6ex]current bounding box.center)}]
    \node[fill=yourcolor,circle,text=white] {\thechapter};
  \end{tikzpicture}}
  {1ex}
  {\titlerule[1.5pt]\vspace*{5ex}\huge\sffamily\itshape}
  []

\titleformat{name=\chapter,numberless}[display]
  {\normalfont\color{yourcolor}}
  {}
  {1ex}
  {\vspace*{5ex}\huge\sffamily\itshape}
  []

%command to print the acutal minitoc
\newcommand{\printmyminitoc}{%
    \noindent\hspace{-2cm}%
    \colorlet{chpnumbercolor}{white}%
    \begin{tikzpicture}
    \node[rounded corners,align=left,fill=yourcolor, blur shadow={shadow blur steps=5}, inner sep=5mm]{%
        \color{white}%
        \begin{minipage}{8cm}%minipage trick
        \printcontents[chapters]{}{1}{}
        \end{minipage}};
    \end{tikzpicture}}

\begin{document}
\tableofcontents
\chapter{A chapter}
\startcontents[chapters]
%print minitoc
\printmyminitoc



\section{Section}
\lipsum[1]
\section{Section 2}
\section{test}
\section{abc}
\lipsum
\chapter{Second chapter}
\end{document}
8
  • How to do this, for \documentclass[twoside]{book}. when i change memoir to book, i get error! Commented Nov 19, 2012 at 16:59
  • You get this error because the example uses commands from memoir class. You need to modify the the code to work with book.
    – someonr
    Commented Apr 11, 2013 at 18:57
  • So, will not you teach us this codes? Commented Sep 18, 2014 at 9:38
  • @GurebuBokofu I just added a quick example. Hope it helps ;)
    – someonr
    Commented Sep 18, 2014 at 21:45
  • @someonr There are two bugs in your code \documentclass\[twoside\]{book} and \usepackage\[\]{titlesec} Commented Sep 19, 2014 at 0:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .