Code: Select all
Before After
_________ _________ __________ ___________
|N Stack | | O Stack | | N Stack | | O Stack |
---------- ---------- ----------- -----------
| Value1 | | Object1 | | | | Object2 |
---------- ----------- ----> ----------- -----------
| Value2 |
----------
I need to avoid using any specific measurements because eventually these diagrams will be automatically generated by a script. Getting the script to figure out how large each element should be would be a nightmare, and would something I would expect our layout package to do for us.
I've tried doing this with tables within minipages (and then varwidth):
Code: Select all
\begin{table}[ht]
\small
\begin{varwidth}[t]{0.5\linewidth}\centering
\begin{tabular}{|c|}
\hline
\textbf{N}\\
\hline
N1\\
\hline
N2\\
\hline
\end{tabular}
\end{varwidth}
\hspace{0.5cm}
\begin{varwidth}[t]{0.5\linewidth}
\centering
\begin{tabular}{|c|}
\hline
\textbf{O}\\
\hline
O1\\
\hline
\end{tabular}
\end{varwidth}
\end{table}
Next, I tried using several graphics packages. I tried using the Dot-notation used by Graphviz, since MikTeX seems to work OK with it. Unfortunately, it has the same issue... you cannot top-align nodes in Graphviz... it lays them out the way it wants.
Finally, I turned to PGF/Tikz, since it seemed really powerful, and capable of of just about anything.
Code: Select all
\begin{tikzpicture}
\node[rectangle split, rectangle split parts=2, draw, anchor=north, text width=5em] (n1)
{N
\nodepart{second}
N1 \\
N2
};
\node[fill=green!65!black, single arrow, draw, right=of n1] (arrow) {};
\node[rectangle split, rectangle split parts=2, draw, anchor=north, right=of arrow] (n2)
{N
\nodepart{second}
N3
};
\end{tikzpicture}
\begin{tikzpicture}[start chain, every node/.style={draw} text node part/.style={text centered}]
\node[on chain, rectangle split, rectangle split parts=2, draw, text width=1cm] (n1)
{N
\nodepart{second}
N1\\
N2
};
\node[on chain, rectangle split, rectangle split parts=2, draw] (o1)
{O
\nodepart{second}
O1
};
\begin{scope}[start branch=arrow]
\node[fill=green!65!black, single arrow, draw, on chain=going below right] (arrow) {};
\end{scope}
\node[on chain, rectangle split, rectangle split parts=2, draw] (n2)
{N
\nodepart{second}
N3
};
\node[on chain,rectangle split, rectangle split parts=2, draw] (o2)
{O
\nodepart{second}
O2
};
\end{tikzpicture}
\vspace{1in}
\begin{tikzpicture}
\matrix[draw,column sep=10pt, anchor=north] (before)
{
\node[rectangle split,
rectangle split parts=2,
rectangle split part fill={gray!20, white!100},
draw,
anchor=north] (n1)
{N
\nodepart{second}
N1 % can't use \\ here because tikz will think it's the end of the matrix row
Bar
};
&
\node[rectangle split,
rectangle split parts=2,
rectangle split part fill={gray!20, white!100},
draw,
anchor=north] (o1)
{O
\nodepart{second}
LargeObjectName
};
&
\node[fill=green!65!black, single arrow, draw, minimum height=20pt, below=10pt] (arrow) {};
&
\node[rectangle split,
rectangle split parts=2,
rectangle split part fill={gray!20, white!100},
draw,
anchor=north] (n2)
{N
\nodepart{second}
N3
};
&
\node[rectangle split,
rectangle split parts=2,
rectangle split part fill={gray!20, white!100},
draw,
anchor=north] (o2)
{O
\nodepart{second}
LargeObjectName
};
\\
};
\end{tikzpicture}
Unfortunately, it has the a large number of blind spots that prevent me from doing what I need to do:
- Using relatively aligned nodes or nodes on a chain results in the nodes being aligned along their centers, not by their tops, even if I tell them to anchor to their "north point." I can't seem to find any option that will align nodes by anything other than their centerpoints. I can manually add fudge factors to get a specific diagram to line up, but that's not an option with the automatically generated diagrams.
- Sticking the nodes into a matrix does solve the alignment problem.... but it breaks the ability to insert linebreaks into the text, which I need to use show the contents of the stacks one on top of the other.