0

How to go to the new line and draw nodes in tikz

    \documentclass[tikz,border=3mm]{standalone}
    \usetikzlibrary{positioning,matrix}
    \begin{document}
    \begin{tikzpicture}[Dotted/.style={% https://tex.stackexchange.com/a/52856/194703
        line width=1.2pt,
        dash pattern=on 0.01\pgflinewidth off #1\pgflinewidth,line cap=round,
        shorten >=0.3em,shorten <=0.3em},
        Dotted/.default=5]
     \matrix[matrix of math nodes,nodes={circle,draw,minimum size=1.5em},
        column sep=2em,row sep=1ex](mat) {
        C_1 & D_1 \\
        C_2 & D_2 \\[2em]
        C_m & D_n \\
     };
     \draw[Dotted] (mat-2-1) -- (mat-3-1);
     \draw[Dotted] (mat-2-2) -- (mat-3-2);
     \foreach \X in {1,2,3}
     {\foreach \Y in {1,2,3}
     {\draw (mat-\X-1) -- (mat-\Y-2);}}
     \matrix[matrix of math nodes,nodes={circle,draw,minimum size=1.5em},
        column sep=1em,below=2em of mat,xshift=2em,
        column 2/.style={column sep=2.5em}](mat2) {
        E_1 & E_2 & E_p\\
        F_1 &F_2 &  F_p \\
     };
 \foreach \X in {1,2}
  {   \draw[Dotted] (mat2-\X-2) -- (mat2-\X-3);}
  \draw[Dotted];
    \end{tikzpicture}
\end{document}

This is in reference to the above linked question which was answered by @Schrodinger's Cat

I want to do some more manipulations to the code. I want to add a line full of dots and then again add some nodes.

I tried to use \draw but its not giving the required output. Can someone kindly tell me what I am doing wrong here?

enter image description here

Sebastiano
  • 54,118
Charlotte
  • 963

1 Answers1

1

I'd kindly like to suggest that you try to understand, to some extent, what these codes do. They really are just matrices of nodes. with

\matrix[matrix of math nodes,nodes={circle,draw,minimum size=1.5em}, ...]

you instruct TikZ to typeset the contents of the nodes in math mode, and tell it to draw a circle around each node. With

\foreach \X in {1,2,3}
 {\draw[Dotted] (mat2-\X-2) -- (mat2-\X-3);
 \draw[Dotted] (mat2-2-\X) -- (mat2-3-\X);}

you access the nodes of a matrix, and connect them by dotted lines. If the matrix has the name mat2, say, then its nodes have the names mat2-<row>-<column>, where <row> and <column> indicate the row and column index of the respective nodes. The rest is just relative positioning of the matrices.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{positioning,matrix}
\begin{document}
\begin{tikzpicture}[Dotted/.style={% https://tex.stackexchange.com/a/52856/194703
    line width=1.2pt,
    dash pattern=on 0.01\pgflinewidth off #1\pgflinewidth,line cap=round,
    shorten >=0.3em,shorten <=0.3em},
    Dotted/.default=5]
 \matrix[matrix of math nodes,nodes={circle,draw,minimum size=1.5em},
    column sep=2em,row sep=1ex](mat) {
    C_1 & D_1 \\
    C_2 & D_2 \\[2em]
    C_m & D_n \\
 };
 \draw[Dotted] (mat-2-1) -- (mat-3-1);
 \draw[Dotted] (mat-2-2) -- (mat-3-2);
 \foreach \X in {1,2,3}
 {\foreach \Y in {1,2,3}
 {\draw (mat-\X-1) -- (mat-\Y-2);}}
 \matrix[matrix of math nodes,nodes={circle,draw,minimum size=1.5em},
    column sep=1em,row sep=1em,below=2em of mat,xshift=2em,
    column 2/.style={column sep=2.5em}](mat2) {
    E_1 & E_2 & E_p\\
    F_1 & F_2 & F_p\\[2em]
    F_1 & F_2 & F_p\\
 };
 \foreach \X in {1,2,3}
 {\draw[Dotted] (mat2-\X-2) -- (mat2-\X-3);
 \draw[Dotted] (mat2-2-\X) -- (mat2-3-\X);}
\end{tikzpicture}
\end{document}

enter image description here