latex - Draw pictures in Latex - latex tutorial
How to draw pictures in Latex
- The package pgf/tikz can be used to generate beautiful graphics, specially diagrams in LaTeX.
- It Allows you to create vector graphics from within your document, without the need of external tools such as Inkscape or Adobe Illustrator and thus is much more flexible.
- But unlike the graphical editors, we don't actually draw, but program the vector graphics using predefined macros.
Sample code:
Output
learn latex tutorial - latex tikz - latex example
- We usually want to embed our tikzpicture in a figure environment.\
- By using the \draw command, we can add elements. It's necessary to specifiy options in brackets and the coordinates of the element.
Syntax of Tikz
To prove the basic syntax, we will have a closer look at the line that draws the red rectangle in our picture:
latex pictures tikz :
learn latex - latex tutorial - latex pictures tikz - latex example programs
- The options here indicate that the rectangle should be red and dashed, no magic here.
- Then we define the location of our rectangle (-2.5,2.5) in cartesian coordinates
- To set the size of the rectangle, we simply add a second pair of coordinates behind our rectangle statement. (-1.5,1.5).
- You can see, there is also a text below our rectangle.
- Text is usually placed as a so-called node (text-node) in our picture.
- We define the text to have black color and set the position to below our rectangle.
- Tikz can usually figure out the size of the rectangle automatically.
- Other than in plain LaTeX we have to terminate each command with a semicolon inside of the tikzpicture environment.
The next snippet shows how to draw a line by specifying a path in Tikz:
- The syntax is the same as for the rectangle, we only use a different command in between the coordinates.
- The to command is used to specify a point of the path. Tikz usually draws straight lines between the points, in the picture below we can clearly see the lines are bent.
- This can be accomplished by setting the in and out angle in brackets.
- There are many more options available and mastering tikz can take a vast amount of time.
- To accomplish basic drawings very fast and they integrate very smoothly with the rest of your document.
- There are also many extensions for tikz, which provide easy ways to create diagrams, flowcharts, mindmaps and many more.
latex graphics :
learn latex - latex tutorial - latex graphics - latex example programs