Next: , Previous: , Up: Environments   [Contents][Index]

8.19 picture


   picture commands 


  picture commands

An environment to create simple pictures containing lines, arrows, boxes, circles, and text. Note that while this environment is not obsolete, new documents typically use much more powerful graphics creation systems, such as TikZ, PSTricks, MetaPost, or Asymptote. These are not covered in this document; see CTAN.

This shows the parallelogram law for adding vectors.

\begin{picture}(6,6)      % picture box will be 6cm wide by 6cm tall
  \put(0,0){\vector(2,1){4}}  % for every 2 over this vector goes 1 up
    \put(2,1){\makebox(0,0)[l]{\ first leg}}
    \put(5,4){\makebox(0,0)[l]{\ second leg}}  
    \put(3,3){\makebox(0,0)[r]{sum\ }}  

You can also use this environment to place arbitrary material at an exact location.

\usepackage{color,graphicx}  % in preamble
\begin{picture}(1,1)      % leave space, \textwidth wide and tall
  \put(0.25,0.35){\textcolor{red}{X Treasure here}}

The red X will be precisely a quarter of the \linewidth from the left margin, and 0.35\linewidth up from the bottom. Another example of this usage is to put similar code in the page header to get repeat material on each of a document’s pages.

The picture environment has one required argument, a pair of numbers (width,height). Multiply these by the value \unitlength to get the nominal size of the output, the space that LaTeX reserves on the output page. This nominal size need not be how large the picture really is; LaTeX will draw things from the picture outside the picture’s box.

This environment also has an optional argument (xoffset,yoffset). It is used to shift the origin. Unlike most optional arguments, this one is not contained in square brackets. As with the required argument, it consists of two real numbers. Multiply these by \unitlength to get the point at the lower-left corner of the picture.

For example, if \unitlength has been set to 1mm, the command


produces a box of width 100 millimeters and height 200 millimeters. The picture’s origin is the point (10mm,20mm) and so the lower-left corner is there, and the upper-right corner is at (110mm,220mm). When you first draw a picture you typically omit the optional argument, leaving the origin at the lower-left corner. If you then want to modify your picture by shifting everything, you can just add the appropriate optional argument.

Each picture command tells LaTeX where to put something by naming its position. A position is a pair such as (2.4,-5) giving the x- and y-coordinates. A coordinate is a not a length, it is a real number (it may have a decimal point or a minus sign). It specifies a length in multiples of the unit length \unitlength, so if \unitlength has been set to 1cm, then the coordinate 2.54 specifies a length of 2.54 centimeters.

LaTeX’s default for \unitlength is 1pt. it is a rigid length (see Lengths). Change it with the \setlength command (see \setlength). Make this change only outside of a picture environment.

Coordinates are given with respect to an origin, which is normally at the lower-left corner of the picture. Note that when a position appears as an argument, as with \put(1,2){...}, it is not enclosed in braces since the parentheses serve to delimit the argument. Also, unlike in some computer graphics systems, larger y-coordinates are further up the page.

There are four ways to put things in a picture: \put, \multiput, \qbezier, and \graphpaper. The most often used is \put. This


places the object with its reference point at coordinates (11.3,-0.3). The reference points for various objects will be described below. The \put command creates an LR box (see Modes). Anything that can go in an \mbox (see \mbox & \makebox) can go in the text argument of the \put command. The reference point will be the lower left corner of the box. In this picture


the three dots are just slightly left of the point of the angle formed by the two lines. (Also, \line(1,1){1} does not call for a line of length one; rather the line has a change in the x coordinate of 1.)

The \multiput, qbezier, and graphpaper commands are described below.

This draws a rectangle with a wavy top, using \qbezier for that curve.

  \put(0,0){\vector(1,0){8}}  % x axis
  \put(0,0){\vector(0,1){4}}  % y axis
  \put(2,0){\line(0,1){3}}       % left side rectangle
  \put(4,0){\line(0,1){3.5}}     % right side
  \thicklines                 % below here, lines are twice as thick
  \put(4.5,2.5){\framebox{Trapezoidal Rule}}

Unofficial LaTeX2e reference manual