Diagrams in LaTeX

The advantages of using LaTeX it has been repeatedly discussed. As well as the ways create presentations using beamer and vector graphics from the package PGF/Tikz. But is it possible to get graphs in LaTeX, not inferior in appearance obtained in large and complex packages? One of the ways suggested below.
the
Beginning
To begin with, we'll need LaTeX (for Windows fit MiKTeX, for Linux or Mac TeXlive), and packages beamer and tikz. Both are supplied with MiKTeX. Download the latest version either from the project page or from CTAN. You will also need basic knowledge about LaTeX, and the use of these packages. Since beamer is focused on using pdflatex will be used in the PDF.
the
Simple chart
Try to make a small and simple chart. As example, take the serial format conversion when working in LaTeX:
\usepackage{tikz}
\usetikzlibrary{positioning,arrows}<br>
it Should be noted that when listing the names of libraries separated by commas spaces are not allowed. This is because tikz substitutes the string as part of file name with the library.In the add document surrounded by tikzpicture, inside of which lists the commands tikz. Each command must end with a semicolon. Commands can be nested, for example to create arrows with the signature or child elements. The General syntax is:
\command [parameters] (name) {contents} the arguments;
where -
the
- command — the actual command; the
- parameters — the command parameters separated by a comma; the
- name — the name of the object being created; the
- contents — the contents of the object (can include other objects); the
- arguments — arguments, such as point or size, and other teams (but without backslash).
The command \path creates a "loop" in the terminology of vector graphics. As a parameter to specify what should be done with this loop:
-
the
- draw — only to draw the outline; the
- fill — just pour; the
- fill,draw, — to draw the outline and fill; the
- use as bounding box — use the outline as a size limit for pictures.
As arguments are passed the coordinates through which the contour should pass. In tikz there are many variants of the task coordinate:
-
the
- relative coordinates (1,5); the
- real on the sheet, in all formats LaTeX (10pt, 3mm); the
- relative to the previous point ++(0,1); the
- relative to the starting point +(-1,2); the
- relative to the named object, (name).
\path (foo) edge (bar);<br>
The command \node creates a node (or object), usually with some text. Its parameters can be text style, color, information about the presence, form and color shape location relative to other objects, and many others. To place the node at a particular location with the coordinates of (x, y) using the argument at (x, y). But the most interesting is the location in relation to other objects provided by the library positioning. To use it, simply specify in settings in which direction relative to another object must be given. For example,
\node (foo) {foo};<br>
\node[right of=foo] (bar) {bar};<br>
More detailed information is available in the documentation. The above is enough to create first simple chart. It should be 4 objects, and 3 arrows between them. The implementation looks like this
\node (tex) {.tex};<br>
\node[right of=tex] (dvi) {.dvi};<br>
\node[right of=dvi] (ps) {.ps};<br>
\node[right of=ps] (pdf) {.pdf};<br>
<br>
\path[->] (tex) edge (dvi);<br>
\path[->] (dvi) edge (ps);<br>
\path[->] (ps) edge (pdf);<br>

the
perfect graph
The first picture we've got, but she did not look: offset a line of text, no frames around the text too close to one another. And it is beautiful images with gradients and transparency? The chart definitely needs to be improved and we will use for this assignment styles. The style is set with the command
\tikzstyle{name} = [, parameters]
the name of the style can then be passed as a parameter to another command. For further work we also need to connect the library shapes and shadows. A good figure for text will be a rectangle with rounded edges, which is available in the library. For it will also need to describe the background and the outline. Before you do, let's deal with ways to specify colors in tikz.Color can be called from predefined in LaTeX and xcolor package. You can also define your own RGB color by using the command
\definecolor{name}{rgb}{0.5,0.5,0.5}
comma-separated specified RGB components and their quantity from 0 to 1. Or other systems, which you can read more in the documentation of the xcolor package. Also the predefined colors can be mixed. The syntax for this operation is:color1!percent!color2
the result is a color with percent% of the first color and (100-percent)% of the second. If the second is not given, the default is white. Mixing colors can be repeated without saving the intermediate color, for exampleFirst, you will receive a color of 50% red and 50% black, then the result is mixed with 50% white. In the result of red and black colors will be 25%.
Now you can go directly to the mission style
\tikzstyle{format} = [rounded rectangle,<br>
thick<br>
minimum size=1cm<br>
draw=red!50!black!50,<br>
top color=white,<br>
bottom color=red!50!black!20,<br>
font=\itshape<br>
drop shadow]<br>
This style instructs to draw a rectangle with rounded edges, thick line of the contour color with the red!50!black!50, fill it using a gradient down from white to the red!50!black!20, with shadow, inner text should be typed in italic.Next we want to align the baseline of the text. To do this, first understand why it was shifted. The words "tex", "ps" and "pdf" are of different heights, and therefore had been centered inside the object. So explicitly specify the text height should solve the issue.
Environment tikzpicture also allows you to specify options that apply to all commands inside this environment. Use this and set it the thickness of the communication line, the minimum distance between the objects and the height of the text.
\begin{tikzpicture}[thick, and<br>
node distance=2cm,<br>
text height=1.5 ex,<br>
text depth=.25ex]<br>
\node[format] (tex) {.tex};<br>
\node[format,right of=tex] (dvi) {.dvi};<br>
\node[format,right of=dvi] (ps) {.ps};<br>
\node[format,right of=ps] (pdf) {.pdf};<br>
<br>
\path[->] (tex) edge (dvi);<br>
\path[->] (dvi) edge (ps);<br>
\path[->] (ps) edge (pdf);<br>
\end{tikzpicture}<br>

