9

I wanted to create a node with vertical and horizontal parts. So after some searching I found that I can achieve this by using a matrix. I tried the code below:

\documentclass{article}
\usepackage{tikz,listings}
\usetikzlibrary{shapes.multipart,matrix}
\begin{document}
\begin{tikzpicture}[->, my shape/.style={
rectangle split, rectangle split parts=#1, draw, anchor=center}]

%transactional descriptor
 \node[matrix, align=center, label=above:transactional descriptor] (up_part) at (7, 0) {
        \node [my shape=4, rectangle split horizontal] (up_line) at (3, 0) 
        {\nodepart{one}\lstinline!start!\nodepart{two}\lstinline!readSet!\nodepart{three}
          \lstinline!writeSet!\nodepart{four}\lstinline!commitTime!}; \\
    };
    \node[matrix, below of=up_part, node distance=0.5cm] (down_part) 
    {
        \node [my shape=2, rectangle split horizontal] (down_line) at (3, 0) 
        {\nodepart{one}\lstinline!overwrittenVersions!\quad\nodepart{two}\lstinline!next!}; \\
   };
\end{tikzpicture}

\end{document}

the problem is that the second node containing 2 parts has not the same width as the the node from above it, as you can see in the picture below: enter image description here

I tried using minimum width or text width but didn't work.

Any ideas how to fix this?

foobar
  • 913
  • The use of matrix library is not doing actually what you are aiming for since every matrix has one cell. What's the positioning that you are after ultimately? – percusse Jul 23 '12 at 18:39
  • @percusse I don't really understand what you area saying? Could you please explain a little more? I just want to have the second line extended so it has the same width as the first one. – foobar Jul 23 '12 at 18:43
  • @percusse I don't really care how. I just want them aligned :S. Well, I'm a newbie at tikz, so I don't really understand. But I guess any solution will do – foobar Jul 23 '12 at 18:56
  • yes, I want the second line to be stretched to fit the first line. The size of the first line is OK – foobar Jul 23 '12 at 19:04

2 Answers2

11

Unless you really need each element to be an actual TikZ node, it might be simpler to use a simple tabular for this:

\documentclass{article}
\usepackage{tikz,listings}
\usepackage{array}
\newcolumntype{C}{>{\ttfamily}c}
\usetikzlibrary{shapes.multipart,matrix}
\begin{document}
\begin{tikzpicture}[->, my shape/.style={
rectangle split, rectangle split parts=#1, draw, anchor=center}]

%transactional descriptor
\node (A) {%
\begin{tabular}{|C|C|C|C|}
\hline
start & readSet & writeSet & commitTime\\
\hline
\multicolumn{3}{|C|}{overwrittenVersions} & next\\
\hline
\end{tabular}
};
\end{tikzpicture}

\end{document}

output of code

Alan Munn
  • 218,180
  • @Alan Munn thanks for answering. I actually need the elements to be nodes as I want to create paths from the next or overwrittenVersions part to other nodes – foobar Jul 24 '12 at 20:09
9

Something like this?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{chains,calc}

\begin{document}
\usetikzlibrary{chains,calc}
\begin{tikzpicture}[start chain,node distance=0mm,every node/.style={font=\ttfamily,outer sep=0,text height=1.5ex}]
\node [draw,on chain] (a) {start};
\node [draw,on chain] {readSet};
\node [draw,on chain] {writeSet};
\node [draw,on chain] (b) {commitTime};

\node[draw,anchor=north west] at (a.south west) (c) {overwrittenVersions};
\path 
let \p1=(c.east),\p2=(b.east),\n1={(\x2-\x1)} 
in 
node[draw,anchor=west,minimum width=\n1] at (c.east) {next};
\end{tikzpicture}
\end{document}

enter image description here

percusse
  • 157,807
  • Thanks! This was what I was looking for. Do you perhaps mind explain all this on chain, anchor ...? Or suggesting what to read in order to understand them? – foobar Jul 24 '12 at 20:13
  • @equality I have tried to explain the anchor part in this answer: http://tex.stackexchange.com/a/63469/3235 But chains library needs to be introduced from the manual. The manual is actually my only guide for TikZ-related issues (other than the source code itself whenever I can understand) – percusse Jul 24 '12 at 22:42