So I have this :

        \node [above] at (\fpeval{7/16},0.04) {\tiny $\frac{7}{16}$};
          \draw [color=red,latex-] (\fpeval{7/16},0) -- (\fpeval{7/16},0.2) ;
        \node [above] at (\fpeval{11/16},0.3) {\tiny $\frac{11}{16}$};
          \draw [color=red,latex-] (\fpeval{11/16},0) -- (\fpeval{11/16},0.4) ;
        \node [above] at (\fpeval{11/12},0.04) {\tiny $\frac{11}{12}$};
          \draw [color=red,latex-] (\fpeval{11/12},0) -- (\fpeval{11/12},0.2) ;
        \node [above] at (\fpeval{1/12},0.3) {\tiny $\frac{1}{12}$};
          \draw [color=red,latex-] (\fpeval{1/12},0) -- (\fpeval{1/12},0.4) ;

which draws a series of points on a number line generated in Tikz :

enter image description here

Is there a way to neatly write this with a \foreach?

  • 3
    Can you please make the code snippet into a fully compilable example? – egreg Sep 1 '20 at 16:47


\tikzset{every path/.style={draw=red,latex-},
        every node/.style={above,inner sep=1pt}}
          \foreach \num/\den [count=\n,evaluate=\n as \j using {isodd(\n)==1?.4:.2}] in {1/12,7/16,11/16,11/12}{
          \draw (\fpeval{\num/\den},0) -- (\fpeval{\num/\den},\j)node  {\tiny $\frac{\num}{\den}$} ;
  • 1
    Well that count use is all kinds of brilliant. – Cliff Stamp Sep 3 '20 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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