Feld mit „Titel“ am Rand und weißem Rand

Feld mit „Titel“ am Rand und weißem Rand

Wie kann ich bei einer framedPaketschachtel (oder einer anderen Schachtel Ihrer Wahl) die erste Zeile (mit nur einem oder zwei Wörtern) so auf dem Rand der Schachtel schweben lassen, dass links und rechts etwas Leerraum bleibt?

Ich suche nach folgendem Effekt:

Bildbeschreibung hier eingeben

Antwort1

Sie könnten dies mithilfe der tikzBibliothek versuchen. Ich nahm an, Sie wollten eine vollständig ausgekleidete Schachtel, aber ich bin mir nicht sicher?Bildbeschreibung hier eingeben

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}

\tikzstyle{background rectangle}=[thin,draw=black]
\begin{tikzpicture}[show background rectangle]

\node[align=justify, text width=\textwidth, inner sep=1em]{
Some sample text here thats in the box
};

\node[xshift=3ex, yshift=-0.7ex, overlay, fill=white, draw=white, above 
right] at (current bounding box.north west) {
\textit{Push}
};

\end{tikzpicture} 
\end{document}

Antwort2

Hier ist eine Version, bei der tcolorboxdas Feld gezeichnet und der Titel am Rand platziert wird.

Bildbeschreibung hier eingeben

Dies ist der Quellcode:

\documentclass{article}

\usepackage[skins]{tcolorbox}

\newtcolorbox{myframe}[2][]{%
  enhanced,colback=white,colframe=black,coltitle=black,
  sharp corners,boxrule=0.4pt,
  fonttitle=\itshape,
  attach boxed title to top left={yshift=-0.3\baselineskip-0.4pt,xshift=2mm},
  boxed title style={tile,size=minimal,left=0.5mm,right=0.5mm,
    colback=white,before upper=\strut},
  title=#2,#1
}

\begin{document}

\begin{myframe}{Push}
  Some sample text here thats in the box.
\end{myframe}

\begin{myframe}{Pop}
  Some sample text. Some sample text. Some sample text. Some sample text.
  Some sample text. Some sample text. Some sample text. Some sample text.
  Some sample text. Some sample text. Some sample text. Some sample text.
\end{myframe}

\end{document}

verwandte Informationen