가장자리에 '제목'이 있고 주변에 공백이 있는 상자

가장자리에 '제목'이 있고 주변에 공백이 있는 상자

패키지 상자(또는 선택한 다른 항목) 가 주어지면 framed왼쪽과 오른쪽에 약간의 공백이 있는 상자 테두리에 첫 번째 줄(한두 단어만 포함)을 어떻게 띄울 수 있습니까?

나는 다음과 같은 효과를 찾고 있습니다 :

여기에 이미지 설명을 입력하세요

답변1

라이브러리를 사용하여 시도해 볼 수 있습니다 tikz. 나는 당신이 완전히 포장된 상자를 원한다고 생각했지만 확실하지 않습니까?여기에 이미지 설명을 입력하세요

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

답변2

tcolorbox다음은 상자를 그리고 가장자리에 제목을 배치하는 데 사용하는 버전입니다 .

여기에 이미지 설명을 입력하세요

소스 코드는 다음과 같습니다.

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

관련 정보