7

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

manish
  • 9,111
  • 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 http://tex.stackexchange.com/questions/38574/resources-for-designing-a-table-of-contents?lq=1 but i need image there – manish Jan 23 '13 at 16:59

1 Answers1

8

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}
Werner
  • 603,163
  • 1
    Thanks, Is there any way to replace word Contents with Summary – manish Jan 26 '13 at 02: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 03:35
  • @Werner, Thanks, is thre any way to remove numbering 1,2,3 ... – manish Jan 29 '13 at 03:04
  • 1
    @user15662: See the updated answer. – Werner Jan 29 '13 at 16:12
  • Thanks, but i observe one thing, Font size of section is bigger than font size of table of contents. Is there any way to control it? – manish Jan 30 '13 at 02:04
  • 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 03:09
  • How can we control it? – manish Jan 30 '13 at 03:17
  • 1
    @user15662: See updated answer. – Werner Jan 30 '13 at 03:58
  • Is there any way to control the page number and position of toc? Actually i have 3 cover pages and after that table of content should be printed. How can i control it? – manish Mar 26 '13 at 02:43
  • @user15662: It is possible to control this. However, you need to provide more detail and context. Consider asking a new question that contains all of this. – Werner Mar 26 '13 at 03:54
  • @Werner, I got the solution for it by putting \tableofcontents later wherever needed. – manish Mar 26 '13 at 06:05
  • @Werner: I have one query, How can i move indented name without numbering to left aligned as show here http://postimage.org/image/6zu00vrhz/2b6189a1/ – manish Mar 26 '13 at 06:11
  • @user15662: How did you create those sections in the first place? What packages are you using the could format the ToC entries? All of these questions and uncertainties leads me to push you to ask a new question where you are able to provide a complete, minimal working example (MWE) that clearly reproduces your problem. – Werner Mar 27 '13 at 01:28
  • @Werner: i found its solution. Just for info i m using your code posted here. I need one more info is there any way to write a line in toc but without page number like \addcontentsline{toc}{section}{\protect\numberline{}Fourth section} but don't want to write page number here. – manish Mar 27 '13 at 07:27
  • @user15662: To get rid of the space before an unnumbered (starred) \section, drop \protect\numberline{} from your \addcontentsline references. To avoid setting a page number, you could use \addtocontents{toc}{\protect\contentsline{section}{Section Name}{}}. Usually the last argument (empty here) contains \thepage. – Werner Mar 27 '13 at 08:00
  • Thanks! It works fine. One small question. Can i reduce the spacing between Section and line (\addtocontents{toc}{\protect\contentsline{section}{Section Name}{}}). – manish Mar 27 '13 at 08:15