# How to typeset a frame with the title across the boundary?

How could I typeset a frame like:

?

I've always used mdframed or tcolorbox to typeset frames but I cannot find mention of such functionality.

Is there a simple way of achieving this effect with one of the above-mentioned packages? If not can we obtain that output with a tcolorbox's skin via tikz? If not how else could we get that box?

-
have you seen example 6 in the mdframed documentation? – cmhughes Oct 22 '13 at 21:23
@cmhughes I did search look at the user guide of mdframed but I didn't know there was a separate file with some examples(at least on my distribution). Yes, that example matches quite closely what I wanted. – Bakuriu Oct 22 '13 at 21:37

# Remarks

This solution using tcolorbox was heavily inspired by the "FancyTitle" example in the tcolorbox documentation on page 45.

# Implementation

\documentclass{article}
\pagestyle{empty}
\usepackage{tcolorbox,lipsum}
% Inspired by FancyTitle in the tcolorbox-doc page 45
\tcbuselibrary{skins}
\newtcolorbox{mycolorbox}[2][]{%
enhanced,
colback=white,colframe=black,
arc=0pt,outer arc=0pt,
enlarge top by=\baselineskip/2+1mm,
overlay unbroken and first={%
\node[
rectangle,fill=white,
inner sep=1mm,anchor=west
] at ([xshift=4.5mm]frame.north west) {\strut\textbf{#2}};
},
#1%
}
\begin{document}
\lipsum[1]
\begin{mycolorbox}{Variables}
$\frac{}{x_1 : A_1,\ldots,x_n : A_n \vdash x_i : A_i} i \in \{ 1,\ldots,n \}$
\end{mycolorbox}
\lipsum[1]
\end{document}


# Output

-
I received an "Undefined control sequence \newtcolorbox" when trying your solution. I have tcolorbox version 1.30 on my machine. – Bakuriu Oct 23 '13 at 6:23
I am on the latest CTAN version, which is 2.51. You might want to consider updating your TeXlive. – Henri Menke Oct 23 '13 at 6:35
Okay, I was able to install the new version of tcolorbox and it seems to work fine. – Bakuriu Oct 23 '13 at 6:55

You could use TikZ for the task:

## Code

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc}

\usepackage{lipsum}

\newcommand{\mybox}[3][black]% [options] title, content
{   \par
\begin{tikzpicture}
\node[draw,minimum width=\textwidth,inner sep=5mm,align=center,#1] (tempnode) {#3};
\node[right,#1,fill=white] at ($(tempnode.north)!0.9!(tempnode.north west)$) {#2};
\end{tikzpicture}
\par
}

\begin{document}

\lipsum[1]

\mybox{Test 1}{$\int\limits_{e}^{\pi}\log_2 x\ dx$}

\lipsum[2]

\mybox[very thick,red]{Test 2}{$\int\limits_{e}^{\pi}\log_2 x\ dx$}

\lipsum[3]

\mybox[line width=1mm,densely dashed,cyan!50!lime,text=black]{Test 3}{$\int\limits_{e}^{\pi}\log_2 x\ dx$}

\lipsum[4]

\end{document}


## Edit 1:

As the very wide boxes cause overfull hbox warnings, I used \rlap from the mathtools package to reduce their width to zero. This is probably okay for thin frames, but very thick frames might extrude into the margin. Also, now you can influence the text and title separately (and hence go nuts if you like):

## Code

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{mathtools}

\usepackage{lipsum}

\newcommand{\mybox}[4]% title, content, options, title options
{   \par
\vspace{3mm}
\rlap{%
\begin{tikzpicture}
\node[draw,minimum width=\textwidth,inner sep=5mm,align=center,outer sep=0pt,#3] (tempnode) {#2};
\node[fill=white,right,#4] at ($(tempnode.north)!0.9!(tempnode.north west)$) {#1};
\end{tikzpicture}}
\par
}

\begin{document}

\lipsum[1]

\mybox{Test 1}{$\int\limits_{e}^{\pi}\log_2 x\ dx$}{}{}

\lipsum[2]

\mybox{Test 2}{$\int\limits_{e}^{\pi}\log_2 x\ dx$}{red,densely dotted,ultra thick,fill=yellow!30}{text=red,rounded corners=3mm,font=\Huge,circle}

\lipsum[3]

\mybox{Test 3}{$\int\limits_{e}^{\pi}\log_2 x\ dx$}{text=yellow,inner color=blue,outer color=red,rounded corners=10mm}{left color=orange,right color=yellow,rounded corners=3mm,draw}

\lipsum[4]

\end{document}


## Output

-
This doesn't work when used with the semantic package. pdflatex simply keeps compiling at 100% CPU and never ends. Also it fails when using environments for the text. – Bakuriu Oct 23 '13 at 6:39
Hmm, I didn't check that to be honest. In that case, you should probably accept Henri's answer. – Tom Bombadil Oct 23 '13 at 11:12