我完全是新手,tikz
所以如果这看起来很容易,请原谅我。我将在我写的封闭路径内放置一个标签(大部分取自这里):
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,
thick,main node/.style={circle,draw,font=\Large\bfseries}]
\node[main node] (2) {2};
\node[main node] (1) [below left of=2] {1};
\node[main node] (3) [below right of=2] {3};
\path
(1) edge node [below]{} (2)
edge node[below] {} (3)
(2) edge node[right] {} (3)
(3) ;
\end{tikzpicture}
谢谢任何指导。
答案1
如果你不知道哪个“中心“你所说的,我建议你使用重心坐标来做到这一点。(参见手册 3.1 13.2.2 重心系统第 136 页及以下各页)
\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,
thick,main node/.style={circle,draw,font=\Large\bfseries}]
\node[main node] (2) {2};
\node[main node] (1) [below left of=2] {1};
\node[main node] (3) [below right of=2] {3};
\path
(1) edge node [below]{} (2)
edge node[below] {} (3)
(2) edge node[right] {} (3)
(3) ;
\node at (barycentric cs:1=1,2=1 ,3=1) {Text};
\end{tikzpicture}
\end{document}
答案2
无关:
- 仅使用数字作为节点名称并不是好习惯。最好使用和
1
,例如或和2
3
n1
n2
n3
- 如果不标记边,则不要用空节点弄乱代码。
quotes
使用库来标记边缘非常方便- 使用
barycentric
坐标时要小心:冒号或逗号与节点名称之间不能有空格 - 看起来你画箭头的代码有点乱
使用@AndréC 回答(+1) 中建议的将节点放置在三角形内的解决方案姆韦可以如下:
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta, positioning, quotes}
\begin{document}
\begin{tikzpicture}[
node distance = 17.3mm and 10mm,
every edge/.style = {draw, semithick, -Stealth, shorten >=1pt},
every edge quotes/.style = {inner sep=1pt,
font=\footnotesize, text=gray,
sloped, auto=left},
main/.style = {circle, draw, semithick,
minimum size=3ex, inner sep=2pt,
font=\bfseries}
]
\node (n1) [main] {1};
\node (n2) [main, above right=of n1] {2};
\node (n3) [main, below right=of n2] {3};
% note: between ":" or "," and "<node name>" had not to be empty space!
\node at (barycentric cs:n1=1 ,n2=1 ,n3=1) {text};
\draw (n1) edge ["2" '] (n3)
(n1) edge ["3"] (n2)
(n2) edge ["1"] (n3);
\end{tikzpicture}
\end{document}