我正在尝试自己编写一个 TikZ,但遇到了麻烦。这就是我正在寻找的: 以下是我所能得到的: 最后,这是我编写的代码:
\begin{figure}[ht]
\centering
\begin{tikzpicture}[scale=10]
\coordinate (C0) at ($(0,0)$) {};
\coordinate (C1) at ($(1,0)$) {};
\draw[arrows=->] (C0) -- (C1);
\foreach \x in {2,3,4,5,6}
{
\coordinate (A\x) at ($(1/\x,0)$) {};
\draw ($(A\x)+(0,0.01)$) -- ($(A\x)-(0,0.01)$);
\node [below] at ($(A\x)+(0,-0.003)$) {$\frac{1}{\x}$};
}
\foreach \x [evaluate=\x as \xeval using \x-1] in {3,4,5,6}
{
\coordinate (B\x) at ($({(\x-1)/\x},0)$) {};
\draw ($(B\x)+(0,0.01)$) -- ($(B\x)-(0,0.01)$);
%\node [below] at ($(B\x)+(0,-0.003)$) {\frac{\xeval}{\x}}; %ERROR!
}
\node [below] at ($(1/12,-0.023)$) {$\ldots$};
\node [below] at ($(11/12,-0.023)$) {$\ldots$};
\draw ($(0,0.01)$) -- ($(0,-0.01)$);
\node [below] at ($(0,-0.011)$) {$0$};
\draw ($(1,0.01)$) -- ($(1,-0.01)$);
\node [below] at ($(1,-0.011)$) {$1$};
\end{tikzpicture}
\label{fig:dinamica F(x)}
\end{figure}
所以我问你的是:
- 如何使用评估自动书写
\frac{2}{3}
等\frac{3}{4}
? - 我怎样才能自动写出弯曲的箭头?
我尝试做这件事大约需要 2 个小时。
还有一件事:为了垂直对齐标签0
,我不得不手动尝试很多坐标,直到找到正确的组合。有没有办法自动完成?谢谢\ldots
!\frac{1}{2}
答案1
我不太清楚你对“自动评估”有什么想法。我只是试着重现你的手绘草图(为了练习……)。
\documentclass[tikz,
border=3mm]{standalone}
\usetikzlibrary{calc,positioning,quotes}
\begin{document}
\begin{tikzpicture}[
every edge quotes/.style = {font=\footnotesize, auto},
L/.style = {->, shorten >=1mm, shorten <=1mm},
LA/.style = {out= 75, in=105, looseness=#1},
LB/.style = {out=255, in=285, looseness=#1}
]
\draw (0,0) -- (10,0);
\foreach \x/\y [count = \xx] in
{0/1, 1/6, 1/5, 1/4, 1/3, 1/2, 2/3, 3/4, 4/5, 5/6, 1/1}
{
\ifnum\y=1
\coordinate[label={[yshift=-1mm]below:$\x$}] (n\xx) at (10*\x/\y,0)
\else
\coordinate[label={[yshift=-1mm]below:$\frac{\x}{\y}$}] (n\xx) at (10*\x/\y,0)
\fi;
% draw ticks
\draw (10*\x/\y,0.1) -- + (0,-0.2);
}
% dots
\node [below=7pt] at ($(n1)!0.5!(n2)$) {$\dots$};
\node [below=7pt] at ($(n10)!0.5!(n11)$) {$\dots$};
% loops above
\draw[L] ($(n2)!0.5!(n3)$) to [LA=2,"4"] ($(n3)!0.5!(n4)$);
\draw[L] ($(n3)!0.5!(n4)$) to [LA=2,"3"] ($(n4)!0.5!(n5)$);
\draw[L] ($(n4)!0.5!(n5)$) to [LA=2,"2"] ($(n5)!0.5!(n6)$);
\node (A) [above=17mm of n6,inner sep=0pt] {A};
\draw[L] ($(n5)!0.6!(n6)$) to [bend left,"1"] (A);
\draw[L] ($(n6)!0.4!(n7)$) to [bend right,"1" '] (A);
% loops below
\draw[L] ($(n8)!0.5!(n9)$) to [LB=1.5,"4" '] ($(n3)!0.5!(n4)$);
\draw[L] ($(n7)!0.5!(n8)$) to [LB=1.5,"3" '] ($(n4)!0.5!(n5)$);
\draw[L] ($(n6)!0.5!(n7)$) to [LB=2.5,"2" '] ($(n5)!0.5!(n6)$);
\end{tikzpicture}
\end{document}
我得到:
答案2
这是我画数轴的尝试。我不知道画弧的算法/逻辑自动地。圆弧必须从刻度标记的中点开始,并结束于其他刻度标记的中点之间(这是我从图片中了解到的全部内容)。在此代码中,刻度标签和椭圆是半自动放置和标记。0 和 1 不受欢迎,作为副作用被标记为 0/1 和 1/1。
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
% the unit interval is magnified by 10 times
\draw (0,0) -- (10,0);
\foreach \x/\y [count = \cc] in
{0/1, 1/6, 1/5, 1/4, 1/2, 4/5, 5/6, 1/1}
{
\coordinate (nn\cc) at(10*\x / \y, 0);
\node [below of= nn\cc,
node distance = 0.5cm]
{$\frac{\x}{\y}$};
% comment below node. it is not required
\node [above of= nn\cc,
node distance = 0.5cm,
rotate=45]
{$nn\cc$};
% draw ticks
\draw (10*\x / \y, -0.1) --
(10*\x / \y, 0.1);
}
%Find midpoint of first two and last two nodes
\draw (nn1) -- coordinate [pos=0.5](firstdot) (nn2);
\draw (nn7) -- coordinate [pos=0.5](lasttdot) (nn8);
% draw ellipsis at the midpoint shifted by 0.5cm
\node [below of= firstdot, node distance = 0.5cm]
{$\cdots$};
\node [below of= lasttdot, node distance = 0.5cm]
{$\cdots$};
\end{tikzpicture}
\end{document}