7

I'd like to draw a rounded rectangle behind an existing tcolorbox. The result should look like this:

enter image description here

That's what I've got so far:

\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}
  • Will the word "Wert" be constant or will it change from box to box? – Gonzalo Medina Apr 12 '14 at 14:20
  • In the end I will create a macro "\wert" that has the content as parameter and the word "Wert" constantly above the box (eg \wert{That's what is inside of the box}) – Moldevort Apr 12 '14 at 14:27
7

One option using interior titled code to first draw the gray filled rounded rectangle for the title and then the rounded rectangle for the contents:

\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}

enter image description here

The definition for the \wert command then might be something like

\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}

If the title for the boxes must be variable, a simple modification for the above code (introducing an optional or mandatory argument for the tcolorbox) will suffice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.