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
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
Bartman
Posts: 366
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