8

I want to write something like in the attached file.enter image description here

In particular I want the box to be flexible in such a way that it can contain the text -- both in the small box and the bigger one.

Any help will be appreciated.

14

An example with 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} 

Output

enter image description here

6

Here's another option, allowing page breaks as the tcolorbox option, but using the also powerful mdframed package:

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

enter image description here

  • Is there a reason why you used \strut#1\strut instead of \strut#1? – Tobi Nov 1 '15 at 16:35
4
\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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.