Graphics in LaTeX. Part I

Good time of day! Recently noticed palenie on habrahabr blog devoted to LaTeX. And decided to share the little knowledge that I have.
I will not repeat and describe what is LaTeX, why is it needed and how to install packages. This is already a lot written, including on this blog, but you and without me know it all. Here I decided to describe how to use the graphics capabilities of Latex and, as she had recently prepared the subject for the University. Material quite a lot, so I had to break apart. In this part I will tell you:
the

    what is pseudorank, the

  • how to use the package XY-pic.

So, in order.

Pseudorank


LaTeX, unlike TeX, allows the use of primitive drawings consisting of straight, oblique lines, arrows and circles.
For pseudorandom use the environment {picture}:
\begin{picture}(110,50)
...
\end{picture}

In brackets specifies the size of the canvas — width and height (remember that the default sizes are measured in points, you can change the preamble of the document with \unitlength).
To put something on the canvas, use the command \put(x,y){<object>}. (x,y) — object's coordinates (origin lower left corner of the canvas!) In curly brackets the object that you want to apply. Possible objects:
the

    Inscription. Any text, e.g. \put(10,15){Example text}

    Line. Example: \line(1,-2){20}. Here 1/-2 — angle coefficient of the segment, 20 — length of the projection on the x-axis.

    Arrow. Arrow is set with the command \vector. The parameters are the same as that of the line.

    Circle. Command: \circle{<radius>}.

    Circle. Command: \circle*{<radius>}.

    the Oval — a rectangle with rounded edges: \oval(<width>,<height>).

    Bezier Curves. Example: \qbezier(22,2)(120,20)(20,77) — in parentheses the coordinates of the control points.


To duplicate objects is to use the command \multiput(x, y)(dx,dy){n}{<object>}. Here (x, y) — the coordinates of the first object, (dx,dy) — coordinate, n — the number of objects. A small example:
\begin{picture}(100,80)
\multiput(10,70)(8,-6){8}%
{\circle*{3}}
\end{picture}

By the way, the percent sign is needed for the newline — setting picture does not allow empty lines, i.e. either the entire code must go in one line, or at the end of each is a percentage.

XY-pic


XY-pic is a package for creating graphs and charts. Graphs are constructed in the form of a matrix, where each matrix element corresponds to a vertex in the graph. Edges of the graph are built using special commands.

Connect package XY-pic

In the preamble of document write
\input xy
\xyoption{all}

or
\usepackage[all]{xy}.


Build count

Use the command \xymatrix{ ... }. Within the environment described by the matrix. The matrix elements in the string separated by "&". Line separated by "\\". Example:
\xymatrix{ U \ar@/_/[ddr]_y \ar@/^/[drr]^x
\ar@{.>}[dr]|-{(x,y)} \\
&X \times_Z Y \ar[d]^q \ar[r]_p
&X \ar[d]_f \\
&Y \ar[r]^g &Z }

The example shows that arrows are constructed with \ar. The team has a lot of modifications:
the
    the
  • In the square brackets you can specify the direction of the arrow \ar[hop]. The options u, d, l, r, ur, ul, dl, dr, drr, and so on. Example: \ar[ur]
  • the
  • you Can specify the arrow style — \ar@style[hop]. Some of the options: @{=>}, @{.>}, @{:>}, @{~>}, @{-->}, @{-}, @{}. Please do not confuse with smiles))
  • the
  • Arcs: @/^/, @/_/, @/_1pc/, etc.

A few examples:
$\xymatrix{ {\bullet} \ar@{-}[r] &{\bullet} \ar@{.}[d] \\
{\bullet} \ar@{--}[u] &{\bullet} \ar@{- > } [l] \ar@{=}[ul] }$

$\xymatrix@1{ A \ar[r]^f \ar[dr]_{f;g} &B \ar[d]^g \ar[dr]^{g;h} \\
&C \ar[r]_h &D }$

$\xymatrix{
A \ar[d]_f \ar[r]^f &B \ar[d]^g \ar[dl]|{iB} \\
B \ar[r]_g &C }$

$\xymatrix{ x \ar@(ul,dl)[]|{id} \ar@/^/[rr]|f && f(x)
\ar@/^/[ll]|{f^{-1}} } $

$\xymatrix{ 1 \ar[rr] ^-{1000000x}
\ar[dr]_(.2){2000x}|!{[d];[rr]}\hole
&& 1000000 \\
1000 \ar[r] _{2x} \ar[urr] _>>>>{x^2} &2000 }$

Useful books:
    the
  1. S. M. Lvov: "LaTeX system"
  2. the
  3. Tobias Oetiker, Hubert Partl, Irene Hyna and Elisabeth Schlegl: "a Not very short introduction to LaTeX2e" Translation: B. Tobotras
  4. the
  5. Vladimir Syutkin: "Russian language in LaTeX2e"
  6. Kristoffer H. Rose: "XY-pic User's Guide" the

  7. M. Goossens, F. Mittelbach, A. Samarin: "a Guide to LaTeX package and its extension LaTeX2e"
  8. the
  9. I. Kotelnikov, P. Chebotaev: "LaTeX2e in Russian"

That's all. Thank you for your attention.
The original article here: alex.kotomanov.com/2009/01/11/graph_in_latex
P. S. In the next part you will learn
the
    the
  • how to import bitmap and vector graphics
  • the
  • how to make colored documents
  • the
  • and finally, a little about hypertext in the pdf.
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

Templates ESKD and GOST 7.32 for Lyx 1.6.x

Monitoring PostgreSQL + php-fpm + nginx + disk using Zabbix

Custom table in MODx Revolution