General ⇒ Framed box with label vertically centered over top line
Framed box with label vertically centered over top line
I've attached a pdf file that shows exactly what I'm after. Is there a way to do this? I'm not looking for someone to do the work for me, but some direction would be nice. I've tried using a tabular environment, but the vertical alignment doesn't work out. Might there be a way to "nudge" text to appear above where it otherwise "should" appear?
Thanks in advance.
- Attachments
-
- sample.pdf
- (17.57 KiB) Downloaded 291 times
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
Re: Framed box with label vertically centered over top line
Framed box with label vertically centered over top line
What's really nice for me about this is the text within the environment is taken verbatim, so all special characters are okay.
Within the preamble, I have defined:
Code: Select all
% probably several others needed here as well
\usepackage{verbatim}
\usepackage{varwidth}
...
\newsavebox{\codebox}
\newsavebox{\labelbox}
\newenvironment{labelcodebox}[1]
{\VerbatimEnvironment\begin{lrbox}{\labelbox}\it\footnotesize#1\end{lrbox}%
\begin{lrbox}{\codebox}\begin{varwidth}{\linewidth-0.5in-2\tabcolsep-2\fboxrule}\ssp\small\begin{Verbatim}}
{\end{Verbatim}\end{varwidth}\end{lrbox}
{\begin{flushright}\ssp\tt\small\begin{tabularx}{\linewidth-0.5in}{|Xcp{1ex}<{\hfill}|}
\cline{1-1} \cline{3-3}
& \raisebox{1.3ex}[0ex]{\usebox{\labelbox}} & \\ [-2ex]
\multicolumn{3}{|@{}l@{}|}{
\begin{tabular}{@{}l@{}}
\setlength{\fboxrule}{0pt}\setlength{\fboxsep}{0.4\tabcolsep}\hspace{0.6\tabcolsep}\fbox{\usebox{\codebox}}
\end{tabular}
} \\
\hline
\end{tabularx}\end{flushright}}\par\ignorespacesafterend\noindent}
Code: Select all
One can write
\begin{labelcodebox}{Sample Linux code}
> cd ..
> rm -r $OLDPWD
\end{labelcodebox}
to delete the directory you were just in.
