I want to create a diagram like that enter image description here

so far I am here, can someone help?





\tikzstyle{lightedge}=[<-, dashed]
\tikzstyle{mainstate}=[state,very thick]
\tikzstyle{mainedge}=[<-,very thick]
% 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};

  • Welcome to TeX.SX! A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). – dexteritas Jun 23 '17 at 14:44
  • @Bernard It is spelled "trellis" not "treillis" – dexteritas Jun 23 '17 at 16:36
  • @dexteritas: OK, but does it come from? – Bernard Jun 23 '17 at 16:42
  • @Bernard Yes, there is also an image of a Trellis diagram on the linked page. – dexteritas Jun 23 '17 at 16:46
  • 1
    I've put the title in its initial state. I was very surprised by this term, as usually treillis is lattice in algebra, and thought of a typo or misspelling. – Bernard Jun 23 '17 at 16:51

Here is my approach. I made commands for the edges and the inputs and outputs.

enter image description here



\tikzstyle{mainedge}=[red,very thick]
\tikzstyle{inputBit}=[rectangle,fill=red, text=white]
\tikzstyle{outputBit}=[rectangle,fill=blue, text=white]

    \pgfmathtruncatemacro{\xplusone}{#1 + 1}
        \draw[mainedge] (s#1#2) -- (s\xplusone2);
        \draw[mainedge] (s#1#2) -- (s\xplusone0);
        \draw[lightedge] (s#1#2) -- (s\xplusone3);
        \draw[lightedge] (s#1#2) -- (s\xplusone1);

% #1=x; #2=y; #3=In; #4=Out
    \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) {
            Node \pgfmathprintnumber[fixed,fixed zerofill,precision=0]{\pgfmathresult}

    % Edges

    % Inputs and Outputs
    \node at (-0.5,5) [left] {Input Bits};
    \node at (-0.5,6) [left] {Output Bits};



Here is a starting point, I've done a matrix s with only the circle nodes, to have an easy reference s-row-column.

The rest of the nodes and paths are positioned referring to that matrix.

If you find a node like $(node1-name)!.5!(node2-name)$, it refers to a node which is half way (.5) between node1 and node2.

Let me know if you have some difficulties in completing the picture.

BTW, use tikzset instead of tikzstyle, which is deprecated.


\usetikzlibrary{matrix, positioning, calc, intersections, arrows, arrows.meta}
\tikzset{% use tikzset not tikzstyle
    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},

    matrix of math nodes,
    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}; \\

enter image description here

  • I would set output bits in blue rectangles in white color, now are almost invisible. I draw many trellis diagrams, but no one so fancy :) – Zarko Jun 24 '17 at 13:02
  • @Zarko Corrected, with some refinements :) – CarLaTeX Jun 24 '17 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.