# How to add mdframed in toc?

This refers to my previous question.

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

Regards

-

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}

\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}
\section{Second section}
\section{Third section}
\section*{Fourth section}

@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