到目前为止我在这里,有人可以帮忙吗?
\documentclass[a4paper,10pt]{article}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[ansinew]{inputenc}
\usepackage{lmodern}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{tikz}
\begin{document}
\tikzstyle{state}=[shape=circle,draw=blue!50,fill=blue!20]
\tikzstyle{observation}=[shape=rectangle,draw=orange!50,fill=orange!20]
\tikzstyle{lightedge}=[<-, dashed]
\tikzstyle{mainstate}=[state,very thick]
\tikzstyle{mainedge}=[<-,very thick]
\begin{tikzpicture}[]
% 1st column
\node at (0,6) {$t=0$};
\node at (-1.5,5) {$s_1=00$};
\node at (-1.5,4) {$s_2=01$};
\node at (-1.5,3) {$s_3=10$};
\node at (-1.5,2) {$s_4=11$};
\node[mainstate] (s1_1) at (0,5) {$s_1$};
\node[state] (s2_1) at (0,4) {$s_2$};
\node[state] (s3_1) at (0,3) {$s_3$};
\node[state] (s4_1) at (0,2) {$s_4$};
\node at (0,1) {Node1};
% 2nd column
\node at (2,6) {$t=1$};
\node[mainstate] (s1_2) at (2,5) {$s_1$}
edge[mainedge] (s1_1);
\node[mainstate] (s2_2) at (2,4) {$s_2$}
edge[lightedge] (s1_1);
\node[state] (s3_2) at (2,3) {$s_3$};
\node[state] (s4_2) at (2,2) {$s_4$};
\node at (2,1) {Node2};
% 3rd column
\node at (4,6) {$t=2$};
\node[mainstate] (s1_3) at (4,5) {$s_1$}
edge[mainedge] (s1_2);
\node[mainstate] (s2_3) at (4,4) {$s_2$}
edge[lightedge] (s1_2);
\node[mainstate] (s3_3) at (4,3) {$s_3$}
edge[mainedge] (s2_2);
\node[mainstate] (s4_3) at (4,2) {$s_4$}
edge[lightedge] (s2_2);
\node at (4,1) {Node3};
% 4th column
\node at (6,6) {$t=3$};
\node[mainstate] (s1_4) at (6,5) {$s_1$}
edge[mainedge] (s1_3)
edge[mainedge] (s3_3);
\node[mainstate] (s2_4) at (6,4) {$s_2$}
edge[lightedge] (s1_3)
edge[lightedge] (s3_3);
\node[mainstate] (s3_4) at (6,3) {$s_3$}
edge[mainedge] (s2_3)
edge[mainedge] (s4_3);
\node[mainstate] (s4_4) at (6,2) {$s_4$}
edge[lightedge] (s2_3)
edge[lightedge] (s4_3);
\node at (6,1) {Node4};
\end{tikzpicture}
\end{document}
答案1
这是我的方法。我为边缘、输入和输出制定了命令。
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\tikzstyle{lightedge}=[blue]
\tikzstyle{mainedge}=[red,very thick]
\tikzstyle{inputBit}=[rectangle,fill=red, text=white]
\tikzstyle{outputBit}=[rectangle,fill=blue, text=white]
\tikzstyle{pointer}=[orange,->,dashed]
\newcounter{ctra}
\newcommand{\trellisEdges}[2]{%
\setcounter{ctra}{#2}
\pgfmathtruncatemacro{\xplusone}{#1 + 1}
\ifodd\value{ctra}
\draw[mainedge] (s#1#2) -- (s\xplusone2);
\else
\draw[mainedge] (s#1#2) -- (s\xplusone0);
\fi%
\ifodd\value{ctra}
\draw[lightedge] (s#1#2) -- (s\xplusone3);
\else
\draw[lightedge] (s#1#2) -- (s\xplusone1);
\fi%
}
% #1=x; #2=y; #3=In; #4=Out
\newcommand{\trellisInOut}[4]{
\node[inputBit] (in#1) at (#1+0.5,5) {#3};
\node[outputBit] (out#1) at (#1+0.5,6) {#4};
\draw[pointer] (in#1) -- (#1+0.5,#2);
}
\begin{tikzpicture}[x=1.5cm, y=-1cm]
\node at (-0.5,0) [left] {$s_1=00$};
\node at (-0.5,1) [left] {$s_2=01$};
\node at (-0.5,2) [left] {$s_3=10$};
\node at (-0.5,3) [left] {$s_4=11$};
% Nodes
\foreach \x in {0,...,3} {
\node at (\x,-.7) {$t=\x$};
\foreach \y in {0,...,3} {
\node (s\x\y) at (\x,\y) [circle,fill=blue] {};
}
\node at (\x,4) {
\pgfmathparse{\x+1}
Node \pgfmathprintnumber[fixed,fixed zerofill,precision=0]{\pgfmathresult}
};
}
% Edges
\trellisEdges{0}{0}
\trellisEdges{1}{0}
\trellisEdges{1}{1}
\trellisEdges{2}{0}
\trellisEdges{2}{1}
\trellisEdges{2}{2}
\trellisEdges{2}{3}
% Inputs and Outputs
\node at (-0.5,5) [left] {Input Bits};
\node at (-0.5,6) [left] {Output Bits};
\trellisInOut{0}{0.5}{1}{11}
\trellisInOut{1}{2.0}{1}{01}
\trellisInOut{2}{2.5}{0}{01}
\end{tikzpicture}
\end{document}
答案2
这是一个起点,我做了一个s
只有圆形节点的矩阵,以便于参考s-row-column
。
其余节点和路径均参考该矩阵进行定位。
如果找到类似 的节点,它指的是和中间 ( )$(node1-name)!.5!(node2-name)$
的节点。.5
node1
node2
如果您在完成图片时遇到困难请告诉我。
顺便说一句,请使用tikzset
而不是tikzstyle
,因为它已被弃用。
\documentclass[a4paper,10pt]{article}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[ansinew]{inputenc}
\usepackage{lmodern}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{tikz}
\usetikzlibrary{matrix, positioning, calc, intersections, arrows, arrows.meta}
\tikzset{% use tikzset not tikzstyle
state/.style={shape=circle,draw=blue!50,fill=blue!20},
bits/.style={rectangle, text width=1.5em, align=center, text=white},
greendashed/.style={-angle 60, dashed, green, thick},
bluethick/.style={-angle 60,very thick, blue, line width=2pt},
blueline/.style={blue, thick},
redline/.style={red, thick},
}
\begin{document}
\begin{tikzpicture}
\matrix[%
matrix of math nodes,
nodes={state},
column sep=4em, row sep=7ex,
] (s) {%
s_{1} & s_{1} & s_{1} & s_{1} \\
s_{2} & s_{2} & s_{2} & s_{2} \\
s_{3} & s_{3} & s_{3} & s_{3} \\
s_{4} & s_{4} & s_{4} & s_{4} \\
};
\foreach \num/\bb in {1/00, 2/01, 3/10, 4/11}{%
\node[left = of s-\num-1, red] {$s_{\num}=\bb$};
}
\foreach \numcol in {1, 2, ..., 4}{%
\node[above =3ex of s-1-\numcol] {$t_{\numcol}$};
\node[below =3ex of s-4-\numcol] {Node $\numcol$};
}
\node[bits, fill=red, below =12ex of $(s-4-1)!.5!(s-4-2)$] (Ain) {$\mathbf{1}$};
\node[bits, fill=red, below =12ex of $(s-4-2)!.5!(s-4-3)$] (Bin) {$\mathbf{1}$};
\node[bits, fill=red, below =12ex of $(s-4-3)!.5!(s-4-4)$] (Cin) {$\mathbf{0}$};
\node[left=3em of Ain] {Input bits};
\node[bits, fill=blue, below =3ex of Ain] (Aout) {$\mathbf{11}$};
\node[bits, fill=blue, below =3ex of Bin] (Bout) {$\mathbf{01}$};
\node[bits, fill=blue, below =3ex of Cin] (Cout) {$\mathbf{01}$};
\node[left=3em of Aout] {Output bits};
\foreach \icol [evaluate=\icol as \isucc using int(\icol+1)] in {1,2,3}{%
\draw[redline] (s-1-\icol) -- node[above, black, font=\scriptsize] {$00$} (s-1-\isucc);
}
\draw[bluethick] (s-1-1) -- node[draw=blue, thin, fill=blue!20, rectangle, rounded corners, above=5pt, text=black, font=\scriptsize] {$11$} (s-2-2);
\foreach \icol [evaluate=\icol as \isucc using int(\icol+1)] in {2,3}{%
\draw[blueline] (s-1-\icol) -- node[above=2pt, black, font=\scriptsize] {$11$} (s-2-\isucc);
}
\draw[greendashed] (Ain) -- ($(s-2-1.north east)+(0.5,-0.5)$) to[out=90, in=240] ($(s-1-1)!.25!(s-2-2)-(1pt,1pt)$);
\draw[greendashed] ($(s-1-1)!.60!(s-2-2)-(1pt,1pt)$) to[out=-90, in=90] ($(Ain.north east)+(0,.7)$) to[out=-90, in=0] (Aout.east);
\matrix[above=7ex of s, column sep=.7em]{%
\draw[redline] (0,.25) -- (1,.25); & \node[font=\scriptsize] {Path when the input is 0}; \\
\draw[blueline] (0,.25) -- (1,.25); & \node[font=\scriptsize] {Path when the input is 1}; \\
};
\end{tikzpicture}
\end{document}