9

I've got a large document whose table of contents is being generated by the usual \tableofcontents command. I'd really like to include a small image next to each line in the TOC. How can I do that?

EDIT: Answering the question in the comment below, I'm using Article, and I'd like a different image for each SubSection.

1 Answers1

8

Here's an example using the tocstyle package which is part of KOMA-script. (You may replace \rule with \includegraphics from the graphicx package.) Graphics for the "section" ToC entries may be changed using \setsectiongraphics.

\documentclass{article}

\DeclareRobustCommand{\sectiongraphics}{}

\newcommand*{\setsectiongraphics}[1]{%
  \addtocontents{toc}{\protect\renewcommand{\sectiongraphics}{\protect #1}}%
}

\usepackage{tocstyle}
\usetocstyle{standard}
\settocstylefeature{entryhook}{\rule{0.15cm}{0.15cm}\hspace{0.15cm}}% for all ToC levels
\settocstylefeature[1]{entryhook}
    {\sectiongraphics\hspace{0.3cm}\bfseries}% "[1]" for sections

\begin{document}

\setsectiongraphics{\rule{0.3cm}{0.3cm}}

\tableofcontents

\section{bla}

\setsectiongraphics{\rule{0.5cm}{0.5cm}}
\section{blubb}

\subsection{foo}

\subsubsection{bar}

\end{document}

enter image description here

lockstep
  • 250,273