1

I am trying to add a figure in the background of the table of contents page. Similar to this one:

enter image description here

I found this template The legrand orange book and tried to use the code used there for my document, but I am still having problems to use it correctly for my application.

This is the code I am using to modify the TOC page style (Taken from the template mentioned above, with a couple of modifications)

\makeatletter
\renewcommand{\tableofcontents}{
\chapter*{
\vspace*{-50\p@}
\begin{tikzpicture}[remember picture, overlay]
\node[
    anchor=north west,
    inner sep=0pt,
] at (current page.north west) {\includegraphics[width=\paperwidth]{figure1.jpg}};

\draw[anchor=west] (current page.north west) node [
        anchor=north west,
        xshift=3cm, 
        yshift=-5cm,
        line width=2pt,
        rounded corners=10pt,
        draw=blue,
        fill=black!5,
        fill opacity=0.6,
        text opacity=1,
        inner ysep=12.5pt,
        inner xsep=20pt,
        align=flush left,
        text width=1.2\linewidth,
        font=\huge\sffamily\bfseries,
        ] {}; 
        \pgftext[right,x=6cm,y=0.2cm]{\color{blue}\Huge\scshape\bfseries\contentsname}
\end{tikzpicture}}
\@starttoc{toc}}
\makeatother

However, when I run it in my dissertation, this is the result I get:

enter image description here

Interesting enough, when I use the same code in the MWE, I get another result:

enter image description here

Here is the MWE:

\documentclass[twoside,12pt,openright]{scrbook}
\usepackage[a4paper]{geometry}
\usepackage[dvipsnames]{xcolor}
\usepackage[sfdefault]{universalis}
\usepackage{titletoc}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{decorations, decorations.pathmorphing, decorations.pathreplacing}
\usepackage[linkcolor=black,colorlinks=true]{hyperref}
%% command to print the actual minitoc ---------------------------------------------
\newcommand{\printmyminitoc}{%
    \begin{center}%
        \begin{tikzpicture}%
            \node[  anchor=south,
                    inner ysep=12.5pt, % Inner vertical padding
                    inner xsep=20pt, % Inner horizontal padding
                    align=flush left, % Text alignment inside box
                  ](s) at (current page.south) {%
            \begin{minipage}[c][][t]{0.90\textwidth}
                \begin{flushright}
                     \renewcommand{\baselinestretch}{1.15}\selectfont
                     \startcontents[chapters]
                     \printcontents[chapters]{}{1}{}
                \end{flushright}
            \end{minipage}
             };%
            \draw[bottom color = blue!80, top color= blue!10, draw=blue!60,fill opacity=0.1,decorate, decoration={random steps,segment length=3pt,amplitude=1pt},line width=1.25pt] (s.north west) rectangle (s.south east);
        \end{tikzpicture}%
    \end{center}%
    \vfill
    \pagebreak
    }

%% command to print the TOC ---------------------------------------------
\titlecontents{chapter}[0pc]
{\addvspace{0pt}}%
{\begin{tikzpicture}[remember picture, overlay]%
\draw[fill=blue!60,draw=blue!60,rounded corners=5pt] (-2.8,-.2) rectangle (1,.7);%
\pgftext[left,x=-2.0cm,y=0.2cm]{\color{white}\Large\scshape\bfseries Chapter\ \thecontentslabel};%
\end{tikzpicture}\hspace{1.5cm}\color{blue!60}\large\scshape\bfseries}
{\color{blue!60}\large\scshape\bfseries}
{\color{blue!60}\;\dotfill\;\large\scshape\bfseries \thecontentspage}
% \titlerule
\titlecontents{section}[2.4pc]
{\addvspace{0.2pt}}
{\hspace{1.6cm}\contentslabel[\thecontentslabel]{2.4pc}}
{}
{\dotfill\small \thecontentspage}
[]

\titlecontents{subsection}[5pc]
{\addvspace{0.2pt}}
{\hspace{1.6cm}\contentslabel[\thecontentslabel]{2.4pc}}
{}
{\dotfill\small\thecontentspage}
[]

