I am trying to create LaTeX TOC entries (within the report class) using simple tikz boxes to add some flare. This topic was addressed awhile back (see How to customize the table of contents using TikZ?), bowever the solutions posted there do not handle the appendix environment correctly. To try to fix this, I used \renewcommand instead of their method. I created a style file (greenBoxTOC.sty, below) that looks like:
% Style file to get green boxes in TOC.
% mtg6193@gmail.com
\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}}{}{}
% ToC Entry modification -- green boxes.
\titlecontents{chapter}[0em]
{\vspace*{20pt}}%
{\hspace{80pt}%
\begin{tikzpicture}[remember picture, overlay]%
\draw[fill=uvmgreen,draw=uvmgreen] (-4,-.1) rectangle (-0.7,.5);%
\pgftext[left,x=-3.7cm,y=0.2cm]{\color{white}\Large\bfseries Chapter\ \thecontentslabel};%
\end{tikzpicture}\color{uvmgreen}\large\bfseries%
\vspace{20pt}}{}{}
And when included in a report such as the following:
\documentclass{report}
% import style file
\usepackage{greenBoxTOC}
\begin{document}
\tableofcontents
\chapter{Quantum Harmonic Oscillator}
\section{test section}
\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}
\begin{appendices}
% fix the fact that appendices show up as "Chapter (A,B..)"
\titlecontents{chapter}[0em]
{\vspace*{20pt}}%
{\hspace{80pt}%
\begin{tikzpicture}[remember picture, overlay]%
\draw[fill=uvmgreen,draw=uvmgreen] (-4,-.1) rectangle (-0.5,.5);%
%\pgftext[left,x=-3.72cm,y=0.2cm]{\color{white}\Large\bfseries Appendix \pgftext[left,x=-3.72cm,y=0.2cm]{\color{white}\Large\bfseries Appendix\
\thecontentslabel};%
\end{tikzpicture}\color{uvmgreen}\large\bfseries%
\vspace{20pt}}{}{}
\chapter{QHO and Riemann Integrals}
\section{test section}
\end{appendices}
\end{document}
this yields the same thing as what they had except for the appendices are handled correctly. The only problem here is that the appendices don't show up correctly in the TOC unless you put the snippet of code inside of the appendices environment within the body of the document (this seems unnecessary). How would one specify different behaviour of this command depending upon whether or not we are within the appendices environment? Another problem is that whenever the implementation above is used, the TOC entry for the appendix A is listed as
Appendix A Appendix QHO and Riemann Integrals
How can you set it up to not have the word Appendix before the name of the appendix chapter?
If anyone knows how to fix either of these problems, please let me know! Thanks in advance.
appendix
package without the optiontitletoc
, i.e.\usepackage{appendix}
. About the former I think there is no easy solution...