2

I'd like to make a frame (probably using mdframed) as in the example picture I included. I looked around on this website and tried to google the think, but I don't even know how to desrcibe this in words (when I type "header" or "text inside frame" I get very different results. Sorry, I'm not a native speaker).

The example is taken from a slide of a statistics course I attended a while ago. Unfortunately, I don't have the LaTeX-file, only the finished PDF document. Would be great if anyone could give me a hint how to do this in LaTeX. Thanks!

Example Frame

4

This is just an starting point with tcolorbox. From there you can configure whatever you want, font, colors, corners, ...

\documentclass{article}
\usepackage[most]{tcolorbox}

\newtcolorbox{mybox}[2][]{enhanced,fonttitle=\ttfamily,fontupper=\ttfamily,attach boxed title to top center={yshift=-2mm}, title=#2,#1}

\begin{document}

\begin{mybox}{R code}
boxplot(x,horizontal=TRUE)
\end{mybox}

\end{document}

enter image description here

Next one looks more similar to what's wanted:

\documentclass{article}
\usepackage[most]{tcolorbox}

\newtcolorbox{mybox}[2][]{enhanced,
    fonttitle=\ttfamily,
    fontupper=\ttfamily,
    sharp corners,
    colback=white,
    colbacktitle=white,
    coltitle=black,
    boxed title style={colframe=white},
    attach boxed title to top center={yshift=-3mm}, 
    title=#2,#1}

\begin{document}

\begin{mybox}{R code}
boxplot(x,horizontal=TRUE)
\end{mybox}

\end{document}

enter image description here

2

With only tikz

\documentclass{article}
\usepackage{tikz}
\usepackage{environ}

\NewEnviron{mybox}[1][]{%
 \noindent
 \begin{tikzpicture}
   \node[minimum width=\linewidth-0.4pt,draw,text width=\linewidth-12pt,,font=\ttfamily] (a){\BODY};
   \node[fill=white,yshift=0.5ex,font=\ttfamily] at (a.north) {#1};
 \end{tikzpicture}}

\begin{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.