\makeatletter
\renewcommand{\tableofcontents}{%
\chapter*{%
\vspace*{-50\p@}%
\begin{tikzpicture}[remember picture, overlay]%
% Output the chapter image
\node[
    anchor=north west, % Anchor point on the image
    inner sep=0pt, % Inner padding
] at (current page.north west) {\includegraphics[width=\paperwidth]{figure1.jpg}};
% Box with the chapter title
\draw[anchor=west] (current page.north west) node [
        anchor=north west, % Anchor point of the chapter box
        xshift=3cm, % Horizontal distance from the left side of the page
        yshift=-5cm, % Vertical distance from the top of the page
        line width=2pt, % Border line thickness
        rounded corners=10pt, % Rounded corners amount
        draw=blue, % Border line color
        fill=black!5, % Box background color
        fill opacity=0.6, % Background transparency
        text opacity=1, % Text transparency
        inner ysep=12.5pt, % Inner vertical padding
        inner xsep=20pt, % Inner horizontal padding
        align=flush left, % Text alignment inside box
        text width=1.2\linewidth, % Box width (wider than page to go off the right side)
        font=\huge\sffamily\bfseries, % Font styling for chapter title
        ] {}; % Chapter title in a fixed width box for wrapping
        \pgftext[right,x=6cm,y=0.2cm]{\color{blue}\Huge\scshape\bfseries\contentsname}
\end{tikzpicture}}%
\@starttoc{toc}}
\makeatother
    
    
\begin{document}
    \renewcommand{\chaptermark}[1]{\markboth{#1}{}}
    \frontmatter
    \pagenumbering{roman}
    \pagestyle{empty}   
    \setcounter{tocdepth}{2}
    \tableofcontents        
    \cleardoublepage
    \mainmatter
    \pagenumbering{arabic}
    \setcounter{page}{1}
    \pagestyle{headings}
    \chapter{Intro}
    \printmyminitoc
    \lipsum[1-3]
    \section{Intro 1 - Section 1}
    \lipsum[1-3]
    \section{Intro 1 - Section 2}
    \lipsum[1-3]
    \section{Intro 1 - Section 3}
    \lipsum[1-3]
    \section{Intro 1 - Section 4}
    \lipsum[1-3]
    \section{Intro 1  - Section 5}
    \lipsum[1-3]
    \chapter{Literature}
    \printmyminitoc
    \lipsum[1-3]
    \section{Literature - Section 1}
    \lipsum[1-3]
    \section{Literature - Section 2}
    \lipsum[1-3]
    \section{Literature - Section 3}
    \lipsum[1-3]
    \section{Literature - Section 4}
    \lipsum[1-3]
    \section{Literature - Section 5}
    \lipsum[1-3]
\end{document}

Could someone offer me any guidance on how to achieve this customisation?

1 Answer 1

2

It is difficult to help you here since you MWE results in a very different output as your original file. Therefore, I removed everything from you code except for the stuff that is needed for the title for the ToC and concentrated on this part.

You need to place the \contentsname inside the node, not below. Don't use \pgftext, just place the plain macro inside the node. Also, you already define some font-styling options to this node, so I would suggest that you put all the styling options there.

As for the picture in the background, in order to prevent that it covers the whole background of your page if it is too large, I added a \clip macro. You may want to adjust the height of the picture by changing yshift to something else.

Finally, since you place the whole title in a tikzpicture with options remember picture, overlay, you will need to adjust the spacing between the title of the ToC and the ToC itself, because thanks to the options remember picture, overlay, the tikzpicture has no height. Thus, if you don't add any vertical spance, the title will probably overlap the ToC entries.

I hope this can get you started:

\documentclass[twoside,12pt,openright]{scrbook}
\usepackage[a4paper]{geometry}
\usepackage[dvipsnames]{xcolor}
\usepackage[sfdefault]{universalis}
\usepackage{titletoc}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{decorations, decorations.pathmorphing, decorations.pathreplacing}
\usepackage[linkcolor=black,colorlinks=true]{hyperref}

\makeatletter
\renewcommand{\tableofcontents}{%
\chapter*{%
\vspace*{3cm}% 
\begin{tikzpicture}[remember picture, overlay]%
% Output the chapter image
\clip (current page.north west) rectangle ([yshift=-9cm]current page.north east);
\node[
    anchor=north west, % Anchor point on the image
    inner sep=0pt, % Inner padding
] at (current page.north west) {\includegraphics[width=\paperwidth]{example-image-a}};
% Box with the chapter title
\draw[anchor=west] (current page.north west) node [
        anchor=north west, % Anchor point of the chapter box
        xshift=3cm, % Horizontal distance from the left side of the page
        yshift=-5cm, % Vertical distance from the top of the page
        line width=2pt, % Border line thickness
        rounded corners=10pt, % Rounded corners amount
        draw=blue, % Border line color
        fill=black!5, % Box background color
        fill opacity=0.6, % Background transparency
        text opacity=1, % Text transparency
        inner ysep=12.5pt, % Inner vertical padding
        inner xsep=20pt, % Inner horizontal padding
        align=flush left, % Text alignment inside box
        text width=1.2\linewidth, % Box width (wider than page to go off the right side)
        font=\Huge\sffamily\scshape\bfseries\color{blue}, % Font styling for chapter title
        ] {%
          \contentsname%
        }; % Chapter title in a fixed width box for wrapping
\end{tikzpicture}}%
\@starttoc{toc}}
\makeatother
    
    
\begin{document}
    \renewcommand{\chaptermark}[1]{\markboth{#1}{}}
    \frontmatter
    \pagenumbering{roman}
    \pagestyle{empty}   
    \setcounter{tocdepth}{2}
    \tableofcontents        
    
    \newpage
    \section{One}
\end{document}

enter image description here

3
  • thanks for your solution. It does the job. And I also found the issue I was having between my document and the MWE. I have all the preamble stuff in one separate file and include it in the main file using \include{}. It just happens I did not know I cannot use \include{} command in the preamble of the main file. So, basically, I just changed from include{preamble} to \input{preamble} and now get the same results. Just one last thing, how should increase/reduce the line spacing between the entrances of the TOC? Commented Jul 25, 2022 at 22:17
  • Thank for your beautiful code. But I have something error with \section. Can you fix it for me? Thank you! ![enter image description here](i.sstatic.net/HlN8u.png) Commented Dec 17, 2023 at 3:56
  • @ChanthornHeng Sorry, I cannot make sense of this without any context. If I compile the above code with a current TeX distribution, No error occurs. So, you need to provide a minimal working example (MWE) that shows the code that generates this error. I'd suggest that you ask a new question and refer to this question or answer and provide more context to this. Commented Dec 17, 2023 at 17:03

You must log in to answer this question.

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