1

Iteration with foreach brings error in the moment I use a list with two variables as you can see in the mwe. Is there a solution possible? As the output PDF shows the error occurs when trying to use a list. Howto integrate the mwe?

\documentclass[a4paper,10pt]{article}
\usepackage[utf8x]{inputenc}
\usepackage{tikz}

\begin{document}
%two variables
\foreach \x   in    {1.00,1.033,...,2.000,2.033,2.083,...,3.000,3.050,3.15,...,4.000}
{
   x \x ;
}

% output 3 series of variables(x and y). 1. between 1 and 2 thirty steps,   2. betw. 2 a. 3 twenty steps, 3. betw. 3 a. 4 ten steps. thats the aim. here  shortened to the end of three(3.000)
\foreach \x / \y in 
   %{1.00/1.033,1.033/1.066}% 0 errors, pdf ok
   {1.00/1.033,1.033/1.066,...,2.000/2.033} % 63 errors, pdf output gen  erated! shows wrong variable contents
   % third version 88 errors, but pdf generated! shows wrong variable values
   %{1.00/1.033,1.033/1.066,...,2.000/2.033,2.033/2.066,2.116/2.166,...,3.000/3.050}
   {
      x1: \x,  y1: \y \\
   }
\end{document}
vonbrand
  • 5,473
gizeh
  • 491
  • 1
    Not sure, but could you use an alternative notation? As an example: \foreach \x [evaluate=\x as \y using \x+0.033] in {1.0,1.033,...,2.0} { x1: \x, y1: \y \\} – Ignasi Jan 11 '16 at 09:44
  • @ignasi that gives an emergency stop don't know why. Your syntax is a nice proposal. But I see no solution for the three series of two variables I need. The addition \x+0.033 must change. – gizeh Jan 11 '16 at 10:03
  • @gizeh Ignasi's code worked for me. It's very odd that it gave you an emergency stop. Also, how the addition must change? Is the 0.033 addition not a constant? – Alenanno Jan 11 '16 at 10:22
  • My code works for me. You can type this three-part-series with three different foreach. Why do you want only one? – Ignasi Jan 11 '16 at 10:26
  • If you want to automatically type complex tables you could also use pgfplotstable which is part of pgfplots. – Ignasi Jan 11 '16 at 10:28
  • @Alenanno as mwe. the value 0.033 have to become 0.05 in the second part of the list. In the third part 0.10. Have to search for a solution with three different foreach, I think. Can't get rid of the emergency stop. – gizeh Jan 11 '16 at 13:30
  • @Ignasi I want one, because I can change the width of the step as indicated in the mwe. With the variables I want to draw/fill 30 arcs from 1 to 2, 20 arcs from 2 to 3, 10 arcs from 4 to 5. It's the shading bent tube problem that I want to solve with pgf/tikz. Before I try the "gradient"-solution ([link: http://tex.stackexchange.com/questions/172905/how-can-i-draw-a-curved-gradient-fade-in-tikz/173310#173310])with new inst. at worst internet-conn I want to solve that problem with foreach and list. The gradient seems to be the best, but I cannot understand the code yet (biquadratic). – gizeh Jan 11 '16 at 13:43
  • Don't know if this helps, but if the previous value is always in the next, you can just save it e.g. \foreach \y [remember=\y as \x (initially 1.00)] in {1.033,1.066,...,2.033} {x1: \x, y1: \y\par}. – cfr Jan 12 '16 at 03:43
  • You can use a different approach using something like multido. – Werner Jan 12 '16 at 16:22
  • thanks to all for your answers. Imho this qu. can be closed with one hint for others. Avoid use of list item "..." together with multiple variables, cp. pgf manual 3.0.1.a, p. 902f. \documentclass[a4paper,10pt]{article} \usepackage{tikz} \begin{document} \foreach \x / \y in {0/0,10/20,...,90/180,100/200}{ x1: \x, y1: \y \\} \end{document} Mwe shows: – gizeh Jan 26 '16 at 13:55

0 Answers0