如何使用 tcolorbox/任何其他包創建多級彩色框?

如何使用 tcolorbox/任何其他包創建多級彩色框?

tcolorbox手冊提供了以下範例:

在此輸入影像描述

任何人都可以建議我如何創建這種類型的盒子 - 沒有。新增的行數必須靈活(似乎 tcolorbox 除了頂部和底部之外沒有其他選項):

在此輸入影像描述

答案1

這是使用的一種可能性mdframed

\documentclass{article}
\usepackage{xcolor}
\usepackage[framemethod=tikz]{mdframed}

\definecolor{mybrown}{RGB}{128,64,0}

\mdfdefinestyle{mystyle}{%
linecolor=mybrown,outerlinewidth=1pt,%
frametitlerule=true,frametitlefont=\sffamily\bfseries\color{white},%
frametitlerulewidth=1pt,frametitlerulecolor=mybrown,%
frametitlebackgroundcolor=mybrown,
backgroundcolor=mybrown!05,
innertopmargin=\topskip,
roundcorner=5pt
}
\mdtheorem[style=mystyle]{example}{Example}

\gdef\Sepline{%
  \par\noindent\makebox[\linewidth][l]{%
  \hspace*{-\mdflength{innerleftmargin}}%
   \tikz\draw[thick,dashed,gray!60] (0,0) --%
        (\textwidth+\the\mdflength{innerleftmargin}+\the\mdflength{innerrightmargin},0);
  }\par\nobreak}


\begin{document}

\begin{example}[The Title]
The contents of the first part.
\Sepline
\noindent The contents of the second part.
\Sepline
\noindent The contents of the third part.
\Sepline
\noindent The contents of the fourth part.
\end{example}

\end{document}

在此輸入影像描述

現在,這裡的修改不使用類似定理的結構,而是使用一個帶有強制參數來提供標題的簡單環境:

\documentclass{article}
\usepackage{xcolor}
\usepackage[framemethod=tikz]{mdframed}

\definecolor{mybrown}{RGB}{128,64,0}

\mdfdefinestyle{mystyle}{%
linecolor=mybrown,outerlinewidth=1pt,%
frametitlerule=true,frametitlefont=\sffamily\bfseries\color{white},%
frametitlerulewidth=1pt,frametitlerulecolor=mybrown,%
frametitlebackgroundcolor=mybrown,
backgroundcolor=mybrown!05,
innertopmargin=\topskip,
roundcorner=5pt
}
\newmdenv[style=mystyle]{exa}
\newenvironment{example}[1]
  {\begin{exa}[frametitle=#1]}
  {\end{exa}}

\gdef\Sepline{%
  \par\noindent\makebox[\linewidth][l]{%
  \hspace*{-\mdflength{innerleftmargin}}%
   \tikz\draw[thick,dashed,gray!60] (0,0) --%
        (\textwidth+\the\mdflength{innerleftmargin}+\the\mdflength{innerrightmargin},0);
  }\par\nobreak}

\begin{document}

\begin{example}{The Title}
The contents of the first part.
\Sepline
\noindent The contents of the second part.
\Sepline
\noindent The contents of the third part.
\Sepline
\noindent The contents of the fourth part.
\end{example}

\end{document}

在此輸入影像描述

答案2

tcolorbox不提供新增多個下部部分的程式碼。但您可以新增額外的行:

\documentclass{report}

\usepackage{tikz,tcolorbox}

\makeatletter
\newcommand{\DrawLine}{%
  \begin{tikzpicture}
  \path[use as bounding box] (0,0) -- (\linewidth,0);
  \draw[color=red!75!black,dashed,dash phase=2pt]
        (0-\kvtcb@leftlower-\kvtcb@boxsep,0)--
        (\linewidth+\kvtcb@rightlower+\kvtcb@boxsep,0);
  \end{tikzpicture}%
  }
\makeatother

\begin{document}

\begin{tcolorbox}[colback=red!5,colframe=red!75!black,title=My nice heading]

This is another \textbf{tcolorbox}.

\tcblower

Here, you see the lower part of the box.

\DrawLine

and some more

\end{tcolorbox}

\end{document}

這產生:

在此輸入影像描述

相關內容