我有以下 tex 代码
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning}
\tikzset{
%Define standard arrow tip
>=stealth',
%Define style for boxes
punkt/.style={
rectangle,
rounded corners,
draw=black, very thick,
text width=6.5em,
minimum height=2em,
text centered},
% Define arrow style
pil/.style={
->,
thick,
shorten <=2pt,
shorten >=2pt,}
}
\begin{document}
\begin{tikzpicture}[node distance=1cm, auto,]
%nodes
\node[punkt] (agent) {Agent};
\node[below=of agent] (dummy) {};
\node[left=2.0 of dummy] (state) {$X_t$}
edge[pil, bend left=45] (agent.west);
\node[left=3.0 of dummy] (reward) {$R_t$}
edge[pil, bend left=45] (agent.west);
\node[punkt, inner sep=5pt,below=1.0cm of dummy]
(environment) {Environment};
\draw (environment.west) edge[pil, bend left=45] (state.south)
edge[pil, bend left=45] (reward.south);
% We make a dummy figure to make everything look nice.
\node[right=2.0cm of dummy] (action) {$A_t$}
edge[pil,bend right=45] (agent.east)
edge[pil, bend left=45] (environment.east); % .east since we want
% consistent
\end{tikzpicture}
\end{document}
我想
- 将主体与行动联系起来
- 从环境节点左侧中间开始边缘(已修复,感谢@marsupilam)
答案1
步骤如下:
- 定义所需的节点
- 画出它们之间的边缘。
听起来很合逻辑,不是吗?
输出
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{calc,positioning,arrows}
\begin{document}
\tikzset
{
punkt/.style =
{
circle,
draw,
},
pil/.style =
{
red,
-stealth',
bend left=45,
},
}
\begin{tikzpicture}[node distance=1cm, auto,]
%nodes
\node[punkt] (agent) {Agent};
\node[below=of agent] (dummy) {};
\node[left=2.0 of dummy] (state) {$X_t$} ;
\node[left=3.0 of dummy] (reward) {$R_t$} ;
\node[punkt, inner sep=5pt,below=1.0cm of dummy] (environment) {Environment};
\node[right=2.0cm of dummy] (action) {$A_t$} ;
% edges
\path[every edge/.append style={pil}]
(environment.west) edge (state.south)
edge (reward.south)
(agent.east) edge (action)
(action) edge (environment.east)
(state) edge (agent.west)
(reward) edge (agent.west);
\end{tikzpicture}
\end{document}
答案2
基于给定的 MWE 和马苏皮兰答案,但有以下变化:
- 节点定位的不同方法,仅使用预定义的节点距离
- 对于边缘的使用
arrow.meta
和bending
库以及它们的风格,我有一些个人风格(可以根据您的需要轻松更改) - 简化绘制边缘的代码
这些变化使得 MWE 稍微更加简洁:
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta, bending, positioning}
\begin{document}
\begin{tikzpicture}[
every node/.append style = {inner sep=1.5pt},
node distance = 12mm and 9mm,
punkt/.style = {circle, draw, very thick},
pil/.style = {line width=1mm, red, -{Stealth[length=4mm,bend]},
shorten >=1pt, shorten <=2pt, bend left=#1},
pil/.default = 30
]
%nodes
\node (reward) {$R_t$} ;
\node (state) [right=of reward] {$X_t$} ;
\node (env) [punkt,
below right=of state] {Environment};
\node (action) [above right=of env] {$A_t$} ;
%
\node (agent) [punkt,
above=of state.north -| env] {Agent};
% edges
\draw[pil] (agent) edge (action)
(action) edge (env)
(env) edge (state)
(env) edge[pil=40] (reward)
(state) edge (agent)
(reward) edge[pil=40] (agent);
\end{tikzpicture}
\end{document}