绘制 LaTeX 框

绘制 LaTeX 框

我想写一些类似于附件中的内容。在此处输入图片描述

特别是,我希望该框具有灵活性,以便它可以包含文本——无论是在小框中还是在大框中。

任何帮助将不胜感激。

答案1

以 为例tcolorbox

\documentclass{article}

\usepackage[most]{tcolorbox}

\newtcolorbox{mybox}[1]{%
colback=white,
colbacktitle=white,
coltitle=black,
leftrule=0pt,
rightrule=0pt,
toprule=0.4pt,
bottomrule=0.4pt,
boxsep=0pt,
left=0pt,
right=0pt,
top=10pt,
bottom=10pt,
arc=0pt,
breakable,
enhanced,
attach boxed title to top center={yshift=-2mm},
boxed title style={boxrule=0.4pt,arc=0pt},
title=#1}

\usepackage{lipsum} % just for the example

\begin{document}
\begin{mybox}{A title}
\lipsum[1]
\end{mybox}
\end{document} 

输出

在此处输入图片描述

答案2

这是另一个选项,允许分页作为tcolorbox选项,但使用同样强大的mdframed包裹:

\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{lipsum} % just for the example

\newenvironment{boxed}[1]
  {%
    \begin{mdframed}[hidealllines=true,
      topline=true,
      bottomline=true,
      skipabove=\dimexpr\topsep+\ht\strutbox\relax,
      innertopmargin=\dimexpr\ht\strutbox+1.35ex\relax,
      innerleftmargin=0pt,
      innerrightmargin=0pt,
      singleextra={\path (P) -- node[overlay,draw,fill=white] {\strut#1\strut} (O|-P);},
      firstextra={\path (P) -- node[overlay,draw,fill=white] {\strut#1\strut} (O|-P);}
    ]
  }
  {\end{mdframed}}

\begin{document}

\lipsum[2]
\begin{boxed}{The title}
\lipsum[4]
\end{boxed}
\lipsum[4]

\end{document}

在此处输入图片描述

答案3

\documentclass{article}
\begin{document}
{\parindent0pt\relax
\raisebox{6pt}{\hbox to \textwidth{%
  \hrulefill\fbox{\textit{DB}: \textbf{D}enominator \textbf{B}ounding}\hrulefill}}\par
$\bullet$ \textbf{Given} blah-blah-blah blah-blah-blah\par
$\bullet$ \textbf{Find} blah-blah-blah blah-blah-blah\par
\hrulefill}
\end{document}

在此处输入图片描述

相关内容