Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
Will the word "Wert" be constant or will it change from box to box? –  Gonzalo Medina Apr 12 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 at 14:27

1 Answer 1

up vote 7 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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