Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

\def\ffIiC{+0.0436275-1.18778*\x^1+0.542693*\x^2}
% ...
\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
add comment

1 Answer 1

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.

\documentclass{article}
\usepackage{tikz}

\begin{document}
\tikz {
    \def\ffIiC{+0.0436275-1.18778*\x^1+0.542693*\x^2}
    \draw \foreach\x in {0,.1,...,4} {
            \ifdim\x pt=0pt \else--\fi
            ({\x},{\ffIiC})
    };
}
\end{document}

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
add comment

Your Answer

 
discard

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.