latextikz

How do I align nodes of different heights to the bottom?


The following code

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


\begin{document}
  \begin{figure}
    \centering
    \begin{tikzpicture}[stack/.style={rectangle split, rectangle split parts=#1,draw, anchor=base}]
      \node (s4) [stack=4] {
      \nodepart{one}12
      \nodepart{two}5
      \nodepart{three}97
      \nodepart{four}86
      };
      \node (s5) [stack=5, right=of s4] {
      \nodepart[]{one}42
      \nodepart{two}12
      \nodepart{three}5
      \nodepart{four}97
      \nodepart{five}86
      };
    \end{tikzpicture}
    \caption{Two stacks.}
  \end{figure}
\end{document}

Generates these two stacks, side by side:

tikz image of two stacks

That's fine, but what I need is to have the two stacks align at the bottom rather at vertical center. Any assistance on this would be greatly appreciated.


Solution

  • \documentclass{article}
    \usepackage{tikz}
    \usetikzlibrary{shapes.multipart,chains,positioning}
    
    
    \begin{document}
      \begin{figure}
        \centering
        \begin{tikzpicture}[stack/.style={rectangle split, rectangle split parts=#1,draw}]
          \node (s4) [stack=4] {
          \nodepart{one}12
          \nodepart{two}5
          \nodepart{three}97
          \nodepart{four}86
          };
          \node[right=of s4.south,anchor=south] (s5) [stack=5] {
          \nodepart[]{one}42
          \nodepart{two}12
          \nodepart{three}5
          \nodepart{four}97
          \nodepart{five}86
          };
        \end{tikzpicture}
        \caption{Two stacks.}
      \end{figure}
    \end{document}
    

    enter image description here