Drawing stacks side-by-side in LaTeX

To place additional stacks just portion the new nodes appropriately:

enter image description here

Code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}

\begin{document}
\begin{tikzpicture}[
    stack/.style={rectangle split, rectangle split parts=#1,draw, anchor=center}
]

\node[stack=5] (A) {
    \nodepart{two}a
    \nodepart{three}b
    \nodepart{four}c
    \nodepart{five}d
};
\node[stack=5, right of=A] (B) {
    \nodepart{two}a
    \nodepart{three}b
    \nodepart{four}c
    \nodepart{five}d
};
\node[stack=5, right of=B] (C) {
    \nodepart{two}a
    \nodepart{three}b
    \nodepart{four}c
    \nodepart{five}d
};
\node[stack=5, right of=C] (D) {
    \nodepart{two}a
    \nodepart{three}b
    \nodepart{four}c
    \nodepart{five}d
};

\end{tikzpicture}%
\end{document}

with library matrix:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix, positioning}


\begin{document}
    \begin{tikzpicture}[node distance=1cm]
\matrix (m) [matrix of nodes,
             nodes={draw, minimum width=1.5em, minimum height=2ex, outer sep=0pt},
             row sep    = -\pgflinewidth,
             column sep = -\pgflinewidth % <--- as matrix
             ]
{   a   &   a   &   a   &   a   \\
    b   &   b   &   b   &   b   \\
    c   &   c   &   c   &   c   \\
    d   &   d   &   d   &   d   \\
};
\matrix (n) [right=of m,
             matrix of nodes,
             nodes={draw, minimum width=1.5em, minimum height=2ex, outer sep=0pt},
             row sep    = -\pgflinewidth,
             column sep = 2em  % <--- as separate stacks
             ]
{   a   &   a   &   a   &   a   \\
    b   &   b   &   b   &   b   \\
    c   &   c   &   c   &   c   \\
    d   &   d   &   d   &   d   \\
};
    \end{tikzpicture}
\end{document}

enter image description here


Really just 4 fun (and to answer a TikZ question with a non-TikZ answer, usually I am doing the opposite ;-).

\documentclass{article}
\usepackage{youngtab}
\begin{document}
\young(~,a,b,c,~)\quad\young(~,a,b,c,~)\quad\young(~,a,b,c,~)\quad\young(~,a,b,c,~)
\end{document}

enter image description here

Tags:

Stack

Tikz Pgf