views:

476

answers:

3

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?

+1  A: 

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.

reinierpost
+3  A: 

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.

Ewan Todd
Thanks to Stephan202 for the \newcommand translation here. I want to give everyone +1 simply for being into LaTeX, but SO is not letting me do that unless y'all make some new edits.
Ewan Todd
Thanks Ewan :DLaTeX rocks. I've not found anything better for math.Also, nice find with keystrokes. I don't really need the fancy buttons but again, thanks :D
Mike
+4  A: 

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$}
Alexey Malistov
Thanks Alexey. You rock; i was only after a hint to the solution but got a perfect macro.I'll decompose this later to see how it works :D
Mike