Caixa com “título” na borda e espaço em branco ao redor

Caixa com “título” na borda e espaço em branco ao redor

Dada uma framedcaixa de pacote (ou qualquer outra de sua escolha), como posso fazer a primeira linha (com apenas uma ou duas palavras) flutuar na borda da caixa com um pouco de espaço em branco nos lados esquerdo e direito?

Estou procurando o seguinte efeito:

insira a descrição da imagem aqui

Responder1

Você poderia tentar isso usando a tikzbiblioteca. Presumi que você queria uma caixa totalmente forrada, mas não tem certeza?insira a descrição da imagem aqui

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

Responder2

Aqui está uma versão usada tcolorboxpara desenhar a caixa e colocar o título na borda.

insira a descrição da imagem aqui

Este é o código fonte:

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

informação relacionada