Basically, on the top line of an fbox, I'd like the line to be interrupted by a label.
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.
General ⇒ Framed box with label vertically centered over top line
Framed box with label vertically centered over top line
- Attachments
-
- sample.pdf
- (17.57 KiB) Downloaded 281 times
Last edited by kostka on Fri Apr 02, 2010 5:27 am, edited 1 time in total.
NEW: TikZ book now 40% off at Amazon.com for a short time.
Re: Framed box with label vertically centered over top line
Found out about \raisebox, which might work for what I want. I'll post an update at some point.
Framed box with label vertically centered over top line
Yep, I was able to use /raisebox to do this, along with a bunch of other things. I'll post the solution here, but keep in mind it relies on several things in my own style file, including /ssp which sets spacing to single space.
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:
And then the code
Produces the output:

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.
