Graphics in LaTeX. Part I
Good time of day! Recently noticed an update on the Habré blog devoted to the LaTeX system. And I decided to share the little knowledge that I have.
I will not repeat myself and describe what LaTeX is, why it is needed and how to install packages. Much has already been written about this, including on this blog, and you know all this without me. Here I decided to describe how to use the graphics capabilities of LaTeX, as I recently prepared this topic for the university. There is a lot of material, so I had to break it into pieces. In this part I will tell:
So, in order.
LaTeX, unlike TeX, allows you to use primitive drawings consisting of straight, oblique lines, arrows and circles.
For pseudo-drawings we use the environment
In brackets, the canvas size is set - width, height (I remind you that by default sizes are measured in points, you can change the command in the document preamble
To put something on the canvas, use the command
For repeating objects, it’s convenient to use the command
By the way, the percent sign is needed for line breaks - the environment
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 the top of the graph. The edges of the graph are built using special commands.
In the preamble of the document we write
or
We use the command
The example shows that the arrows are built by the team
A few examples:
Useful books:
That is all for now. Thanks for attention.
The original article is here: alex.kotomanov.com/2009/01/11/graph_in_latex
PS In the next part you will learn
I will not repeat myself and describe what LaTeX is, why it is needed and how to install packages. Much has already been written about this, including on this blog, and you know all this without me. Here I decided to describe how to use the graphics capabilities of LaTeX, as I recently prepared this topic for the university. There is a lot of material, so I had to break it into pieces. In this part I will tell:
- what are pseudo-drawings,
- how to use the XY-pic package.
So, in order.
Pseudo-drawings
LaTeX, unlike TeX, allows you to use primitive drawings consisting of straight, oblique lines, arrows and circles.
For pseudo-drawings we use the environment
{picture}:\begin{picture}(110,50)
...
\end{picture}
In brackets, the canvas size is set - width, height (I remind you that by default sizes are measured in points, you can change the command in the document preamble
\unitlength). To put something on the canvas, use the command
\put(x,y){<объект>}. (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 applied. Possible objects:- 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 onto the abscissa axis. - Arrow. The arrow is set by the command
\vector. The parameters are the same as the line. - Circle. Team:
\circle{<радиус>}. - A circle. Team:
\circle*{<радиус>}. - Oval - a rectangle with rounded corners:
\oval(<ширина>,<высота>). - Bezier curves. Example:
\qbezier(22,2)(120,20)(20,77)- in brackets the coordinates of control points.
For repeating objects, it’s convenient to use the command
\multiput(x, y)(dx,dy){n}{<объект>}. Here (x, y)- the coordinates of the first object, (dx,dy)- the increment of coordinates, 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 line breaks - the environment
picturedoes not allow empty lines, i.e. either the whole code should go in one line, or at the end of each one a percentage is put.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 the top of the graph. The edges of the graph are built using special commands.
Connection of the XY-pic package
In the preamble of the document we write
\input xy
\xyoption{all}
or
\usepackage[all]{xy}.Graph construction
We use the command
\xymatrix{ ... }. Inside the environment, a matrix is described. Matrix elements in a row are separated by a " &". 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 }The example shows that the arrows are built by the team
\ar. The team has many modifications:- In square brackets, you can specify the direction of the arrow -
\ar[hop]. Options are u, d, l, r, ur, ul, dl, dr, drr and so on. Example:\ar[ur] - You can specify the arrow style
\ar@style[hop]. Some options are:@{=>},@{.>},@{:>},@{~>},@{-->},@{-},@{}. Please do not confuse with smiles)) - Above (or below) arrows, you can place text or other objects. "
^" - label above, "_" - below, "|" - will break the arrow. Example:$\xymatrix@1{ X\ar[r]^a_b & Y & Z\ar[l]^A_B }$ - Dougie:
@/^/,@/_/,@/_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. M. 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. Gussens, F. Mittelbach, A. Samarin: “A Guide to the LaTeX Package and Its LaTeX2e Extension”
- I. Kotelnikov, P. Chabotaev: “LaTeX2e in Russian”
That is all for now. Thanks for attention.
The original article is here: alex.kotomanov.com/2009/01/11/graph_in_latex
PS In the next part you will learn
- how to import raster and vector graphics,
- how to make color documents
- and, finally, a little about pdf hypertext.