Please help with a picture environment.

Please help with a picture environment.

Post by Gary A. Churc » Mon, 14 Aug 1995 04:00:00



Hi,

I've come across a problem for which I can't find a solution.

I want to create a new picture environment that draws a pair of
orthogonal axes with labels of a particular size.

This environment takes four arguments: xdim, ydim, xlabel, ylabel. Here's
a skeleton of the environment:

\newenvironment{axes}[4]{\begin{picture}(#1,#2)%
...

Quote:}%

{\end{picture}}

A call to this environment would be:

\setlength{\unitlength}{1in}
\begin{axes}{4}{3}{time}{Power}
\put(...
\put(...
...
\end{axes}

The result would be a 4" by 3" picture like that shown below:

                              ^ Power
                              |
                              |
                              |
                              |
                              |
        <----------------------------------------------->
                              |                     time
                              |
                              |
                              |
                              |
                              ~

(this is the bare coord. system without additional graphic elements that
might be provided by various "\put"'s within the environment.)

The labels should be positioned as shown with the y-label a small
distance to the right of the up arrow of the y-axis and the x-label a
small distance under the x-axis right-flush with the right arrow.

Ideally the put's within this environment would have an origin consistent
with the location of the intersection of the axes.

TIA for any solutions,
Gary

--

 
 
 

Please help with a picture environment.

Post by Gary A. Churc » Wed, 16 Aug 1995 04:00:00



: Hi,

: I've come across a problem for which I can't find a solution.

: I want to create a new picture environment that draws a pair of
: orthogonal axes with labels of a particular size.

: This environment takes four arguments: xdim, ydim, xlabel, ylabel. Here's
: a skeleton of the environment:

After some tinkering, I've come up with a solution to my own problem.
I'm no macro author but it seems to work. Here it is:

\setlength{\unitlength}{0.01in}

\newcount\xdim
\newcount\ydim
\newcount\xorg
\newcount\yorg

\newenvironment{\myaxes}[6]{%
\xdim=#1%
\ydim=#2%
\xorg=#3%
\yorg=#4%
\multiply\xorg by -1%
\multiply\yorg by -1%
\begin{picture}(\xdim,\ydim)(\xorg,\yorg)%
\put(\xorg,0){\vector(1,0){\xdim}}%
\put(0,\yorg){\vector(0,1){\ydim}}%
\advance\xdim by \xorg%
\advance\ydim by \yorg%
\put(\xdim,-5){\makebox(0,0)[tr]{\large#5}}%
\put(-5,\ydim){\makebox(0,0)[tr]{\large#6}}%

Quote:}%

{\end{picture}}

Other "axes-type" environments can be defined in terms of this one:

\newenvironment{firstquad}[2]{\begin{myaxes}{175}{175}{20}{20}{#1}{#2}}%
{\end{myaxes}}

Thus entering:

\begin{firstquad}{$x$}{$y$}
  \put(50,80){\circle*{5}}
\end{firstquad}

will create a picture 1.75in by 1.75in with the origin shifted .20in up
and to the right of the lower left corner. There will be a horizontal
axis labeled "x" and a vertical axis labeled "y."

It took me awhile to come up with this since I've never delved into TeX
commands to create*macros. Learned alot though.

Gary.

--