![图表存在问题](https://linux22.com/image/459143/%E5%9B%BE%E8%A1%A8%E5%AD%98%E5%9C%A8%E9%97%AE%E9%A2%98.png)
我正在尝试绘制一个图表,我尽了最大努力,创建了下图。从图中可以看出,标签令人困惑。可以解决这个问题吗?确切地说,是否可以在箭头内部或沿箭头方向标记边缘?
以下是代码:
\documentclass[reqno]{amsart}
\usepackage[left=2.5cm,right=2.5cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{amsthm}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usetikzlibrary{positioning}
\tikzset{
treenode/.style = {shape=rectangle, rounded corners,
draw, align=center,
top color=white, bottom color=blue!20},
root/.style = {treenode, font=\Large, bottom color=red!30},
env/.style = {treenode, font=\ttfamily\normalsize},
dummy/.style = {circle,draw}
}
\begin{document}
\begin{center}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=5.2cm,
semithick]
\tikzstyle{every state}=[fill=yellow,draw=none,text=black]
\node[env] (A) { $\alpha$-derivative};
\node[env] (B) [below left of=A] {Nabla $(q,h)$-derivative};
\node[env] (C) [below right of=A] {Delta $(q,h)$-derivative};
\node[env] (D) [below of=B] {Nabla $q$-derivative};
\node[env] (E) [below left of=B] {Nabla $h$-derivative};
\node[env] (F) [below of=C] {Delta $q$-derivative};
\node[env] (G) [below right of=C] {Delta $h$-derivative};
\node[env] (O) [below left of=F] {Ordinary derivative};
\node[env] (H) [left of=A] {$q$-derivative generator};
\node[env] (I) [right of=A] {$h$-derivative generator};
\path (A) edge node {$t=0$} (B)
(A) edge node {$h\to 0$} (H)
(A) edge node {$q\to 1$} (I)
edge node {$t=1$} (C)
(B) edge node {$h\to 0$} (D)
(B) edge node {$q\to 1$} (E)
(C) edge node {$h\to 0$} (F)
(C) edge node {$q\to 1$} (G)
(D) edge node[below] {$q\to 1$} (O)
(E) edge[thick, bend right] node[below] {$h\to 0$} (O)
(F) edge node {$q\to 1$} (O)
(G) edge[thick, bend left] node[below] {$h\to 0$} (O)
(B) edge node[left] {$(q,h)\to (1,0)$} (O)
(C) edge node[left] {$(q,h)\to (1,0)$} (O)
(H) edge[thick, bend right] node[below]{$t=0$} (D)
(H) edge node {$t=1$} (F)
(I) edge[thick, bend left] node {$t=1$} (G)
(I) edge [thick, out=90, in=90, looseness=1] node[below] {$t=0$} (E)
;
\end{tikzpicture}
\end{center}
\end{document}
答案1
我认为你也可以通过使用从左到右的布局来改进它,并调整节点的相对位置以避免一些交叉。也许像这样:
我相信你可以在 tikz 中完成这个布局,但在这里我使用了元帖子因此您需要使用以下命令编译该示例lualatex
:
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
pair a, b; a = origin; b = 400 right;
picture b[];
b0 = thelabel("\strut $\alpha$-derivative", a);
b1 = thelabel("\strut Ordinary derivative", b shifted 120 right);
b2 = thelabel("\strut Delta $h$-derivative", b shifted 80 up);
b4 = thelabel("\strut Nabla $h$-derivative", b shifted 40 up);
b3 = thelabel("\strut Delta $q$-derivative", b shifted 40 down);
b5 = thelabel("\strut Nabla $q$-derivative", b shifted 80 down);
b6 = thelabel("\strut Delta $(q,h)$-derivative", 7/16[a,b] shifted 24 up);
b7 = thelabel("\strut Nabla $(q,h)$-derivative", 7/16[a,b] shifted 24 down);
b8 = thelabel("\strut $h$-derivative generator", 3/8[a,b] shifted 72 up);
b9 = thelabel("\strut $q$-derivative generator", 3/8[a,b] shifted 72 down);
forsuffixes $=0,1,2,3,4,5,6,7,8,9:
% decorate the box
interim bboxmargin := 4;
path corner; corner = 3 up {down} .. {right} 3 right;
path rb; rb = for i=0 upto 3: corner rotated 90i shifted point i of bbox b$ -- endfor cycle;
picture fb; fb = image(
for i = 0 upto 32:
draw interpath(i/32, subpath(0,1) of bbox b$, subpath (3,2) of bbox b$)
withpen pencircle scaled 1
withcolor (i/128+3/4)[blue, white];
endfor); clip fb to rb; draw fb; draw rb;
% draw the text
draw b$;
endfor
vardef connect(expr A, B, r, t) =
save s, p;
interim bboxmargin := 6;
path p; p = point 3/2 of bbox A {right} .. {right} point 7/2 of bbox B;
picture s; s = thelabel(TEX(t) scaled 5/8, point r of p);
interim bboxmargin := 2; interim ahangle := 30;
drawarrow p; unfill bbox s; draw s withcolor 2/3 red;
enddef;
connect(b0, b6, 1/2, "$t=1$");
connect(b0, b7, 1/2, "$t=0$");
connect(b0, b8, 1/2, "$q\to1$");
connect(b0, b9, 1/2, "$h\to0$");
connect(b8, b2, 1/3, "$t=1$");
connect(b8, b4, 1/3, "$t=0$");
connect(b9, b3, 1/3, "$t=1$");
connect(b9, b5, 1/3, "$t=0$");
connect(b6, b1, 9/16, "$(q,h)\to(1,0)$");
connect(b6, b2, 1/4, "$q\to1$");
connect(b6, b3, 1/4, "$h\to0$");
connect(b7, b1, 9/16, "$(q,h)\to(1,0)$");
connect(b7, b4, 1/4, "$q\to1$");
connect(b7, b5, 1/4, "$h\to0$");
vardef connect(expr A, B, r, t) =
save s, p;
interim bboxmargin := 6;
path p; p = point 3/2 of bbox A {right} .. {dir -50} point 21/8 of bbox B;
picture s; s = thelabel(TEX(t) scaled 5/8, point r of p);
interim bboxmargin := 2; interim ahangle := 30;
drawarrow p; unfill bbox s; draw s withcolor 2/3 red;
enddef;
connect(b2, b1, 1/3, "$h\to0$");
connect(b4, b1, 1/3, "$h\to0$");
vardef connect(expr A, B, r, t) =
save s, p;
interim bboxmargin := 6;
path p; p = point 3/2 of bbox A {right} .. {dir 50} point 3/8 of bbox B;
picture s; s = thelabel(TEX(t) scaled 5/8, point r of p);
interim bboxmargin := 2; interim ahangle := 30;
drawarrow p; unfill bbox s; draw s withcolor 2/3 red;
enddef;
connect(b3, b1, 1/3, "$q\to1$");
connect(b5, b1, 1/3, "$q\to1$");
endfig;
\end{mplibcode}
\end{document}
如果您注释掉“装饰盒子”部分,您会得到一个更简单的版本,我想我更喜欢这个版本:
答案2
您可以添加every node/.append style={sloped}
到您的tikzpicture
。然后使用对单个节点进行一些手动调整below
,并pos=
可以清理一切。
(H.345)
另外,请注意下面代码中的使用。345
指的是节点周边的位置(角度)。通过不使用节点的默认值(中心),可以避免箭头穿过节点Nabla (q,h)-derivative
。
\documentclass[reqno]{amsart}
\usepackage[left=2.5cm,right=2.5cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{amsthm}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usetikzlibrary{positioning}
\tikzset{
treenode/.style = {shape=rectangle, rounded corners,
draw, align=center,
top color=white, bottom color=blue!20},
root/.style = {treenode, font=\Large, bottom color=red!30},
env/.style = {treenode, font=\ttfamily\normalsize},
dummy/.style = {circle,draw}
}
\begin{document}
\begin{center}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=5.2cm,
semithick, every node/.append style={sloped}]
\tikzstyle{every state}=[fill=yellow,draw=none,text=black]
\node[env] (A) { $\alpha$-derivative};
\node[env] (B) [below left of=A] {Nabla $(q,h)$-derivative};
\node[env] (C) [below right of=A] {Delta $(q,h)$-derivative};
\node[env] (D) [below of=B] {Nabla $q$-derivative};
\node[env] (E) [below left of=B] {Nabla $h$-derivative};
\node[env] (F) [below of=C] {Delta $q$-derivative};
\node[env] (G) [below right of=C] {Delta $h$-derivative};
\node[env] (O) [below left of=F] {Ordinary derivative};
\node[env] (H) [left of=A] {$q$-derivative generator};
\node[env] (I) [right of=A] {$h$-derivative generator};
\path
(A) edge node {$t=0$} (B)
(A) edge node[below, pos=.4] {$h\to 0$} (H)
(A) edge node {$q\to 1$} (I)
edge node {$t=1$} (C)
(B) edge node {$h\to 0$} (D)
(B) edge node[pos=.7] {$q\to 1$} (E)
(C) edge node {$h\to 0$} (F)
(C) edge node {$q\to 1$} (G)
(D) edge node[below] {$q\to 1$} (O)
(E) edge[thick, bend right] node[below] {$h\to 0$} (O)
(F) edge node {$q\to 1$} (O)
(G) edge[thick, bend left] node[below] {$h\to 0$} (O)
(B) edge node {$(q,h)\to (1,0)$} (O)
(C) edge node[pos=.6] {$(q,h)\to (1,0)$} (O)
(H) edge[thick, bend right] node[pos=.8]{$t=0$} (D)
(H.345) edge node {$t=1$} (F)
(I) edge[thick, bend left] node {$t=1$} (G)
(I) edge [thick, out=90, in=90, looseness=1] node[pos=.4] {$t=0$} (E)
;
\end{tikzpicture}
\end{center}
\end{document}