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.

This refers to my previous question.

How to put image in table of contents?

How can i add mdframed after toc on the same page?

enter image description here

Regards

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Here's one possible solution, patching the \tableofcontents command (I used the code provided by Werner in the question linked); of course, use the desired options for mdframed in the \mdframedintoc command:

\documentclass{article}
\usepackage{etoolbox,graphicx}% http://ctan.org/pkg/{etoolbox,graphicx}
\usepackage{xcolor}
\usepackage{mdframed}

\definecolor{myblue}{RGB}{146,243,224}

\newcommand{\addstufftotoc}[2][toc]{% \addimagetotoc[<toc>]{<stuff>}
  \addtocontents{#1}{#2}}

\makeatletter
\patchcmd{\l@section}% <cmd>
  {\begingroup}% <search>
  {\begingroup\normalfont\Large\bfseries}% <replace>
  {}{}% <success><failure>
\newcommand\mdframedintoc{\par\bigskip%
\begin{mdframed}[hidealllines=true,backgroundcolor=myblue]
Some contents for the \texttt{mdframed} environment.
\end{mdframed}\par\bigskip
\begin{mdframed}% mdframed for the image
\centering
\includegraphics[height=2\baselineskip]{example-image-a}
\end{mdframed}%
}
\patchcmd{\tableofcontents}{\@starttoc{toc}}{\@starttoc{toc}\mdframedintoc}{}{}
\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}

enter image description here

share|improve this answer
    
Thanks, can i add one more mdframed with image inside after this mdframed on the same page. –  user15662 Mar 29 '13 at 2:37
    
@user15662 please see my updated answer. –  Gonzalo Medina Mar 29 '13 at 2:44
    
Thanks for quick reply. I have one last query, How can i move word "Contents" up so that we can see more spacing between Contents and TOC. I found top margin is more on this page. How can i control it. –  user15662 Mar 29 '13 at 3:00
1  
@user15662 You can add to the preamble something like \patchcmd{\tableofcontents}{\section*}{\vspace*{-80pt}\section*}{}{} change -80pt according to your needs. –  Gonzalo Medina Mar 29 '13 at 3:05
    
Thanks for your reply. I m using \addtocontents{toc}{\protect\contentsline{section}{Image is not present}{}} for writing some text if image is missing but i see space is more between this text and Fourth section. How can i reduce spacing? –  user15662 Mar 29 '13 at 4:29
show 2 more comments

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.