在 tcolorbox 后面画一个矩形

在 tcolorbox 后面画一个矩形

我想在现有的后面绘制一个圆角矩形tcolorbox。结果应如下所示:

在此处输入图片描述

这就是我目前得到的:

\documentclass{book}

\usepackage[many]{tcolorbox}
\usetikzlibrary{calc}
\definecolor{mp}{RGB}{240,240,240} % Farbe für Nummerierung

\tcbset{ % Rahmen
    colback=white,
  arc=20pt,
  freelance,
  frame code={
    \draw[rounded corners=20pt,color=mp, line width=1pt]
      (frame.south west) -- 
      (frame.north west) -- 
      (frame.north east) --
      (frame.south east) -- cycle;
  }
}

\begin{document}

Wert
\begin{tcolorbox}   
Erwachsen \\
8,9 - 10,1 mg/dL
2,25 - 2,75 mmol/L
Kinder höher
\end{tcolorbox}

\end{document}

答案1

一个选项是interior titled code首先绘制灰色填充的圆角矩形作为标题,然后绘制圆角矩形作为内容:

\documentclass{book}

\usepackage[many]{tcolorbox}
\usetikzlibrary{calc}
\definecolor{mp}{RGB}{240,240,240} % Farbe für Nummerierung

\tcbset{ % Rahmen
  arc=20pt,
  outer arc=20pt,
  title=Wert,
  coltitle=black,
  enhanced,
  freelance,
  frame code={},
  interior titled code={
    \fill[mp,rounded corners=12pt]
      ([xshift=-1pt,yshift=-10pt]interior.west)
      rectangle
      ([xshift=50pt,yshift=3pt]title.north west); 
    \draw[rounded corners=20pt,color=mp, line width=1pt,fill=white]
      (frame.south west) -- 
      (title.south west) -- 
      (title.south east) --
      (frame.south east) -- cycle;
  },
}

\begin{document}

\begin{tcolorbox}   
Erwachsen \\
8,9 - 10,1 mg/dL
2,25 - 2,75 mmol/L
Kinder höher
\end{tcolorbox}

\end{document}

在此处输入图片描述

该命令的定义\wert可能类似于

\documentclass{book}
\usepackage[many]{tcolorbox}
\usetikzlibrary{calc}
\definecolor{mp}{RGB}{240,240,240} % Farbe für Nummerierung

\newcommand\wert[1]{%
\begin{tcolorbox}[   
  arc=20pt,
  outer arc=20pt,
  title=Wert,
  coltitle=black,
  enhanced,
  freelance,
  frame code={},
  interior titled code={
    \fill[mp,rounded corners=12pt]
      ([xshift=-1pt,yshift=-10pt]interior.west)
      rectangle
      ([xshift=50pt,yshift=3pt]title.north west); 
    \draw[rounded corners=20pt,color=mp, line width=1pt,fill=white]
      (frame.south west) -- 
      (title.south west) -- 
      (title.south east) --
      (frame.south east) -- cycle;
  }
]
#1
\end{tcolorbox}%
}

\begin{document}

\wert{Erwachsen \\
8,9 - 10,1 mg/dL
2,25 - 2,75 mmol/L
Kinder höher}

\end{document}

如果框的标题必须是变量,则对上述代码进行简单修改(引入一个可选或强制参数tcolorbox)就足够了。

相关内容