答案1
这是一个可能的解决方案,修补\tableofcontents
命令(我使用了提供的代码沃纳在链接的问题中);当然,在命令mdframed
中使用所需的选项\mdframedintoc
:
\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}