mdframed - 编号字幕和单独的框列表

mdframed - 编号字幕和单独的框列表

我有两个与 mdframed 相关的复杂问题。

1) 我有三种类型的框:警告、建议和提示。我想在目录中添加警告列表、建议列表和提示列表。以下这个例子,我可以获得一个包含注意事项、建议和提示的盒子列表。有没有办法将盒子列表分成三个单独的列表?

2) 有时,我会将警告与相关建议放在一起。在这种情况下,我想将建议与警告放在同一个框中,使用 mdframed 中的字幕。但是,我希望“警告”与独立警告一起编号。(建议不需要编号。)有办法吗?我现在拥有的 MWE 没有对附在建议上的警告进行编号。

\documentclass{book}
    \usepackage{lipsum}
    \usepackage[english]{babel}


    \newcounter{TipBox}[chapter]
    \newcounter{RecBox}[chapter]
    \newcounter{CatBox}[chapter]

    \renewcommand{\theTipBox}{\thechapter.\arabic{TipBox}}
    \renewcommand{\theRecBox}{\thechapter.\arabic{RecBox}}
    \renewcommand{\theCatBox}{\thechapter.\arabic{CatBox}}


    \usepackage[framemethod=tikz]{mdframed}

    \makeatletter
    \tikzset{
    mdfsubtitlebackground/.style={
        draw=none,
        fill=\mdf@subtitlebackgroundcolor}
    }
    \makeatother

    \definecolor{LightRed}{rgb}{0.784,0.537,0.714}
    \definecolor{LightTeal}{rgb}{0.53,.745,.745}

    % Tip boxes
    \newenvironment{TipBox}[1][]{%
        \refstepcounter{TipBox}
        \begin{mdframedtoc}[%
            frametitle={Tip \theTipBox\ #1},
            backgroundcolor=gray!15,
            roundcorner=5pt,
            linecolor=teal,
            linewidth=2pt,
            middlelinecolor=white,
            frametitlebackgroundcolor=LightTeal,
            frametitlefontcolor=white,
            ]%
        }{%
        \end{mdframedtoc}
    }

    % Recommendation boxes
    \newenvironment{RecBox}[1][]{%
        \refstepcounter{RecBox}
        \begin{mdframedtoc}[%
            frametitle={Recommendation \theRecBox\ #1},
            backgroundcolor=gray!15,
            roundcorner=5pt,
            linecolor=teal,
            linewidth=2pt,
            middlelinecolor=white,
            frametitlebackgroundcolor=gray!80,
            frametitlefontcolor=white,
            ]%
        }{%
        \end{mdframedtoc}
    }

    % Caution boxes
    \newenvironment{CatBox}[1][]{%
        \refstepcounter{CatBox}
        \begin{mdframedtoc}[%
            frametitle={Caution \theCatBox\ #1},
            backgroundcolor=gray!15,
            roundcorner=5pt,
            linecolor=teal,
            linewidth=2pt,
            middlelinecolor=white,
            frametitlebackgroundcolor=LightRed,
            frametitlefontcolor=white,
            ]%
        }{%
        \end{mdframedtoc}
    }

% Caution plus recommendation boxes
\newmdenv[%
    roundcorner=5pt,
    subtitlebelowline=false,
        subtitleaboveline=false,
    subtitlebackgroundcolor=gray!80,
        %subtitlefontcolor=white,
    backgroundcolor=gray!15,
    frametitle={Caution},
        frametitlerule=true,
    frametitlebackgroundcolor=LightRed,
        frametitlefontcolor=white,
        linewidth=2pt,
        middlelinecolor=white,
        linecolor=gray!15,
        %innerlinewidth=0pt
]{CatRecBox}


\makeatletter
\newmdenv[startinnercode=\addcontentsline{mdbox}{subsection}\mdf@frametitle]
{mdframedtoc}
\newcommand{\listofboxes}{%
 \section*{List of Boxes}
 \@starttoc{mdbox}%
}
\makeatother


%\newcommand{\listCautions}{List of Cautions}
%\newlistof{caution}{mdboxCat}{\listCautions}


\begin{document}

\tableofcontents
\listofboxes

\chapter{Stuff}

\lipsum[65]

\begin{TipBox}
Here's a tip.
  \label{ibx:Tip1}
\end{TipBox}


\begin{RecBox}
Here, we have a stand-alone recommendation.
  \label{ibx:Rec1}
\end{RecBox}

\begin{RecBox}
Here's another stand-alone recommendation.
  \label{ibx:Rec2}
\end{RecBox}

\begin{CatBox}
Here is a stand-alone caution.
 \label{ibx:Cat1}
\end{CatBox}

\begin{CatRecBox}
Here's a caution that is associated with a specific recommendation. 
\mdfsubtitle{\textcolor[rgb]{1,1,1}{Recommendation}}
And here's the associated recommendation \ldots
\label{ibx:CatRec1}
\end{CatRecBox}


\begin{TipBox}
Another tip
 \label{ibx:anothertip}
\end{TipBox}


\chapter{Other Stuff}

\begin{TipBox}
Here's a tip in the next chapter.
  \label{ibx:tipCh2}
\end{TipBox}

\begin{CatRecBox}
Here's another caution that is associated with a specific recommendation. 
\mdfsubtitle{\textcolor[rgb]{1,1,1}{Recommendation}}
And here's the associated recommendation \ldots
\label{ibx:CatRec2}
\end{CatRecBox}

\begin{RecBox}
Here's another stand-alone recommendation in Chapter 2
  \label{ibx:RecCh2}
\end{RecBox}

\begin{CatBox}
Here is a stand-alone caution in Chapter 2
 \label{ibx:CatCh2}
\end{CatBox}

\end{document}

答案1

另一个问题的解决方案可以扩展为包含不同类型的框。您可以定义三个不同的环境,并分别使用相应的、和参数,而不是定义单个newmdenv名为 的环境。对于mdframedtoccontentslinelistof\@starttoc谨慎加建议在这种情况下,您可以定义一个\newenvironment{CatRecBox}类似于其他框环境的,而不是newmdenv。对于此环境,您可以使用与警告框,以便在目录中显示它们(并在正文中编号)。

MWE(请注意,我改变了列表,以\subsection*使列表标题稍微小一些):

\documentclass{book}
\usepackage{lipsum}
\usepackage[english]{babel}


\newcounter{TipBox}[chapter]
\newcounter{RecBox}[chapter]
\newcounter{CatBox}[chapter]

\renewcommand{\theTipBox}{\thechapter.\arabic{TipBox}}
\renewcommand{\theRecBox}{\thechapter.\arabic{RecBox}}
\renewcommand{\theCatBox}{\thechapter.\arabic{CatBox}}


\usepackage[framemethod=tikz]{mdframed}

\makeatletter
\tikzset{
mdfsubtitlebackground/.style={
  draw=none,
  fill=\mdf@subtitlebackgroundcolor}
}
\makeatother

\definecolor{LightRed}{rgb}{0.784,0.537,0.714}
\definecolor{LightTeal}{rgb}{0.53,.745,.745}

% Tip boxes
\newenvironment{TipBox}[1][]{%
  \refstepcounter{TipBox}
  \begin{mdframedtiptoc}[%
      frametitle={Tip \theTipBox\ #1},
      backgroundcolor=gray!15,
      roundcorner=5pt,
      linecolor=teal,
      linewidth=2pt,
      middlelinecolor=white,
      frametitlebackgroundcolor=LightTeal,
      frametitlefontcolor=white,
      ]%
  }{%
  \end{mdframedtiptoc}
}

% Recommendation boxes
\newenvironment{RecBox}[1][]{%
  \refstepcounter{RecBox}
  \begin{mdframedrectoc}[%
      frametitle={Recommendation \theRecBox\ #1},
      backgroundcolor=gray!15,
      roundcorner=5pt,
      linecolor=teal,
      linewidth=2pt,
      middlelinecolor=white,
      frametitlebackgroundcolor=gray!80,
      frametitlefontcolor=white,
      ]%
  }{%
  \end{mdframedrectoc}
}

% Caution boxes
\newenvironment{CatBox}[1][]{%
  \refstepcounter{CatBox}
  \begin{mdframedcauttoc}[%
      frametitle={Caution \theCatBox\ #1},
      backgroundcolor=gray!15,
      roundcorner=5pt,
      linecolor=teal,
      linewidth=2pt,
      middlelinecolor=white,
      frametitlebackgroundcolor=LightRed,
      frametitlefontcolor=white,
      ]%
  }{%
  \end{mdframedcauttoc}
}

% Caution plus recommendation boxes
\newenvironment{CatRecBox}[1][]{%
  \refstepcounter{CatBox}
  \begin{mdframedcauttoc}[%
  frametitle={Caution \theCatBox\ #1},
  roundcorner=5pt,
  subtitlebelowline=false,
  subtitleaboveline=false,
  subtitlebackgroundcolor=gray!80,
  %subtitlefontcolor=white,
  backgroundcolor=gray!15,
  frametitlerule=true,
  frametitlebackgroundcolor=LightRed,
  frametitlefontcolor=white,
  linewidth=2pt,
  middlelinecolor=white,
  linecolor=gray!15,
  %innerlinewidth=0pt
     ]%
  }{%
  \end{mdframedcauttoc}
}

\makeatletter
\newmdenv[startinnercode=\addcontentsline{mdtipbox}{subsection}\mdf@frametitle]
{mdframedtiptoc}
\newcommand{\listoftips}{%
\subsection*{List of Tips}
\@starttoc{mdtipbox}%
}
\newmdenv[startinnercode=\addcontentsline{mdrecbox}{subsection}\mdf@frametitle]
{mdframedrectoc}
\newcommand{\listofrecs}{%
\subsection*{List of Recommendations}
\@starttoc{mdrecbox}%
}
\newmdenv[startinnercode=\addcontentsline{mdcautbox}{subsection}\mdf@frametitle]
{mdframedcauttoc}
\newcommand{\listofcauts}{%
\subsection*{List of Cautions}
\@starttoc{mdcautbox}%
}
\makeatother


%\newcommand{\listCautions}{List of Cautions}
%\newlistof{caution}{mdboxCat}{\listCautions}


\begin{document}

\tableofcontents
\listoftips
\listofrecs
\listofcauts

\chapter{Stuff}

\lipsum[65]

\begin{TipBox}
Here's a tip.
\label{ibx:Tip1}
\end{TipBox}


\begin{RecBox}
Here, we have a stand-alone recommendation.
\label{ibx:Rec1}
\end{RecBox}

\begin{RecBox}
Here's another stand-alone recommendation.
\label{ibx:Rec2}
\end{RecBox}

\begin{CatBox}
Here is a stand-alone caution.
\label{ibx:Cat1}
\end{CatBox}

\begin{CatRecBox}
Here's a caution that is associated with a specific recommendation. 
\mdfsubtitle{\textcolor[rgb]{1,1,1}{Recommendation}}
And here's the associated recommendation \ldots
\label{ibx:CatRec1}
\end{CatRecBox}


\begin{TipBox}
Another tip
\label{ibx:anothertip}
\end{TipBox}


\chapter{Other Stuff}

\begin{TipBox}
Here's a tip in the next chapter.
\label{ibx:tipCh2}
\end{TipBox}

\begin{CatRecBox}
Here's another caution that is associated with a specific recommendation. 
\mdfsubtitle{\textcolor[rgb]{1,1,1}{Recommendation}}
And here's the associated recommendation \ldots
\label{ibx:CatRec2}
\end{CatRecBox}

\begin{RecBox}
Here's another stand-alone recommendation in Chapter 2
\label{ibx:RecCh2}
\end{RecBox}

\begin{CatBox}
Here is a stand-alone caution in Chapter 2
\label{ibx:CatCh2}
\end{CatBox}

\end{document}

结果:

在此处输入图片描述

请注意,这可能可以更加自动化,以减少代码重复。

相关内容