1

In TikZ & PGF Manual for Version 2.10-cvs, page 676/880 there is an example as below:

\foreach \x / \y in {1/2,a/b} {``\x\ and \y''}

It is supposed to yield: "1 and 2""a and b". But for me it gives me nothing only a blank page. Do you know the reason?

7
  • Did you put the \foreach in a tikzpicture?
    – Symbol 1
    Jul 9, 2020 at 4:19
  • Yes I did that.
    – Aria
    Jul 9, 2020 at 4:19
  • 3
    The reason is that {``\x\ and \y''} is not a valid tikzpicture draw command, so it yields nothing. You will get the expected output if using it outside the tikzpicture environment.
    – Ukiyo-E
    Jul 9, 2020 at 4:50
  • Thank you so much!
    – Aria
    Jul 9, 2020 at 5:12
  • 2
    Recent TikZ and PGF manual is for version 3.1.5b and this example is on page 1002 :-). It works outside ikzpicture, as @Amita mentioned in her/his comment. As example of MWE: \documentclass{article} \usepackage{tikz} \usepackage[active,tightpage]{preview} \setlength\PreviewBorder{1em} \begin{document} \begin{preview} \foreach \x / \y in {1/2,a/b} {``\x\ and \y''} \end{preview} \end{document}
    – Zarko
    Jul 9, 2020 at 5:13

2 Answers 2

2

The reason is that {``\x\ and \y''} is not a valid tikzpicture drawing command, so it yields nothing. You will get the expected output if using it outside the tikzpicture environment.

\documentclass{standalone}
\usepackage{tikz}

\begin{document}

\foreach \x / \y in {1/2,a/b} {``\x\ and \y''}

\end{document}

enter image description here

1

In case that you like to have result of your loop in a tikzpictue, than it should be in some node. For example:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{chains, positioning}

\begin{document}
\begin{tikzpicture}[start chain=going right, node distance=0pt]
\foreach \x / \y in {1/2,a/b} 
{
\node[on chain] {``\x\ and \y''};
}
\end{tikzpicture}
\end{document}

enter image description here

1
  • Yes. Thank you! That makes sense to me.
    – Aria
    Jul 9, 2020 at 7:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .