Tell me more ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
2  
Which document class are you using? Will the image be the same for all entries in the ToC? –  Gonzalo Medina Apr 4 '11 at 22:44
 
add comment

1 Answer

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

share|improve this answer
 
Can i add different picture for different chapter? –  manish Jan 24 at 3:56
 
@manish See updated answer. –  lockstep Jan 24 at 11:15
 
i need output like chapter name and below to that image name. Infront of it index (page number). Is this possible to implement it. –  manish Jan 25 at 15:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.
http://tex.stackexchange.com/questions/14956/include-images-in-toc/14964
tex.stackexchange.com
crawl=CC-MAIN-2013-48
52143
application/http; msgtype=response
sha1:NHOVXWEFSFY2LWER72B6MAJ5EQFKX2QC
<urn:uuid:d1374ba4-38a1-4175-a791-6936a37e8e5a>
2013-12-06T16:40:37Z
198.252.206.16
sha1:JCSJMVQ7QD5DXYPPE2RBSE6TELISWUR5
<urn:uuid:ad2b93f0-2e71-40c7-b9a8-7166ef6cc454>
http://tex.stackexchange.com/questions/14956/include-images-in-toc/14964
response
<urn:uuid:42f6593c-68e9-4907-bb69-5f22cbb26b31>
robots: classic
hostname: ip-10-33-133-15.ec2.internal
software: Nutch 1.6 (CC)/CC WarcExport 1.0
isPartOf: CC-MAIN-2013-48
operator: CommonCrawl Admin
description: Wide crawl of the web with URLs provided by Blekko for Winter 2013
publisher: CommonCrawl
format: WARC File Format 1.0
conformsTo: http://bibnum.bnf.fr/WARC/WARC_ISO_28500_version1_latestdraft.pdf