Graphics, Figures & TablesCreating labeled (a, b, c, …) nodes with TikZ and foreach

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Howard87
Posts: 2
Joined: Thu Mar 06, 2014 3:35 pm

Creating labeled (a, b, c, …) nodes with TikZ and foreach

Post by Howard87 »

Hello everybody,

I'm trying to create a graph using TikZ with a foreach loop. I'd like to label the nodes with characters, but I'm unable to do so.

\def \n {5}
\foreach \s in {1,...,\n} {
\node[mynodestyle] (\s) at ({360/\n * (\s - 1)}:3) {$\s$};
}


(I've been inspired by http://www.texample.net/tikz/examples/cycle/.)

The nodes are named 1 to 5, but they should be named a to e instead. I could not find any chr(\s) function. The 5 is pretty much fixed, so a lookup/makro might also be appropriate.

Thank you for any hints.

Howard

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

Howard87
Posts: 2
Joined: Thu Mar 06, 2014 3:35 pm

Creating labeled (a, b, c, …) nodes with TikZ and foreach

Post by Howard87 »

Hm…

I now seem to having found a way to do it:

\def \n {5}
\foreach \x/\y in {1/a,2/b,3/c,4/d,5/e} {
\node[mynodestyle] (\y) at ({360/\n * (\x - 1)}:3) {$\y$};
}


At least I don't have to worry about node positioning any more.
Post Reply