Graphics, Figures & TablesTikz | Arrangement of nodes

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
phponline
Posts: 2
Joined: Wed Dec 19, 2012 2:40 pm

Tikz | Arrangement of nodes

Post by phponline »

Hi all,
I would like to arrange nodes in an area as an jusitified continuous text.
In my MWE you can see an jusitified continuous text and below the text some justified nodes. I would like to arrange the nodes without a minipage environment.
Is there a possibility to do that with a tikzpicture environment?


Additional it would be nice to arrange the nodes in the shape of a circle, too.
For example I would like to draw a bag and fill it with numbered nodes (like a bag of lottery balls).

Code: Select all

Code, edit and compile here:
\documentclass{minimal}
\usepackage[ngerman]{babel}
\usepackage{blindtext}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\blindtext \\
\begin{minipage}[t]{\textwidth}
\tikz[baseline=(n.base)]{\node [draw, ultra thick, fill=blue!20,ellipse] (n) {H};}
\tikz[baseline=(n.base)]{\node [draw, ultra thick, fill=blue!20,ellipse] (n) {He};}
\tikz[baseline=(n.base)]{\node [draw, ultra thick, fill=blue!20,ellipse] (n) {Hel};}
\tikz[baseline=(n.base)]{\node [draw, ultra thick, fill=blue!20,ellipse] (n) {Hell};}
\tikz[baseline=(n.base)]{\node [draw, ultra thick, fill=blue!20,ellipse] (n) {Hello};}
\tikz[baseline=(n.base)]{\node [draw, ultra thick, fill=blue!20,ellipse] (n) {Hello };}
\tikz[baseline=(n.base)]{\node [draw, ultra thick, fill=blue!20,ellipse] (n) {Hello W};}
\tikz[baseline=(n.base)]{\node [draw, ultra thick, fill=blue!20,ellipse] (n) {Hello Wo};}
\tikz[baseline=(n.base)]{\node [draw, ultra thick, fill=blue!20,ellipse] (n) {Hello Wor};}
\tikz[baseline=(n.base)]{\node [draw, ultra thick, fill=blue!20,ellipse] (n) {Hello Worl};}
\tikz[baseline=(n.base)]{\node [draw, ultra thick, fill=blue!20,ellipse] (n) {Hello World};}
\tikz[baseline=(n.base)]{\node [draw, ultra thick, fill=blue!20,ellipse] (n) {Hello World!};}
\tikz[baseline=(n.base)]{\node [draw, ultra thick, fill=blue!20,ellipse] (n) {Hello World! Hello World!};}
\tikz[baseline=(n.base)]{\node [draw, ultra thick, fill=blue!20,ellipse] (n) {Hello World! Hello World! Hello World!};}
\tikz[baseline=(n.base)]{\node [draw, ultra thick, fill=blue!20,ellipse] (n) {Hello World! Hello World! Hello World! Hello World!};}
\end{minipage}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

Tikz | Arrangement of nodes

Post by Stefan Kottwitz »

Hi,

welcome to the board!

The minipage is already a nice solution I think. Other solutions would also include some code.

Regarding node arrangements in circles, you could use polar coordinates for drawing. Have a look at this TikZ cycle example by Jerome Tremblay:

Code: Select all

Code, edit and compile here:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\def \n {5}
\def \radius {3cm}
\def \margin {8} % margin in angles, depends on the radius
\foreach \s in {1,...,\n}
{
\node[draw, circle] at ({360/\n * (\s - 1)}:\radius) {$\s$};
\draw[->, >=latex] ({360/\n * (\s - 1)+\margin}:\radius)
arc ({360/\n * (\s - 1)+\margin}:{360/\n * (\s)-\margin}:\radius);
}
\end{tikzpicture}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
cycle.png
cycle.png (4.73 KiB) Viewed 8570 times
Stefan
LaTeX.org admin
phponline
Posts: 2
Joined: Wed Dec 19, 2012 2:40 pm

Tikz | Arrangement of nodes

Post by phponline »

Thank you for your quick reply.

But "Additional it would be nice to arrange the nodes in the shape of a circle, too." meant that I would like to arrange the nodes 1-9 in the inner of a shape of a circle as you can see in the following MWE.
The space between shape and first node and between last node and shape should be equal and that for each row.

In the second row of nodes in the MWE you can see that space is needed in this row for this condition.
It would be really nice if I can give a macro the nodes and the shape and the macro does what I have done manually in the MWE.

Code of the MWE:

Code: Select all

Code, edit and compile here:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning, calc}
\begin{document}
\begin{tikzpicture}
\draw[thick] (0cm,0cm) circle(4.5);
\tikzstyle{every node} = [draw, thick, circle, anchor=west];
\node[anchor=center] (n1) at (-1.95,3.5) {1};
\node (n2) at (n1.east) {2};
\node (n3) at (n2.east) {3};
\node (n4) at (n3.east) {4};
\node (n5) at (n4.east) {5};
\node (n6) at (n5.east) {6};
\node (n7) at (n6.east) {7};
\node[xshift=-9, yshift=-6, anchor=north east] (n8) at (n1.south west) {8};
\node[xshift=1] (n9) at (n8.east) {9};
\node[xshift=1] (n10) at (n9.east) {0};
\node[xshift=1] (n11) at (n10.east) {1};
\node[xshift=1] (n12) at (n11.east) {2};
\node[xshift=1] (n13) at (n12.east) {3};
\node[xshift=1] (n14) at (n13.east) {4};
\node[xshift=1] (n15) at (n14.east) {5};
\node[xshift=1] (n16) at (n15.east) {6};
\node[xshift=-2, yshift=-6, anchor=north east] (n17) at (n8.south west) {7};
\node (n18) at (n17.east) {8};
\node (n19) at (n18.east) {9};
\node (n20) at (n19.east) {0};
\node (n21) at (n20.east) {1};
\node (n22) at (n21.east) {2};
\node (n23) at (n22.east) {3};
\node (n24) at (n23.east) {4};
\node (n25) at (n24.east) {5};
\node (n26) at (n25.east) {6};
\node (n27) at (n26.east) {7};
\end{tikzpicture}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
User avatar
Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

Tikz | Arrangement of nodes

Post by Stefan Kottwitz »

You could make a (double) \foreach loop, running over x any y coordinates with (diameter) step, which would place nodes in a quadratic grid. Set the node only if the condition is met that the distance to the circle center is less than the radius (minus the small radius).

Stefan
LaTeX.org admin
Post Reply