Good time of day! Recently noticed a blog post on Habré blog dedicated to the system LaTeX. And I decided to share the little knowledge that I have.
I will not repeat and describe what LaTeX is, why it is needed and how to install packages. Much has already been written about this, including in this blog, and you know all this without me. Here I decided to describe how to use the graphic capabilities of LaTeX, since I recently prepared this topic for the university. There is a lot of material, so I had to break it apart. In this part I will tell:
- what is a pseudowistory,
- how to use the package xy-pic.
So, in order.
Psevdoreniski
LaTeX, in contrast to TeX, allows the use of primitive drawings, consisting of straight, slanting lines, arrows and circles.
For pseudo-shooters, use the
{picture}
environment:
\begin{picture}(110,50)
...
\end{picture}
The size of the canvas is set in brackets - width, height (I remind you that by default dimensions are measured in points, you can change it in the document preamble with the command
\unitlength
).
To put something on the canvas, use the
\put(x,y){<>}
command.
(x,y)
- the coordinates of the object (the origin of the coordinates is the lower left corner of the canvas!) In curly brackets, the object to be drawn. Possible objects:
- The inscription. Any text, for example,
\put(10,15){ }
- Line. Example:
\line(1,-2){20}
. Here, 1 / -2 is the angular coefficient of the segment, 20 is the length of the projection on the abscissa axis. - Arrow. The arrow is specified by the
\vector
command. The parameters are the same as the line. - Circle. The command:
\circle{<>}
. - A circle. The command:
\circle*{<>}
. - An oval is a rectangle with rounded edges:
\oval(<>,<>)
. - Bezier curves. Example:
\qbezier(22,2)(120,20)(20,77)
- in brackets the coordinates of reference points.
For duplicate objects it is convenient to use the command
\multiput(x, y)(dx,dy){n}{<>}
. Here
(x, y)
are the coordinates of the first object,
(dx,dy)
is the increment of coordinates,
n
is the number of objects. A little example:
\begin{picture}(100,80)
\multiput(10,70)(8,-6){8}%
{\circle*{3}}
\end{picture}
By the way, the percent sign is needed for a line break - the
picture
environment does not allow empty lines, i.e. either all the code should go in one line, or a percentage is put at the end of each one.
XY-pic
XY-pic is a package for creating graphs and charts. Graphs are constructed in the form of a matrix, where each element of the matrix corresponds to a vertex of the graph. The edges of the graph are constructed using special commands.
')
Connection package xy-pic
In the preamble of the document we write
\input xy
\xyoption{all}
or
\usepackage[all]{xy}
.
Graphing
Use the command
\xymatrix{ ... }
. The matrix is described inside the environment. Matrix elements in the row are separated by the symbol "
&
". Lines are 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 }
From the example it is clear that the arrows are built with the
\ar
command. The team has a lot of modifications:
- In square brackets you can specify the direction of the arrow -
\ar[hop]
. The options are u, d, l, r, ur, ul, dl, dr, drr, and so on. Example: \ar[ur]
- You can set the arrow style -
\ar@style[hop]
. Some options are: @{=>}
, @{.>}
, @{:>}
, @{~>}
, @{-->}
, @{-}
, @{}
. Please do not confuse with smiles)) - Above the arrows (or below them) you can place text or other objects. "
^
" - the label on the top, " _
" - from the bottom, " |
" - break the arrow. Example: $\xymatrix@1{ X\ar[r]^a_b & Y & Z\ar[l]^A_B }$
- 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:
- S.L. Lvovsky: “Work in the LaTeX system”
- Tobias Oetiker, Hubert Partl, Irene Hyna and Elisabeth Schlegl: “Not a Very Short Introduction to LaTeX2e” Translation: B. Tobotras
- Vladimir Syutkin: “Russian in LaTeX2e”
- Kristoffer H. Rose: "XY-pic User's Guide"
- M. Goossens, F. Mittelbach, A. Samarin: “Guide to the LaTeX package and its extension LaTeX2e”
- I. Kotelnikov, P. Chabotaev: “LaTeX2e in Russian”
This is all for now. Thanks for attention.
Original article here:
alex.kotomanov.com/2009/01/11/graph_in_latexPS In the next part you will learn
- how to import raster and vector graphics,
- how to make color documents
- and, finally, a little about hypertext in pdf.