3

I made the following three diagrams with tabular environment in LaTeX.


enter image description here


enter image description here


enter image description here


Now I want to make these diagrams in Tikz ideally with animation and MWE is below:

\documentclass{standalone}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}

\begin{document}


% Define block styles
\tikzstyle{block} = 
    [
        rectangle
      , draw
      , text width=4.5em
      , text centered
      , node distance=0.7cm
      , minimum height=2em
      ]

\tikzstyle{block1} = 
    [
        rectangle
      , text width=4.5em
      , text centered
      , node distance=1.5cm
      , minimum height=2em
      ]


\tikzstyle{line} = 
    [
        draw
     , -latex'
     ]


\begin{tikzpicture}[node distance = 2cm, auto]

  % Place nodes

    \node [block] (A1R1B1) {$B_{1}$};
    \node [block, below of=A1R1B1] (A1R1B2) {$B_{2}$};
    \node [block, below of=A1R1B2] (A1R1B3) {\vdots};
    \node [block, below of=A1R1B3] (A1R1Bb) {$B_{b}$};

    \node [block, right of=A1R1B1] (A1R2B1) {$B_{1}$};
    \node [block, right of=A1R1B2] (A1R2B2) {$B_{2}$};
    \node [block, right of=A1R1B3] (A1R2B3) {\vdots};
    \node [block, right of=A1R1Bb] (A1R2Bb) {$B_{b}$};


    \node [block1, right of=A1R1B1] (A1R3B1) {\ldots};
    \node [block1, right of=A1R1B2] (A1R3B2) {\ldots};
    \node [block1, right of=A1R1B3] (A1R3B3) {\ldots};
    \node [block1, right of=A1R1Bb] (A1R3Bb) {\ldots};

    \node [block, right of=A1R3B1] (A1RrB1) {$B_{1}$};
    \node [block, right of=A1R3B2] (A1RrB2) {$B_{2}$};
    \node [block, right of=A1R3B3] (A1RrB3) {\vdots};
    \node [block, right of=A1R3Bb] (A1RrBb) {$B_{b}$};


\end{tikzpicture}

\end{document}

enter image description here

Any help to get the desired results will be highly appreciated. Thanks

MYaseen208
  • 8,587

1 Answers1

4

There is a tabular like \matrix macro for TikZ.

With a few settings here and there you can easily achieve something like the examples you did with tabular.

Code

\documentclass[tikz,convert=false]{standalone}
\usetikzlibrary{positioning,matrix}
\begin{document}
\begin{tikzpicture}[
  every block/.style={shape=rectangle, text width=2.5em, align=center, font=\strut, text depth=+.1667em},
  block/.style={every block, draw},
  block1/.style={every block, draw=none},
]

  \matrix[
    inner sep=+0pt,outer sep=+0pt,
    matrix of math nodes,
    nodes={block,outer ysep=+0pt,inner ysep=.3333em,outer xsep=.5\pgflinewidth},
    row 1/.style={nodes=block1},
    row 4/.style={nodes=block1},
    column 3/.style={nodes=block1},
    row sep=-\pgflinewidth,
    column sep=-\pgflinewidth
  ] (m) {
    A_1 & A_2 & \cdots & A_a \\
    B_1 & B_2 & \cdots & B_1 \\
    B_2 & B_1 & \cdots & B_2 \\
    \vdots & \vdots & \ddots & \vdots \\
    B_b & B_b & \cdots & B_b \\
  };
  \draw (m-2-2.north east) -- (m-2-4.north west);
  \draw (m.north west) -- (m.north east);
  \node[above=+0pt of m] {\itshape Block 1};
\end{tikzpicture}
\end{document}

Output

enter image description here

Moriambar
  • 11,466
Qrrbrbirlbel
  • 119,821
  • Thanks @Qrrbrbirlbel for you nice answer. Could you guide me how to reuse this m matrix to make right side of the figure? Thanks – MYaseen208 Aug 08 '13 at 14:09
  • @MYaseen208 What do you mean with the right side? All your figures look very similar if not exactly the same. – Qrrbrbirlbel Aug 09 '13 at 00:01