我想在 LaTex 中绘制一些图形,我正在尝试绘制这个最小图形。
到目前为止我已经写了以下代码:
\documentclass[tikz,border=10pt]{standalone}
\usepackage[english,ngerman]{babel}
\usepackage[utf8]{inputenc}
\usetikzlibrary{arrows}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,
thick,main node/.style={circle,draw,font=\Large\bfseries},every path/.style= {>=latex}]
\node[main node] (a) {A};
\node[main node] (b) [below = 2.4cm of a] {B};
\node[main node] (c) [below right = 1.2cm and 1.5cm of a] {C};
\path
(a) edge node {} (c)
(b) edge [bend right] node {} (c)
(c) edge node[above] {} (b);
\end{tikzpicture}
\end{document}
但我无法绘制黄色方块。有人能帮我吗?
答案1
你可以使用与之前完全相同的策略来放置节点并在它们之间绘制箭头。黄色方块的一个可能的样式定义是
yellow box/.style={draw=black,fill=yellow, minimum size=8mm}
b
在我的示例中,箭头的排列方式与您的图像不同,但这是因为您的代码中和之间有两个箭头c
。
\documentclass[tikz,border=10pt]{standalone}
\usepackage[english,ngerman]{babel}
\usepackage[utf8]{inputenc}
\usetikzlibrary{arrows.meta} % supersedes arrows
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
->, >=Stealth, shorten >=1pt, % Stealth from arrows.meta instead of stealth' from arrows
thick,
main node/.style={circle,draw,font=\Large\bfseries},
every path/.style={>=latex},
yellow box/.style={draw=black,fill=yellow, minimum size=8mm}
]
\node[main node] (a) {A};
\node[main node] (b) [below = 2cm of a] {B};
\node[main node] (c) [below right = 1.2cm and 2.5cm of a] {C};
\node[yellow box, right=of a] (i1) {inf\textsubscript{1}};
\path (b) -- node[yellow box, midway] (i2) {inf\textsubscript{2}} (c);
\node[yellow box, below right=2mm and -2mm of i2] (i3) {inf\textsubscript{3}};
% note that you don't need the empty node {} after each edge
\path
(a) edge (i1)
(i1) edge (c)
(b) edge[bend right] (i3)
(i3) edge[bend right] (c)
(c) edge (i2)
(i2) edge (b);
\end{tikzpicture}
\end{document}