2

I have successfully used TikZ to modify the table of contents of a TeX document, and cannot quite figure out how to achieve the same effect for the list of figures, list of tables, acknowledgements, etc. My (simplified) style file looks like:

% Style file to get green boxes in TOC.

\usepackage{tikz}
\usepackage{xcolor}
\usepackage{titletoc}
\usepackage[titletoc]{appendix}
\usepackage{etoolbox}
\usepackage{lmodern}

% define color
\definecolor{uvmgreen}{rgb}{0,0.35,0.23}

% ToC title with color box.
\patchcmd{\tableofcontents}{\contentsname}{
\vspace*{-70pt}%
\begin{tikzpicture}[remember picture, overlay]%
\pgftext[right,x=12cm,y=0.2cm]{\color{uvmgreen}\Huge\bfseries \contentsname};%
\draw[fill=uvmgreen,draw=uvmgreen] (13.5,-.75) rectangle (10,1);%
\clip (15.5,-.75) rectangle (10,1);
\pgftext[right,x=12cm,y=0.2cm]{\color{white}\Huge\bfseries \contentsname};%
\end{tikzpicture}}{}{}

and an example report looks like:

\documentclass{report}

% import style file
\usepackage{greenBoxTOC}
\usepackage[pdftex]{graphicx}

\begin{document}

\tableofcontents
\newpage

\listoffigures
\newpage

\chapter{Quantum Harmonic Oscillator}
\section{test section}

\begin{figure}
\includegraphics[scale=1.0]{image.png}
\caption{sample caption} \label{fig: first figure}
\end{figure}

\section{test section }
\subsection{test subsection}
\section{test section}
\subsection{test subsection}
\subsection{A test subsection with a long title spanning more than one line in the table of contents}
\section{test section}


\chapter{Is it a Riemann Integral?} 
\section{test section}
\subsection{test subsection}
\section{test section with a long title spanning more than one line in the table of contents}
\subsection{test subsection}

\end{document}

I would really like to be able to add a \listoffigures that would use the same green boxes which show up at the top where it says 'List of Figures'. My (unsuccessful) attempt at this was to add the following to the style file:

\patchcmd{\listoffigures}{\figurename}{
\vspace*{-70pt}%
\begin{tikzpicture}[remember picture, overlay]%
\pgftext[right,x=12cm,y=0.2cm]{\color{uvmgreen}\Huge\bfseries \figurename};%
\draw[fill=uvmgreen,draw=uvmgreen] (15.5,-.75) rectangle (10,1);%
\clip (15.5,-.75) rectangle (10,1);
\pgftext[right,x=12cm,y=0.2cm]{\color{white}\Huge\bfseries \figurename};%
\end{tikzpicture}}{}{}

but when I add this, nothing seems to happen. Any suggestions would be much appreciated. Thanks in advance!

  • 1
    Ah! Indeed. Thanks for this (and for pointing out the e-mail address). If you will put that as an answer, I will gladly accept it. – codeAndStuff Oct 14 '13 at 15:36
2

The \listoffigures macro does not contain a reference to \figurename but to \listfigurename. And \listtablename for the \listoftables.

There are more references to \contentsname and \list*name in the \tableofcontents or the \listof*s macro respectively. These are used for the markings when headings are enabled. These should not be changed.

You could also change \contentsname or \listof* directly, however I advise against it as they could be used somewhere else (e.g. in a heading) which might break everything.

I’d also suggest to introduce a macro, say \tikzHeader that produces your green box to separate content from the TeXnics. I also removed the remember picture key as I don’t see where or why you want to reference anything in your picture (there isn’t anything to reference anyway).

\newcommand*\tikzHeader[1]{%
\begin{tikzpicture}[overlay]
  \pgftext[right,x=12cm,y=0.2cm]{\color{uvmgreen}\Huge\bfseries\htStrut\smash{#1}};
  \draw[fill=uvmgreen,draw=uvmgreen] (13.5cm,-.75cm) rectangle (10cm,1cm);
  \clip (15.5cm,-.75cm) rectangle (10cm,1cm);
  \pgftext[right,x=12cm,y=0.2cm]{\color{white}\Huge\bfseries\htStrut\smash{#1}};
\end{tikzpicture}}

I added a \htStrut macro defined as

\newcommand*\htStrut{\rule{0pt}{.7\baselineskip}}

and \smash the actual text (which means it has no vertical dimensions for \pgftext). (The g in "Figure" will throw the vertical placement off otherwise.) If you have amsmath loaded, you can just use \smash[b]{#1} and drop the \htStrut.

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.