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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

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