邊緣有「標題」的框,周圍有空白

邊緣有「標題」的框,周圍有空白

給定一個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}

相關內容