Draw Overlapping Circles Tikz Latex
TikZ/PGF is a flexible and powerful bundle for creating graphics in LaTeX. It's syntax tin can exist somewhat overwhelming at the first. In this postal service I prove the basics of tree drawing using TikZ and LuaLaTeX.
The following code but works with LuaLaTeX. Brand sure you utilize the lualatex engine rather than standard tex/latex for typesetting.
Setup
Starting time, nosotros load TikZ and it'south graphdrawing.copse
library in the document preamble:
\usepackage{tikz} \usetikzlibrary{graphdrawing.copse}
In the document body, we prepare the figure surroundings. Here, we set nodes to be circles and edges to be directed vertices using the default pointer head.
\begin{tikzpicture}[nodes={draw, circumvolve}, ->] % Tree construction \cease{tikzpicture}
With that, we are ready to start drawing trees.
Tree drawing syntax
We start with a root node r
which has two children, node a
and node b
.
\node{r} child { node {a} } kid { node {b} };
The library implements an algorithm which handles the distribution of children under each parent node. Therefore, nosotros don't have to worry virtually the placement of nodes in the tree.
Next, we might want to add extra levels, for example by adding three children under the child node a
.
This is not really complicated, we just take to make sure that we place children of node a
inside the child node.
\node{r} child { node {a} child { node {c} } child { node {d} } child { node {e} } } child { node {b} };
Obviously, there is not enough infinite to add another three children to node b
. As a consequence, kid nodes would overlap. However, this can be fixed by calculation actress missing nodes and therefore increment the angle between child nodes. I will show how to do that in a moment.
Missing nodes
Missing nodes do just what they say, they add space for missing nodes. In the example below, node b
from the previous example was replaced by a missing node. Therefore, node a
is slightly shifted towards the left, leaving space for the 'missing' child node.
\node{r} child { node {a} child { node {c} } child { node {d} } } child [ missing ];
Using the concept of missing nodes, we can now add together extra children to node b
, whereby we omit overlap with children of node a
.
\node{r} child { node {a} child { node {c} } kid { node {d} } child { node {e} } } kid [missing] child [missing] child {node {b} child { node {c} } child { node {d} } child { node {eastward} } };
Directed and undirected edges
TikZ supports different types of edges. For trees, the following are frequently used types of edges:
-> % Directed edge <- % Contrary directed edge -- % Undirected border <-> % Bi-directed edge
We previously saw how to globally prepare the direction of edges. We tin locally change the direction of a specific vertex using the edge
keyword. In the example below, we change edge a
to a bi-directed edge.
\begin{tikzpicture}[nodes={draw, circle}, ->] \node{r} kid { node {a} edge from parent [<->] } child { node {b} }; \cease{tikzpicture}
Node size and line thickness
The size of a node changes, depending on its content/text. The minimum size
imposes a minimal size on each node. By adjusting the value depending on the longest text/largest node size, we tin ensure that all nodes accept roughly the aforementioned size.
\begin{tikzpicture}[nodes={draw, circle}, minimum size=1cm]
Nosotros can further arrange the line thickness using the keywords thick
or very thick
.
\begin{tikzpicture}[nodes={describe, circle}, thick]
In the example below, I increased the line thickness to thick
and changed nodes to a minimum size of 0.7cm
. Equally you can encounter, all nodes are of the same size now. Whereas earlier, node b
was slightly bigger due to the size of the character.
Further options
Below are a few more options that might be useful to improve the advent of the tree.
Irresolute the level distance (parent to child):
\begin{tikzpicture}[nodes={draw,circle}, level distance=2cm]
Changing the sibling distance (child to kid):
\begin{tikzpicture}[nodes={draw,circle}, sibling altitude=1cm]
Using rectangular rather than circular nodes:
\brainstorm{tikzpicture}[nodes={depict,rectangle}]
Colored nodes:
\begin{tikzpicture}[nodes={draw,circle,fill up=bluish!20}]
Tree layout and graph syntax
The TikZ tree layout
and graph
syntax make tree building fifty-fifty easier. Instead of kid
and node
keywords, curly brackets are used to point dependencies (edges). Siblings are separated past a comma and missing nodes are created by an empty node.
Here is the example from above in graph
syntax:
\documentclass{commodity} \usepackage{tikz} \usetikzlibrary{graphs} \usetikzlibrary{graphdrawing} \usegdlibrary{copse} \begin{document} \tikz[tree layout]\graph[nodes={draw, circle}] { r -> { a -> { c, d }, % b missing } }; \cease{certificate}
Using graph
syntax, nosotros can change the direction of the tree. For case grow=0
lets the tree abound to the right rather than downwards.
\tikz[tree layout, grow=0]\graph[nodes={draw, circle}] { r -> { a -> { c, d }, % b missing } }; \terminate{document}
For more details, please consider reading the documentation (folio 405+) or drop me a annotate beneath.
dinardocasere1951.blogspot.com
Source: https://texblog.org/2015/09/16/drawing-trees-with-tikzpgf-and-lualatex/
0 Response to "Draw Overlapping Circles Tikz Latex"
Post a Comment