I need to represent calculator key presses by the text for the keys to press surrounded by a box. I tried to get away 开发者_如何转开发with just the bare key presses (no box) but I got marked down for it because it would appear my assessor is a bit of a pedant.
Anyway, a bit of research turned up the likes of \boxit and \fbox.
I gave them both a go but \boxit produces nigh on identical results to \fbox. The problem is that the height and baseline of the box varies with the glyphs it contains.
Take the following example that represents pressing 5, multiply, x;
\documentclass{article}
\usepackage{fullpage}
\begin{document}
\fbox{5} \fbox{$\times$} \fbox{$x$}
\end{document}
This generates boxes around the content but they're on different baselines and they're all different heights.
Given what I've seen of LaTeX thus far I'd say this is definitely possible but CTAN, news groups and google have turned up nothing useful thus far.
Any hints?
Using \strut
to make the same height.
\def\press#1{\fbox{\hbox to 1em{\strut\hfil#1\hfil}}}
\press{5} \press{$\times$} \press{$x$}
or set any height and depth of your box:
\def\press#1{{\setbox0=\hbox to 1em{\hfil#1\hfil}\ht0=7.5pt \dp0=2.5pt \fbox{\box0}}}
\press{5} \press{$\times$} \press{$x$}
This looks close to what you are trying to do.
\framebox[2em][c]{5\strut}
\framebox[2em][c]{$\times$\strut}
\framebox[2em][c]{$x$\strut}
You may want to create a new command to create the keys, to avoid repeating yourself:
\newcommand{\key}[1]{\framebox[2em][c]{#1\strut}}
\key{5}
\key{$\times$}
\key{$x$}
I did find a package called keystroke.sty, but it may be overkill for what you're trying to do.
The best I can come up with:
\newcommand{\vlen}[1]{\parbox[c][#1]{0cm}{}}
\fbox{\vlen{1cm}5} \fbox{\vlen{1cm}$\times$} \fbox{\vlen{1cm}$x$}
Yegh.
精彩评论