[OS X TeX] Squeezing text into boxes

Luis Sequeira lfsequeira at gmail.com
Fri Jul 18 10:32:48 CEST 2008


> Good Morning!
>
> I'm trying to create text in a box to simulate the buttons on a
> graphing
> calculator. I've read the sections in "Guide to LaTeX" and "More
> Math into
> LaTeX" about using \fbox and have been experimenting with that
> command. I've
> figured out how to get the text centered in a box of a specific
> width (not
> hard) but have been stumped on getting
>
> 1. A framed box of text of a specific width AND height (so it
> matches the
> graphing calculator button)
>
> and
>
> 2. The text squeezed into the specific sized box (don't want to flow
> out the
> ends.)
>
> I suspect the resolution to #1 is just something I've missed in all
> the
> documentation, but #2 seems tougher. I know I could individually
> adjust each
> bit of text for each button, but it would sure be nice to not have
> to do
> that.
>
> Any ideas, suggestions or comments about how I might be able to do
> these
> tasks?
>
> Thanks,
>
> Randy Scott
> Santiago Canyon College

I second the suggestion to use pstricks. It is easy create the boxes,  
color them and put the text in them. And you can easily scale anything  
to fit, as the OP pointed out.

I was able to draw a little calculator in pstricks in just a few  
minutes,

[if you want to take a look at the result, see here: http://www.ptmat.fc.ul.pt/~lsequeir/calculator.pdf 
  ]

so feel free to use this and customize to your heart's content.

I began by defining a command to draw and place any calculator button.  
They can be of different sizes and colors, so the command expects this  
info in its parameters.

%a command to draw and place a calculator button
%usage:
%\calcbutton{x}{y}{halfwidth}{halfheight}{color}{text}

\newcommand{\calcbutton}[6]{%
\rput(#1,#2){
   \psframe*[linecolor=#5,framearc=0.4](-#3,-#4)(#3,#4)
   \rput(0,0){\textbf{#6}}
}
}


Now we can draw our little calculator in a pspicture, such as the  
following example (which yields the picture in the above link):

\begin{pspicture}(0,-1)(6,10)
\psframe*[linecolor=yellow,framearc=0.2](-1,-2)(9,10)
\psframe*[linecolor=cyan](0,7)(8,9)
\multido{\n=1+1,\i=1+2}{3}{\calcbutton{\i}{1}{0.85}{0.5}{lightgray}{\n}}
\multido{\n=4+1,\i=1+2}{3}{\calcbutton{\i}{2.5}{0.85}{0.5}{lightgray} 
{\n}}
\multido{\n=7+1,\i=1+2}{3}{\calcbutton{\i}{4}{0.85}{0.5}{lightgray}{\n}}
\calcbutton{2}{-0.5}{1.85}{0.5}{lightgray}{0}
\calcbutton{5}{-0.5}{0.85}{0.5}{lightgray}{.}
\calcbutton{1}{5.5}{0.85}{0.5}{red}{C}
\calcbutton{3}{5.5}{0.85}{0.5}{lightgray}{$\pm$}
\calcbutton{5}{5.5}{0.85}{0.5}{lightgray}{$\div$}
\calcbutton{7}{5.5}{0.85}{0.5}{lightgray}{$\times$}
\calcbutton{7}{4}{0.85}{0.5}{lightgray}{$-$}
\calcbutton{7}{2.5}{0.85}{0.5}{lightgray}{$+$}
\calcbutton{7}{0.25}{0.85}{1.25}{green}{$=$}
\end{pspicture}


Notes:

1) As always, when using pstricks, you must use "TeX & Ghostscript"  
instead of pdflatex.

2) Also, don't forget to

\usepackage{pstricks,multido}

(I used multido in this example, but you can do without it and draw  
each button individually)

3) Feel free to email me privately if you need further assistance. I  
am on digest mode, and also possibly some details may not be of  
interest to most members.

4) As to the size of the text: you can \scalebox or \psscalebox or  
\psscaleboxto as needed; and, if necessary, make use of pstricks'  
clipping facilities.

HTH

Luis Sequeira








More information about the macostex-archives mailing list