如何在目录中添加 mdframed?

如何在目录中添加 mdframed?

这涉及到我之前的问题。

如何将图像放入目录中?

如何在同一页面的 toc 之后添加 mdframed?

在此处输入图片描述

问候

答案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}

在此处输入图片描述

相关内容