From Wikibooks, open books for an open world
Jump to navigation Jump to search


Getting Started
  1. Introduction
  2. Installation
  3. Installing Extra Packages
  4. Basics
  5. How to get help

Common Elements

  1. Document Structure
  2. Text Formatting
  3. Paragraph Formatting
  4. Colors
  5. Fonts
  6. List Structures
  7. Special Characters
  8. Internationalization
  9. Rotations
  10. Tables
  11. Title creation
  12. Page Layout
  13. Customizing Page Headers and Footers‎
  14. Importing Graphics
  15. Floats, Figures and Captions
  16. Footnotes and Margin Notes
  17. Hyperlinks
  18. Labels and Cross-referencing
  19. Initials


  1. Errors and Warnings
  2. Lengths
  3. Counters
  4. Boxes
  5. Rules and Struts

Technical Text

  1. Mathematics
  2. Advanced Mathematics
  3. Theorems
  4. Chemical Graphics
  5. Algorithms
  6. Source Code Listings
  7. Linguistics

Special Pages

  1. Indexing
  2. Glossary
  3. Bibliography Management
  4. More Bibliographies

Special Documents

  1. Scientific Reports (Bachelor Report, Master Thesis, Dissertation)
  2. Letters
  3. Presentations
  4. Teacher's Corner
  5. Curriculum Vitae
  6. Academic Journals (MLA, APA, etc.)

Creating Graphics

  1. Introducing Procedural Graphics
  2. MetaPost
  3. Picture
  4. PGF/TikZ
  5. PSTricks
  6. Xy-pic
  7. Creating 3D graphics


  1. Macros
  2. Plain TeX
  3. Creating Packages
  4. Creating Package Documentation
  5. Themes


  1. Modular Documents
  2. Collaborative Writing of LaTeX Documents
  3. Export To Other Formats

Help and Recommendations

  1. FAQ
  2. Tips and Tricks


  1. Authors
  2. Links
  3. Package Reference
  4. Sample LaTeX documents
  5. Index
  6. Command Glossary

edit this boxedit the TOC

The picture environment allows programming pictures directly in LaTeX. On the one hand, there are rather severe constraints, as the slopes of line segments and the radii of circles are restricted to a narrow choice of values. On the other hand, the picture environment of LaTeX2e brings with it the \qbezier command, "q" meaning quadratic. Many frequently-used curves such as circles, ellipses, and catenaries can be satisfactorily approximated by quadratic Bézier curves, although this may require some mathematical toil. If a programming language like Java is used to generate \qbezier blocks of LaTeX input files, the picture environment becomes quite powerful.

Although programming pictures directly in LaTeX is severely restricted, and often rather tiresome, there are still reasons for doing so. The documents thus produced are "small" with respect to bytes, and there are no additional graphics files to be dragged along.

Packages like pict2e, epic, eepic or pstricks enhance the original picture environment, and greatly strengthen the graphical power of LaTeX.

Basic commands[edit | edit source]

A picture environment is available in any LaTeX distribution, without the need of loading any external package. This environment is created with one of the two commands

\begin{picture}(x, y)


\begin{picture}(x, y)(x0, y0)

The first pair, , affects the reservation, within the document, of rectangular space for the picture.

The optional second pair, , assigns arbitrary coordinates to the bottom left corner of the reserved rectangle.

The numbers x, y, x0, y0 are numbers (lengths) in the units of \unitlength, which can be reset any time (but not within a picture environment) with a command such as


The default value of \unitlength is 1pt.

Most drawing commands have one of the two forms

\put(x, y){object}


\multiput(x, y)(dx, dy){n}{object}

Bézier curves are an exception. They are drawn with the command

\qbezier(x1, y1)(x2, y2)(x3, y3)

With the package picture absolute dimension (like 15pt) and expression are allowed, in addition to numbers relative to \unitlength.

Line segments[edit | edit source]

Line segments are drawn with the command:

\put(x, y){ \line(x1, y1){length} }

The \line command has two arguments:

  1. a direction vector,
  2. a "length" (sort of: this argument is the vertical length in the case of a vertical line segment and in all other cases the horizontal distance of the line, rather than the length of the segment itself).

The components of the direction vector are restricted to the integers (−6, −5, ... , 5, 6) and they have to be coprime (no common divisor except 1). The figure below illustrates all 25 possible slope values in the first quadrant. The length is relative to \unitlength.


Arrows[edit | edit source]

Arrows are drawn with the command

\put(x, y){\vector(x1, y1){length}}

For arrows, the components of the direction vector are even more narrowly restricted than for line segments, namely to the integers (−4, −3, ... , 3, 4). Components also have to be coprime (no common divisor except 1). Notice the effect of the \thicklines command on the two arrows pointing to the upper left.


Circles[edit | edit source]