the
more advanced
Now, when we received an acceptable option simple chart let's try to complicate the task. Add to this diagram the methods of data representation (screen and print) and the possibility of conversion without intermediate formats. As lines on the chart a lot, it is worth to sign them.
Define the different style of the node for a representation of the data. Let it be an ellipse with a blue gradient from top to bottom, dark blue outline and shadow. Description of style will be similar to the previous one.
\tikzstyle{format} = [ellipse,<br>
thick<br>
minimum size=1cm<br>
draw=blue!50!black!50,<br>
top color=white,<br>
bottom color=blue!50!black!20,<br>
drop shadow]<br>
But when you add additional lines, another problem arises. If you set the path from (tex) to (pdf) tikz by default it will hold a straight line that absolutely does not suit us. Unfortunately, use of the graphviz package is not able, so will have to describe the path around the elements. For this, we use the relative assignment paths.
\path[-> draw] (dvi) -- ++(0,1) -- ++(3,0) -- (pdf);<br>
the First circuit starts from the node, (tex) and raise it to 2 relative units up. And then proceeds to the right before the formation of the perpendicular to (pdf) and goes to him. The second circuit starts from the node, (dvi) rises by 1 unit, goes to the right by 3 units relative to the previous point, and for a direct routed to the node, (pdf). To add labels to the contours use nested commands and add a node to a path
\path[-> draw] (tex) -- +(0,2) -| node[start near] {pdf\LaTeX} (pdf);<br>
But this command will add an object so that the centers of loop and node coincide. The text will be crossed out line. To avoid this surrounded by tikzpicture specify the setting for automatic positioning of signatures auto. Now our chart will look like
\begin{tikzpicture}[thick, and<br>
node distance=3cm,<br>
text height=1.5 ex,<br>
text depth=.25ex,<br>
auto]<br>
\node[format] (tex) {.tex};<br>
\node[format,right of=tex] (dvi) {.dvi};<br>
\node[format,right of=dvi] (ps) {.ps};<br>
\node[format,right of=ps] (pdf) {.pdf};<br>
\node[medium,below of=dvi] (screen) {screen};<br>
\node[medium,below of=ps] (verbatim) {verbatim};<br>
<br>
\path[->] (tex) edge node {\LaTeX} (dvi);<br>
\path[->] (dvi) edge node {dvips}(ps);<br>
\path[->] (ps) edge node {ps2pdf} (pdf);<br>
\path[->] (dvi) edge node {xdvi} (screen);<br>
\path[->] (ps) edge node[start near] {gs} (screen);<br>
\path[->] (pdf) edge (screen);<br>
\path[->] (ps) edge node {print} (verbatim);<br>
\path[->] (pdf) edge (verbatim);<br>
\path[-> draw] (tex) -- +(0,2) -| node[start near] {pdf\LaTeX} (pdf);<br>
\path[-> draw] (dvi) -- ++(0,1) -- node[start near] {dvipdf} ++(3,0) -- (pdf);<br>
\end{tikzpicture}<br>

the
Use in presentations
The resulting chart can be used as a static picture in the article or the description. But for presentation, it is often required that the diagram objects appear in a certain order. In LaTeX presentation beamer package is used. His work is built around the concept of overlays — different views of the same slide. About using beamer wrote, so remember about the specification of overlays. You can add them to almost any command in LaTeX, and tikz commands are no exception. Therefore, any illustrations obtained with the help of this pack is easily divided into parts and integrated with the beamer. However, now the commands are not very convenient to add overlays. If you need to at the same time appeared the object and its connection with already existing, will have to add specifications to each team. It would be logical to place commands in sequence at the time of appearance on the slide. Here comes to the aid the ability to group teams, which was mentioned in the beginning. In the \path you can specify the nodes that it will connect. So we can do one command for each overlay.
\frametitle{\LaTeX workflow}<br>
\begin{tikzpicture}[thick, and<br>
node distance=3cm,<br>
text height=1.5 ex,<br>
text depth=.25ex,<br>
auto]<br>
<br>
\path[use as bounding box] (-1,0) rectangle (10,-2);<br>
\path[->]<1-> node[filename] (tex) {.tex};<br>
\path[->]<2-> node[filename, right of=tex] (dvi) {.dvi}<br>
(tex) edge node {\LaTeX} (dvi);<br>
\path[->]<3-> node[display, below of=dvi] (screen) {screen}<br>
(dvi) edge node {xdvi} (screen);<br>
\path[->]<4-> node[filename, right of=dvi] (ps) {.ps}<br>
(dvi) edge node {dvips} (ps);<br>
\path[->]<5-> (ps) edge node {gs} (screen);<br>
\path[->]<6-> node[display, below of=ps] (verbatim) {verbatim}<br>
(ps) edge node {print} (verbatim);<br>
\path[->]<7-> node[filename, right of=ps] (pdf) {.pdf}<br>
(ps) edge node {ps2pdf} (pdf);<br>
\path[->]<8-> (pdf) edge (screen)<br>
edge (verbatim);<br>
\path[-> draw]<9-> (tex) -- +(0,2) -| node[start near] {pdf\LaTeX} (pdf);<br>
\path[-> draw]<10-> (dvi) -- ++(0,1) -- node[start near] {dvipdf} ++(3,0) -- (pdf);<br>
\end{tikzpicture}<br>
\end{frame}<br>
What was the result you can see sdes.
_________
When preparing used
PGF/Tikz manual
Xcolor manual
Beamer manual
The TeX workflow example
Комментарии
Отправить комментарий