Take the 2-minute tour ×
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.

My Question is similar to question which has not been answered. How can i put image in index page to improve look and feel.

How to generate index page for report?

enter image description here

share|improve this question
3  
I think you don't need this message but once again, please add a minimal working example (MWE) that illustrates your problem. Also what do you have in mind when you mention improve? –  percusse Jan 23 '13 at 15:17
1  
Are you referring to index or table of contents? They are two very different concepts. If you're asking about the table of contents, as I believe, please state it clearly and at least add some information about what precisely you'd like to do. –  egreg Jan 23 '13 at 16:41
    
I need something like tex.stackexchange.com/questions/38574/… but i need image there –  manish Jan 23 '13 at 16:59

1 Answer 1

Inserting raw content into the ToC is done using \addtocontents{toc}{<stuff>}. In order to survive writing such content, \protecting is usually required. Here's a small example showing how to do it:

enter image description here

\documentclass{article}
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\newcommand{\addstufftotoc}[2][toc]{% \addimagetotoc[<toc>]{<stuff>}
  \addtocontents{#1}{#2}}
\begin{document}
\tableofcontents
\section{First section}
\addstufftotoc{\nobreak\smallskip\protect\includegraphics[height=2\baselineskip]{example-image-a}\par}
\section{Second section}
\addstufftotoc{\nobreak\smallskip\protect\includegraphics[height=2\baselineskip]{example-image-b}\par}
\section{Third section}
\section*{Fourth section}
\addcontentsline{toc}{section}{\protect\numberline{}Fourth section}
\section{Last section}
\addstufftotoc{\nobreak\smallskip\protect\includegraphics[height=2\baselineskip]{example-image-c}\par}
\end{document}

In the above example, \addstufftotoc[<toc>]{<stuff>} allows you to add <stuff> to the ToC of your choice (say List of Figures/Tables or Table of Contents which is the default). The example images are from the mwe package. For unnumbered sections, \section* could be used, together with \addtocontents to insert the appropriate formatted title in the ToC (if needed).


Additional request: Having the same size font \section in the ToC than in the main document body

Sectional unit displays in the ToC is governed by the macro \l@section. The following is taken from its definition in article.cls:

\newcommand*\l@section[2]{%
  \ifnum \c@tocdepth >\z@
    \addpenalty\@secpenalty
    \addvspace{1.0em \@plus\p@}%
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
    \endgroup
  \fi}

The arguments passed to \l@section are the sectional unit number and title (as #1) and the page number (as #2). To match the font size from \section, we extract its definition from article.cls:

\newcommand\section{\@startsection {section}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex}%
                                   {\normalfont\Large\bfseries}}

and redefine \l@section appropriately using a patch (for cleanliness; provided by the etoolbox package):

enter image description here

\documentclass{article}
\usepackage{etoolbox,graphicx}% http://ctan.org/pkg/{etoolbox,graphicx}
\newcommand{\addstufftotoc}[2][toc]{% \addimagetotoc[<toc>]{<stuff>}
  \addtocontents{#1}{#2}}
\makeatletter
\patchcmd{\l@section}% <cmd>
  {\begingroup}% <search>
  {\begingroup\normalfont\Large\bfseries}% <replace>
  {}{}% <success><failure>
\makeatother
\begin{document}
\tableofcontents
\section{First section}
\addstufftotoc{\nobreak\smallskip\protect\includegraphics[height=2\baselineskip]{example-image-a}\par}
\section{Second section}
\addstufftotoc{\nobreak\smallskip\protect\includegraphics[height=2\baselineskip]{example-image-b}\par}
\section{Third section}
\section*{Fourth section}
\addcontentsline{toc}{section}{\protect\numberline{}Fourth section}
\section{Last section}
\addstufftotoc{\nobreak\smallskip\protect\includegraphics[height=2\baselineskip]{example-image-c}\par}
\end{document}
share|improve this answer
1  
Thanks, Is there any way to replace word Contents with Summary –  manish Jan 26 '13 at 2:32
1  
@manish: Yes. Use \renewcommand{\contentsname}{Summary}. For more details, see How to change the name of document elements like “Figure”, “Contents”, “Bibliography” etc.? –  Werner Jan 26 '13 at 3:35
1  
@user15662: See the updated answer. –  Werner Jan 29 '13 at 16:12
1  
@user15662: So you want the font size of \section in the ToC to be the same as the font size of \section in the main body of your document? Yes, they're different, but that can be changed. –  Werner Jan 30 '13 at 3:09
1  
@user15662: See updated answer. –  Werner Jan 30 '13 at 3:58

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.