答案1
使用 Ti钾Z 以及你可以做的一些循环:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \i [evaluate = \i as \x using {pow(2,\i-1)}] in {1,...,4} {
\foreach \j in {1,...,\x} {
\draw ({4-8*\j/\x},0) -- ++({4/\x},{4/\x}) -- ++({4/\x},{-4/\x});
}
}
\draw (0,-0.5) -- (0,4.5) (-5,0) -- (5,0);
\node[right] at (0,4) {$+1$};
\node[below] at (-4,0) {$-1$};
\node[below] at (4,0) {$+1$};
\foreach \k [evaluate = \k as \y using {pow(2,2-\k)},
evaluate = \k as \z using {int(pow(2,\k))})] in {1,...,3} {
\draw[densely dotted] (-4,\y) -- (4,\y);
\node[left] at (-4,\y) {$u = \frac{1}{\z}$};
}
\end{tikzpicture}
\end{document}
您可以在此基础上进一步提高其灵活性,以便您可以将 4 更改为 5(甚至更高的数字)并获得更大的图表:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}\tiny
\pgfmathsetmacro{\d}{5}
\foreach \i [evaluate = \i as \x using {pow(2,\i-1)}] in {1,...,\d} {
\foreach \j in {1,...,\x} {
\draw ({\d-2*\d*\j/\x},0) -- ++({\d/\x},{\d/\x}) -- ++({\d/\x},{-\d/\x});
}
}
\draw (0,-0.5) -- (0,{\d+0.5}) ({-\d-1},0) -- ({\d+1},0);
\node[right] at (0,{\d}) {$+1$};
\node[below] at ({-\d},0) {$-1$};
\node[below] at ({\d},0) {$+1$};
\foreach \k [evaluate = \k as \y using {\d/2/pow(2,\k-2)},
evaluate = \k as \z using {int(pow(2,\k-1))})] in {2,...,\d} {
\draw[densely dotted] ({-\d},\y) -- ({\d},\y);
\node[left] at ({-\d},\y) {$u = \frac{1}{\z}$};
}
\end{tikzpicture}
\end{document}