所以我有这个:
\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) ;
在 Tikz 生成的数轴上绘制一系列点:
有没有办法用 \foreach 整齐地写出这个?
答案1
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usepackage{xfp}
\tikzset{every path/.style={draw=red,latex-},
every node/.style={above,inner sep=1pt}}
\begin{document}
\begin{tikzpicture}
\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}$} ;
}
\end{tikzpicture}
\end{document}