⬆️ ⬇️

Graphics in LaTeX. Part I

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:



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:



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:



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:

  1. S.L. Lvovsky: “Work in the LaTeX system”
  2. Tobias Oetiker, Hubert Partl, Irene Hyna and Elisabeth Schlegl: “Not a Very Short Introduction to LaTeX2e” Translation: B. Tobotras
  3. Vladimir Syutkin: “Russian in LaTeX2e”
  4. Kristoffer H. Rose: "XY-pic User's Guide"
  5. M. Goossens, F. Mittelbach, A. Samarin: “Guide to the LaTeX package and its extension LaTeX2e”
  6. 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_latex

PS In the next part you will learn

Source: https://habr.com/ru/post/48099/



All Articles