Graphics, Figures & TablesMake a list of lines with a list of labels

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
tush
Posts: 11
Joined: Fri Feb 22, 2019 2:54 pm

Make a list of lines with a list of labels

Post by tush »

I am looking for a way to compactly create the following list of lines and text nodes:

Code: Select all

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (-0.2,0) node[left]{Text 1} -- (+0.2,0);
\draw (-0.2,2) node[left]{Second Text} -- (+0.2,2);
\draw (-0.2,3) node[left]{3rd text node} -- (+0.2,3);
\end{tikzpicture}
\end{document}
I am familiar a bit with`\foreach`, which can give me the following:

Code: Select all

\foreach \y in {0,2,3}
\draw(-0.2,\y) -- (+0.2,\y);
But how do I use something more like a list of

Code: Select all

{{x1,label1},{x2,label2},{x3,label3},..}
(So as in the case above it would be

Code: Select all

{{0,Text 1},{2,Second Text},{3,3rd text node},..}
)

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

Bartman
Posts: 369
Joined: Fri Jan 03, 2020 2:39 pm

Make a list of lines with a list of labels

Post by Bartman »

You may want to use multiple variables as explained in section 88 "Repeating Things: The Foreach Statement".
Post Reply