2

I saw this question a few days ago:
missing a tick label that has been named

I answered the following, and it got downvoted (3 times), then deleted:

Does this give what you want? xtick = {-3.14, -1.57, ..., 9.42},

Someone gave the following comment 2 days later:

Replacing your xtick={...} with xtick={-3.14,-1.57,...,9.42} works for me (which avoids the rounding errors).

to which the asker replied:

It worked too on me! Thank you so much

I'm trying to understand what caused this huge difference is these two replies.
I know the most probable explanation is that the 3 people saw something bad in my answer, and not in the other comment.
But, reading and re-reading the 2 replies, I can't see it.
For me, the question was clear, the context was clear, and the 2 replies are short, clear and helpful.

So if the difference is in fact so obvious, could anyone explain it to me?

PS:
After reading some advice on how to post a "good" answer, I tried a different approach and edited my deleted answer, but nothing happened (no upvote, no accepted answer, etc.):

TikZ probably just expects two numbers before "...,", in your xtick list, so, giving it three numbers may lead to this unwanted behaviour. The pgfmanual (https://pgf-tikz.github.io/pgf/pgfmanual.pdf) mentions this two-numbers rules for the foreach statement: "If you provide two numbers before the ..., the \foreach statement will use their difference for the stepping"

So maybe this answer had a problem too.

3
  • 1
    tex.stackexchange.com/questions/644065/… is a comment, not an answer May 18 at 11:44
  • Sorry if my vocabulary is confusing. Is there a term on Stack Exchange to describe the concept I meant: something that answers the question of the asker (like the information "xtick = {-3.14, -1.57, ..., 9.42}"), which is sometimes, and sometimes not, a Stack-Exchange-Answer? Is my original downvote-reason the fact that I wrote an "Answer", which are expected to have certain qualities, whereas the other person wrote a "Comment", which is not expected to have so high qualities?
    – Michaël
    May 18 at 12:07
  • 1
    In any case, you're probably bitten by some automatic quality-control thing inherited from StackOverflow (for one, although the question in your old "answer" is a rhetorical question, it looks like not-an-answer). Generally speaking the rules of this particular site is not as stringent as StackOverflow, but you should still try to make answer somewhat good (include an explanation/at least a disclaimer "I don't really understand why but it works"/some demo/screenshot of output etc.)
    – user202729
    May 27 at 16:45

1 Answer 1

3

Your suggestion to remove the values from the list solves the problem in this specific case, but the explanation is incorrect.

It is perfectly fine to give more than two values before (or after) the .... The documentation you quote, just wants to say that if you provide more than one number, the step size is calculated from the difference of the two numbers before the ... instead of using the default step size of 1.

What is actually happening in this case is the rounding precision of pgf is just not really good and by removing the value, the calculated step size is slightly different. This difference means that the last calculated value is now inside the interval instead of outside, thus one more tick is calculated. Compare the following two loops:

\documentclass{article}
\usepackage{pgffor}
\begin{document}

\foreach \x in {-3.14, -1.57, 0., ..., 7.85, 9.42}{
  \x
  
}

\bigskip


\foreach \x in {-3.14, -1.57, ..., 9.42}{
  \x
  
}


\end{document}

For the question you link to this means that by allowing a bit of margin for rounding errors, e.g. xtick = {-3.14, -1.57, 0., ..., 7.851, 9.42}, the problem can be avoided.

5
  • Indeed, as you said, my answer worked only by accident. The reason of the asker's problem was not what I thought, and it was deeper than I thought! Now I understand why my original answer was downvoted.
    – Michaël
    May 18 at 12:34
  • @Michaël With this new knowledge, you could go ahead and write a new answer to help future users with the same problem :) May 18 at 12:39
  • 2
    Done :-) I stole your answer, and added a link to it in the original post. Thanks for your clear technical explanations and meta-explanations.
    – Michaël
    May 18 at 13:28
  • @Michaël I tried to streamline the answer a bit to focus more on the problem instead of the history with the deleted question. I hope you don't mind. May 18 at 13:53
  • I don't mind ;-)
    – Michaël
    May 18 at 14:03

You must log in to answer this question.

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