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



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:

\usepackage{etoolbox,graphicx}% http://ctan.org/pkg/{etoolbox,graphicx}


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

\patchcmd{\l@section}% <cmd>
  {\begingroup}% <search>
  {\begingroup\normalfont\Large\bfseries}% <replace>
  {}{}% <success><failure>
Some contents for the \texttt{mdframed} environment.
\begin{mdframed}% mdframed for the image


\section{First section}
\section{Second section}
\section{Third section}
\section*{Fourth section}
\addcontentsline{toc}{section}{\protect\numberline{}Fourth section}
\section{Last section}


enter image description here

  • Thanks, can i add one more mdframed with image inside after this mdframed on the same page. – manish 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. – manish 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? – manish Mar 29 '13 at 4:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.