TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am plotting line given by y(x) expression evaluated at regularly spaced points, e.g.

% ...
\draw (0,0.0436275) \foreach\x in {0,.1,...,4}{ -- ({\x},{\ffIiiC}) };
%     ^^^^^^^^^^^^^

However, I always need to specify the first point explicitly. Is there a way to avoid that?

share|improve this question
Having always a small MWE allows other people to simply copy and paste it and test their solutions. TikZ is complex enough that solutions should be tested previous before posting. – Martin Scharrer Dec 14 '11 at 10:52
up vote 5 down vote accepted

A -- without a previous coordinate seems to be the issue. You can add a conditional to have the -- suppressed for the first value.


\tikz {
    \draw \foreach\x in {0,.1,...,4} {
            \ifdim\x pt=0pt \else--\fi

Note: The space before \else is important, otherwise an error is caused. TeX seems to add an implicit \relax as terminator for the dimension expression in that case which breaks the TikZ path.

share|improve this answer
Thanks, I wrote it shorter with count as \draw \foreach\x [count=\xi] in {0,.1,...,4}{ \ifnum\xi=1 \else--\fi ({\x},{\ffIiC}) }; but it still feels more awkward than I would like it to be... – eudoxos Dec 14 '11 at 11:15
Yes, it doesn't look that nice. It would be nice if you could give special code for the first and maybe last iteration. – Martin Scharrer Dec 14 '11 at 11:19
It's preferable to avoid the conditional inside the \foreach (time consuming). I prefer to keep the first point outside and in this case, the loop begins with 0.1 and not 0. – Alain Matthes Dec 14 '11 at 11:19
@Altermundus: Yes, but this means code repetition. In this case it is still manageable, but in general a nicer solution would be great. – Martin Scharrer Dec 14 '11 at 11:22
Isn't there way to give some not-a-point (like NaN) coordinate to TikZ, so that the first point would be simply ignored? – eudoxos Dec 14 '11 at 11:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.