我怎样才能用 LaTeX 制作这个beamer
(我对箭头有问题)?
我只有这个
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows}
\begin{document}
\begin{frame}
\begin{tikzpicture}[ node distance = 8.1 mm and 6 mm, > = stealth', every node/.style = {circle, draw=pink!30!black, fill=pink!30, minimum size=8mm} ]
\node (b) {\tiny A};
\node (a) [below right=of b] {{\tiny C}};
\node (c) [above right=of a] {{\tiny B}};
\node (d) [below right=of c] {{\tiny D}}
\end{tikzpicture}
\end{frame}
\end{document}
答案1
借助图书馆的两个版本automata
:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, automata, positioning, quotes}
\begin{document}
\centering
\begin{tikzpicture}[
shorten < = 1mm, shorten > = 1mm,
node distance = 33mm, on grid, auto,
every path/.style = {bend left, -Latex}
]
\node[state] (A) {A};
\node[state] (B) [right=of A] {B};
\node[state] (C) [below=of A] {C};
\node[state] (D) [right=of C] {D};
%
\path[->] (A) edge ["e"] (B)
(B) edge (D)
(D) edge (C)
(C) edge ["h"] (A)
%
(A) edge (C)
(C) edge (D)
(D) edge ["g"] (B)
(B) edge ["f"] (A);
\end{tikzpicture}
\begin{tikzpicture}[
shorten < = 1mm, shorten > = 1mm,
node distance = 33mm, on grid, auto,
every path/.style = {-Latex},
sx+/.style = {xshift=1 mm},
sy+/.style = {yshift=1 mm},
sx-/.style = {xshift=-1 mm},
sy-/.style = {yshift=-1 mm},
]
\node[state] (A) {A};
\node[state] (B) [right=of A] {B};
\node[state] (C) [below=of A] {C};
\node[state] (D) [right=of C] {D};
%
\path[->] ([sy+] A.east) edge ["e"] ([sy+] B.west)
([sx+] B.south) edge ([sx+] D.north)
([sy-] D.west) edge ([sy-] C.east)
([sx-] C.north) edge ["h"] ([sx-] A.south)
%
([sx+] A.south) edge ([sx+] C.north)
([sy+] C.east) edge ([sy+] D.west)
([sx-] D.north) edge ["g"] ([sx-] B.south)
([sy-] B.west) edge ["f"] ([sy-] A.east);
\end{tikzpicture}
\end{document}
编辑: 在第二张图片中添加了更漂亮的箭头位置
附录: 该版本不遵循所讨论的图像,而是遵循代码:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, automata, calc, positioning, quotes}
\begin{document}
\centering
\begin{tikzpicture}[
shorten < = 1mm, shorten > = 1mm,
node distance = 22mm, on grid, auto,
every path/.style = {-Latex},
state/.append style = {draw=pink!30!black, fill=pink!30, minimum size=8mm},
sx+/.style = {xshift=1 mm},
sy+/.style = {yshift=1 mm},
sx-/.style = {xshift=-1 mm},
sy-/.style = {yshift=-1 mm},
]
\node[state] (A) {A};
\node[state] (B) [right=of A] {B};
\node[state] (C) [below right=of A] {C};
\node[state] (D) [right=of C] {D};
%
\path[->] ([sy+] A.east) edge ["e"] ([sy+] B.west)
([sx+] B.south east) edge ([sx+] D.north west)
([sy-] D.west) edge ([sy-] C.east)
([sx-] C.north west) edge ["h"] ([sx-] A.south east)
%
([sx+] A.south east) edge ([sx+] C.north west)
([sy+] C.east) edge ([sy+] D.west)
([sx-] D.north west) edge ["g"] ([sx-] B.south east)
([sy-] B.west) edge ["f"] ([sy-] A.east);
\end{tikzpicture}
\end{document}
答案2
像这样吗?
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{quotes,positioning,arrows}
\begin{document}
\newcommand*{\arrowsep}{0.2cm}
\begin{tikzpicture}[my arrow/.style={-latex, shorten >=2pt, shorten <=2pt},
shift left/.style={transform canvas={xshift = -\arrowsep/2}},
shift right/.style={transform canvas={xshift = \arrowsep/2}},
shift up/.style={transform canvas={yshift = \arrowsep/2}},
shift down/.style={transform canvas={yshift = -\arrowsep/2}},
node distance = 8.1 mm and 6 mm, > = stealth', my node/.style = {circle, draw=pink!30!black, fill=pink!30, minimum size=8mm}]
\node[my node] (A) {\tiny A};
\node[my node] (C) [below right=of A] {{\tiny C}};
\node[my node] (B) [above right=of C] {{\tiny B}};
\node[my node] (D) [below right=of B] {{\tiny D}};
\draw (A) edge[my arrow, shift up,"e"] (B) edge[my arrow, shift right] (C)
(B) edge[my arrow, shift down,"f"] (A) edge[my arrow, shift left] (D)
(D) edge[my arrow, shift down] (C) edge[my arrow, shift right,"g",auto=right] (B)
(C) edge[my arrow, shift up] (D) edge[my arrow, shift left,"h"] (A);
\end{tikzpicture}
\end{document}
注意,transform canvas
对于移位edge
s,正常移位在这种情况下不起作用:参见TikZ:xshift 没有移位
定义一个命令来保存样式、和的\arrowsep
值。shift up
down
left
right
键shorten >=<dim>
和shorten <=<dim>
通过缩短路径的第一位和最后一位<dim>
,使箭头与节点保持距离。