Next: quotation & quote, Previous: minipage, Up: Environments [Contents][Index]
picture
Synopses:
\begin{picture}(width,height) picture commands \end{picture}
or
\begin{picture}(width,height)(xoffset,yoffset) picture commands \end{picture}
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.
\setlength{\unitlength}{1cm} \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(4,2){\vector(1,2){2}} \put(5,4){\makebox(0,0)[l]{\ second leg}} \put(0,0){\line(1,1){6}} \put(3,3){\makebox(0,0)[r]{sum\ }} \end{picture}
You can also use this environment to place arbitrary material at an exact location.
\usepackage{color,graphicx} % in preamble ... \begin{center} \setlength{\unitlength}{\textwidth} \begin{picture}(1,1) % leave space, \textwidth wide and tall \put(0,0){\includegraphics[width=\textwidth]{desertedisland.jpg}} \put(0.25,0.35){\textcolor{red}{X Treasure here}} \end{picture} \end{center}
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
\begin{picture}(100,200)(10,20)
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
\put(11.3,-0.3){...}
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
\setlength{\unitlength}{1cm} ...\begin{picture}(1,1) \put(0,0){\line(1,0){1}} \put(0,0){\line(1,1){1}} \end{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.
\begin{picture}(3,1.5) \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 \qbezier(2,3)(2.5,2.9)(3,3.25) \qbezier(3,3.25)(3.5,3.6)(4,3.5) \thicklines % below here, lines are twice as thick \put(2,3){\line(4,1){2}} \put(4.5,2.5){\framebox{Trapezoidal Rule}} \end{picture}
• \put: | Place an object at a specified place. | |
• \multiput: | Draw multiple instances of an object. | |
• \qbezier: | Draw a quadratic Bezier curve. | |
• \graphpaper: | Draw graph paper. | |
• \line: | Draw a straight line. | |
• \linethickness: | Set thickness of horizontal and vertical lines. | |
• \thinlines: | The default line thickness. | |
• \thicklines: | A heavier line thickness. | |
• \circle: | Draw a circle. | |
• \oval: | Draw an oval. | |
• \shortstack: | Make a stack of objects. | |
• \vector: | Draw a line with an arrow. | |
• \makebox (picture): | Draw a box of the specified size. | |
• \framebox (picture): | Draw a box with a frame around it. | |
• \frame: | Draw a frame around an object. | |
• \dashbox: | Draw a dashed box. |