0

I'm trying to draw something like this :

enter image description here

I have created matrix normally, from here :

\begin{bmatrix}
x_{11}       & x_{12} & x_{13} & \dots & x_{1n} \\
x_{21}       & x_{22} & x_{23} & \dots & x_{2n} \\
\hdotsfor{5} \\
x_{d1}       & x_{d2} & x_{d3} & \dots & x_{dn}
\end{bmatrix}

But it doesn't give that 3D feeling and how can I create the those line between those matrices.

6

Welcome! You can use tikz-3dplot to install a view and the 3d library of TikZ, which automatically gets loaded, to project the matrices on some planes.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{65}{60}
\begin{tikzpicture}[tdplot_main_coords]
\begin{scope}[canvas is xz plane at y=2,transform shape]
 \node[inner xsep=-3pt,inner ysep=-0.3pt] (mat1){$\displaystyle
  \begin{bmatrix}
  x_{11}       & x_{12} \\
  x_{21}       & x_{22}  \\
  \end{bmatrix}$};
\end{scope}
%
\begin{scope}[canvas is xz plane at y=0,transform shape]
 \node[inner xsep=-4pt,inner ysep=-0.3pt] (mat2){$\displaystyle
  \begin{bmatrix}
  x_{11}       & x_{12} & x_{13} & \dots & x_{1n} \\
  x_{21}       & x_{22} & x_{23} & \dots & x_{2n} \\
  \hdotsfor{5} \\
  x_{d1}       & x_{d2} & x_{d3} & \dots & x_{dn}
  \end{bmatrix}$};
\end{scope}
\foreach \Y in {south,north} {\foreach \X in {west,east}
{\draw (mat1.\Y\space\X)  -- (mat2.\Y\space\X);}}
\end{tikzpicture}
\end{document}

enter image description here

One can also install the background pattern.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{backgrounds}
\begin{document}
\tdplotsetmaincoords{65}{60}
\begin{tikzpicture}[tdplot_main_coords]
\begin{scope}[canvas is xz plane at y=2,transform shape]
 \node[inner xsep=-3pt,inner ysep=-0.3pt] (mat1){$\displaystyle
  \begin{bmatrix}
  x_{11}       & x_{12} \\
  x_{21}       & x_{22}  \\
  \end{bmatrix}$};
\end{scope}
%
\begin{scope}[canvas is xz plane at y=0,transform shape]
 \node[inner xsep=-4pt,inner ysep=-0.3pt] (mat2){$\displaystyle
  \begin{bmatrix}
  x_{11}       & x_{12} & x_{13} & x_{14} \\
  x_{21}       & x_{22} & x_{23} & x_{24} \\
  x_{31}       & x_{32} & x_{33} & x_{34} \\
  x_{41}       & x_{42} & x_{43} & x_{44} \\
  \end{bmatrix}$};
\end{scope}
%
\begin{scope}[on background layer]
 \foreach \Y in {south,north} {\foreach \X in {west,east}
 {\draw (mat1.\Y\space\X)  -- (mat2.\Y\space\X);}}
 \foreach \X in {1,2}
 {\fill[blue!20] (mat\X.west)  -- (mat\X.east) -- (mat\X.south east) 
  -- (mat\X.south) -- (mat\X.north) -- (mat\X.north west) -- cycle; }
\end{scope} 
\end{tikzpicture}
\end{document}

enter image description here

You seem to have problems with installing tikz-3dplot. While there should not be a problem, here is a possible workaround. Save this file as tikzlibrary3dtools.code.tex in the same directory as the file you are compiling. Then this should work, too:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{backgrounds,3d,3dtools}
\begin{document}
\begin{tikzpicture}[3d/install view={phi=70,psi=0,theta=70}]
\begin{scope}[canvas is xz plane at y=2,transform shape]
 \node[inner xsep=-3pt,inner ysep=-0.3pt] (mat1){$\displaystyle
  \begin{bmatrix}
  x_{11}       & x_{12} \\
  x_{21}       & x_{22}  \\
  \end{bmatrix}$};
\end{scope}
%
\begin{scope}[canvas is xz plane at y=0,transform shape]
 \node[inner xsep=-4pt,inner ysep=-0.3pt] (mat2){$\displaystyle
  \begin{bmatrix}
  x_{11}       & x_{12} & x_{13} & x_{14} \\
  x_{21}       & x_{22} & x_{23} & x_{24} \\
  x_{31}       & x_{32} & x_{33} & x_{34} \\
  x_{41}       & x_{42} & x_{43} & x_{44} \\
  \end{bmatrix}$};
\end{scope}
%
\begin{scope}[on background layer]
 \foreach \Y in {south,north} {\foreach \X in {west,east}
 {\draw (mat1.\Y\space\X)  -- (mat2.\Y\space\X);}}
 \foreach \X in {1,2}
 {\fill[blue!20] (mat\X.west)  -- (mat\X.east) -- (mat\X.south east) 
  -- (mat\X.south) -- (mat\X.north) -- (mat\X.north west) -- cycle; }
\end{scope} 
\end{tikzpicture}
\end{document}

Notice that the conventions for the angles may change in future revisions of the library. The problem is that different packages follow different conventions, which applies to e.g. tikz-3dplot and pgfplots. It is not clear what the "best" convention is. However, translating between these conventions is a pain.

3
  • Found it here. I couldn't install it : **LaTeX Error File `tikz-3dplot.sty' not found. Type X to quit or <RETURN> to proceed, or enter new name. (Default extension: sty) Enter file name: ** Oct 4 '19 at 8:04
  • @MaifeeUlAsad AFAIK tikz-3dplot is par of any standard TeX installation. How did you install LaTeX? Note that I am only using it to install a view, so in principle one could achieve the result also by installing the view with e.g. this experimental library.
    – user194703
    Oct 4 '19 at 14:55
  • I installed TeXworkd and that isntalled MiKtex.. Oct 8 '19 at 10:56

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.