我正在尝试创建以下图像,我已经开始了,但它不是我所期望的那样。
我还想选择向网络添加颜色,例如:
我该如何添加这些更改?如果我能完成一个模型,我想我就能完成第二个。
\documentclass[12pt]{article}
\usepackage{tikz}
\tikzset{
embedding/.style={rectangle,draw=black,text centered},
index/.style={circle,draw=black,text centered, minimum width=0.45cm},
hidden/.style={rectangle split,rectangle split horizontal=true,rectangle split parts=7,draw=black},
}
\usetikzlibrary{shapes}
\usetikzlibrary{positioning,backgrounds}
\begin{document}
\begin{figure}
\center
\begin{tikzpicture}[>=latex]
\node[embedding] (Wt) {$w_t$};
\node[hidden] (h1)[above=of Wt]{} edge [<-] (Wt);
\node[index] (W-2) [above left =of h1] {$w_{t-2}$} edge [<-] (h1);
\node[index] (W-1) [right =of W-2] {$w_{t-1}$}edge [<-] (h1);
%\node[index] (W0) [right =of W-0] {$w_{t0}$}edge [<-] (h1) ; % add in a w_0 here and colour it differently to the other nodes at this line
\node[index] (W+1) [right =of W-1] {$w_{t+1}$}edge [<-] (h1) ;
\node[index] (W+2) [right =of W+1] {$w_{t+2}$}edge [<-] (h1) ;
\end{tikzpicture}
\caption{Some caption}
\end{figure}
\end{document}
答案1
在下面的 MWE 中,我稍微改变了绘制圆形节点的顺序。我将 W0 直接放在 h1 上方,然后向左和向右移动(分别使用left=of...
和right=of...
)。为了给 W0 节点着色,我添加了fill=yellow
。
\documentclass[12pt]{article}
\usepackage{tikz}
\tikzset{
embedding/.style={rectangle,draw=black,text centered},
index/.style={circle,draw=black,text centered, minimum width=0.45cm},
hidden/.style={rectangle split,rectangle split horizontal=true,rectangle split parts=7,draw=black},
}
\usetikzlibrary{shapes}
\usetikzlibrary{positioning,backgrounds}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[>=latex]
\node[embedding] (Wt) {$w_t$};
\node[hidden] (h1)[above=of Wt]{} edge [<-] (Wt);
\node[index] (W0) [above =of h1, fill=yellow] {$w_{t0}$}edge [<-] (h1) ; % add in a w_0 here and colour it differently to the other nodes at this line
\node[index] (W-1) [left =of W0] {$w_{t-1}$}edge [<-] (h1);
\node[index] (W-2) [left =of W-1] {$w_{t-2}$} edge [<-] (h1);
\node[index] (W+1) [right =of W0] {$w_{t+1}$}edge [<-] (h1) ;
\node[index] (W+2) [right =of W+1] {$w_{t+2}$}edge [<-] (h1) ;
\end{tikzpicture}
\caption{Some caption}
\end{figure}
\end{document}
如果您希望所有圆形节点具有相同的半径,则可以使用更大的minimum
宽度,如下所示:index/.style={circle,draw=black,text centered, minimum width=1.2cm},
为了使 Wt 框也变成圆形,请替换\node[embedding] (Wt) {$w_t$};
为\node[index] (Wt) {$w_t$};
:
要将七个方框替换为与其他方框半径相同的一个圆,您可以将其替换\node[hidden] (h1)[above=of Wt]{} edge [<-] (Wt);
为\node[index] (h1)[above=of Wt]{} edge [<-] (Wt);
:
如果要单独更改单个圆的半径,可以minimum width
如下使用\node[index] (h1)[above=of Wt, minimum width=0.5cm]{} edge [<-] (Wt);
:
要删除 W0 并保留原来的空白,可以分别对 W-1 和 W+1 使用以下above left= of h1
代码above right= of h1
:
\documentclass[12pt]{article}
\usepackage{tikz}
\tikzset{
index/.style={circle,draw=black,text centered, minimum width=0.45cm},
}
\usetikzlibrary{shapes}
\usetikzlibrary{positioning,backgrounds}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[>=latex]
\node[index] (Wt) {$w_t$};
\node[index] (h1)[above=of Wt]{} edge [<-] (Wt);
\node[index] (W-1) [above left =of h1] {$w_{t-1}$}edge [<-] (h1);
\node[index] (W-2) [left =of W-1] {$w_{t-2}$} edge [<-] (h1);
\node[index] (W+1) [above right =of h1] {$w_{t+1}$}edge [<-] (h1) ;
\node[index] (W+2) [right =of W+1] {$w_{t+2}$}edge [<-] (h1) ;
\end{tikzpicture}
\caption{Some caption}
\end{figure}
\end{document}