The command

\put(x, y){\circle{diameter}}

draws a circle with center (x, y) and diameter (not radius) specified by diameter. The picture environment only admits diameters up to approximately 14mm, and even below this limit, not all diameters are possible. The \circle* command produces disks (filled circles). As in the case of line segments, one may have to resort to additional packages, such as eepic, pstricks, or tikz.

\begin{picture}(60, 40)

There is another possibility within the picture environment. If one is not afraid of doing the necessary calculations (or leaving them to a program), arbitrary circles and ellipses can be patched together from quadratic Bézier curves. See Graphics in LaTeX2e for examples and Java source files.

Text and formulae[edit | edit source]

As this example shows, text and formulae can be written in the environment with the \put command in the usual way:

\put(3.5,0.4){$\displaystyle s:=\frac{a+b+c}{2}$}

\multiput and \linethickness[edit | edit source]

The command

\multiput(x, y)(dx, dy ){n}{object}

has 4 arguments: the starting point, the translation vector from one object to the next, the number of objects, and the object to be drawn. The \linethickness command applies to horizontal and vertical line segments, but neither to oblique line segments nor to circles. It does, however, apply to quadratic Bézier curves!


Ovals[edit | edit source]

The command

\put(x, y){\oval(w, h)}


\put(x, y){\oval(w, h)[position]}

produces an oval centered at (x, y) and having width w and height h. The optional position arguments b, t, l, r refer to "top", "bottom", "left", "right", and can be combined, as the example illustrates. Line thickness can be controlled by two kinds of commands: \linethickness{''length''} on the one hand, \thinlines and \thicklines on the other. While \linethickness{''length''} applies only to horizontal and vertical lines (and quadratic Bézier curves), \thinlines and \thicklines apply to oblique line segments as well as to circles and ovals.


Multiple use of predefined picture boxes[edit | edit source]

A picture box can be declared by the command


then defined by


and finally, arbitrarily often be drawn by

\put(x, y){\usebox{name}}

The optional position parameter has the effect of defining the "anchor point" of the savebox. In the example, it is set to "bl" which puts the anchor point into the bottom left corner of the savebox. The other position specifiers are top and right.

The name argument refers to a LaTeX storage bin and therefore is of a command nature (which accounts for the backslashes in the current example). Boxed pictures can be nested: In this example, \foldera is used within the definition of \folderb. The \oval command had to be used as the \line command does not work if the segment length is less than about 3 mm.

  (40,32)[bl]{% definition

  (40,32)[l]{% definition


Quadratic Bézier curves[edit | edit source]

The command

\qbezier(x1, y1)(x, y)(x2, y2)

draws a quadratic bezier curve where , denote the end points, and denotes the intermediate control point. The respective tangent slopes, and , can be obtained from the equations

See Graphics in LaTeX2e for a Java program which generates the necessary \qbezier command line.


As this example illustrates, splitting up a circle into 4 quadratic Bézier curves is not satisfactory. At least 8 are needed. The figure again shows the effect of the \linethickness command on horizontal or vertical lines, and of the \thinlines and the \thicklines commands on oblique line segments. It also shows that both kinds of commands affect quadratic Bézier curves, each command overriding all previous ones.

Catenary[edit | edit source]

\put( .3,.12763){\line(1,0){.4}}

In this figure, each symmetric half of the catenary is approximated by a quadratic Bézier curve. The right half of the curve ends in the point (2, 2.7622), the slope there having the value m = 3.6269. Using again equation (*), we can calculate the intermediate control points. They turn out to be (1.2384, 0) and (−1.2384, 0). The crosses indicate points of the real catenary. The error is barely noticeable, being less than one percent. This example points out the use of the optional argument of the \begin{picture} command. The picture is defined in a convenient "mathematical" coordinates, whereas by the command


its lower-left corner (marked by the black disk) is assigned the coordinates (−2.5,−0.25).

Plotting graphs[edit | edit source]


The control points of the two Bézier curves were calculated with formulas (*). The positive branch is determined by , and , . Again, the picture is defined in mathematically convenient coordinates, and the lower left corner is assigned the mathematical coordinates (−3,−2) (black disk).

The picture environment and gnuplot[edit | edit source]

The powerful scientific plotting package gnuplot has the capability to output directly to a LaTeX picture environment. It is often far more convenient to plot directly to LaTeX, since this saves having to deal with potentially troublesome postscript files. Plotting scientific data (or, indeed, mathematical figures) this way gives much greater control, and of course typesetting ability, than is available from other means (such as postscript). Such pictures can then be added to a document by an \include{} command.

N.B. gnuplot is a powerful piece of software with a vast array of commands. A full discussion of gnuplot lies beyond the scope of this note. See [1] for a tutorial.

Previous: MetaPost Index Next: PGF/TikZ