Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Ok. I'm trying to make the left look like the right. I'm kinda lost here. Suggestions?

tikz word

\documentclass{article}

\usepackage{tikz}
\usepackage[margin=0.5in]{geometry}
\pagestyle{empty}

\begin{document}

%\input{../tikz-setup.tex}
\usetikzlibrary{shapes, arrows, calc, positioning, matrix }

% Define block styles
\tikzstyle{line}    = [ draw, -triangle 45 ]

\tikzstyle{list}  = [ rectangle, draw,
                        minimum width = 6em                      
                      ]

\tikzstyle{ptr-box}  = [ rectangle, 
                        text width = 8em                      
                      ]

\begin{center}
\begin{tikzpicture}[align = flush center, font = \small]
% Place nodes
    \matrix [matrix of nodes, row sep = 0em] (age)
    {    
    |[list] (free)| Free Page \\    
    |[list] (free2)| Free Page \\    
    |[list] (pg6)| Page 6 \\    
    |[list] (pg12)| Page 12 \\
    |[list] (pg4)| Page 4 \\
    |[list] (pg8)| Page 8 \\
    };

    \matrix [matrix of nodes, row sep = 0em, 
                 left = of age, 
                 nodes={text width=6em},
                 matrix anchor = north east,
                 ] (ptr) at (age.north west)
    {    
    |[ptr-box, ] (oldest)| \textbf{oldest\_ptr} \\ \tiny{Points to pool of free pages.}  \\
    |[ptr-box] (oldest-valid)| \textbf{oldest\_valid\_ptr} \\ \tiny{Points to oldest vaild cache page, else NULL if cache is empty.}  \\
    |[ptr-box] (newest)|\textbf{newest\_ptr} \\ \tiny{Points to newest vaild cache page.}  \\
    };           

    % Draw edges
    \path [line] (oldest) -- (free);
    \path [line] (oldest-valid) -- (pg6);
    \path [line] (newest) -- (pg8);


\end{tikzpicture}
\end{center}
\end{document}
share|improve this question
    
I updated my answer with another option. –  Gonzalo Medina Sep 13 '12 at 22:08

2 Answers 2

up vote 4 down vote accepted

One option would be to use \parboxes for the nodes containing the text:

\documentclass{article}

\usepackage{tikz}
\usepackage[margin=0.5in]{geometry}
\pagestyle{empty}

\begin{document}

%\input{../tikz-setup.tex}
\usetikzlibrary{shapes, arrows, calc, positioning, matrix }

% Define block styles
\tikzstyle{line}    = [ draw, -triangle 45 ]

\tikzstyle{list}  = [ rectangle, draw,
                        minimum width = 6em                      
                      ]

\tikzstyle{ptr-box}  = [ rectangle, 
                        text width = 30em , font=\tiny                     
                      ]

\begin{center}
\begin{tikzpicture}[align = flush center, font = \small]
% Place nodes
    \matrix [matrix of nodes, row sep = 0em] (age)
    {    
    |[list] (free)| Free Page \\    
    |[list] (free2)| Free Page \\    
    |[list] (pg6)| Page 6 \\    
    |[list] (pg12)| Page 12 \\
    |[list] (pg4)| Page 4 \\
    |[list] (pg8)| Page 8 \\
    };

\node [left=of free,text depth=0ex]  (oldest) {\parbox[t]{8em}{\centering%
  \textbf{oldest\_ptr} \\ \tiny  Points to pool of free pages.}};
\node [left=of pg6,text depth=0ex]  (oldest-valid) {\parbox[t]{8em}{\centering%
  \textbf{oldest\_valid\_ptr} \\ \tiny Points to oldest vaild cache page, else NULL if cache is empty.}};
\node [left=of pg8,text depth=0ex] (newest) {\parbox[t]{8em}{\centering%
  \textbf{newest\_ptr} \\ \tiny Points to newest vaild cache page.}};           

    % Draw edges
    \path [line] (oldest) -- (free);
    \path [line] (oldest-valid) -- (pg6);
    \path [line] (newest) -- (pg8);
\end{tikzpicture}
\end{center}

\end{document}

enter image description here

Another option would be to use a style with the appropriate options for the text nodes:

\documentclass{article}
\usepackage{tikz}
\usepackage[margin=0.5in]{geometry}
\usetikzlibrary{shapes, arrows, calc, positioning, matrix }

\pagestyle{empty}

\begin{document}


% Define block styles
\tikzstyle{line}    = [ draw, -triangle 45 ]

\tikzstyle{list}  = [ rectangle, draw,
                        minimum width = 6em                      
                      ]

\tikzstyle{ptr-box}  = [ rectangle, 
                        text width = 30em , font=\tiny                     
                      ]

\begin{center}
\begin{tikzpicture}[align = flush center, font = \small]
% Place nodes
    \matrix [matrix of nodes, row sep = 0em] (age)
    {    
    |[list] (free)| Free Page \\    
    |[list] (free2)| Free Page \\    
    |[list] (pg6)| Page 6 \\    
    |[list] (pg12)| Page 12 \\
    |[list] (pg4)| Page 4 \\
    |[list] (pg8)| Page 8 \\
    };

\begin{scope}[
mytext/.style={
  align=center, font=\tiny,xshift=-1em,anchor=north east,inner ysep=-1ex}
]
\node [left=of free,mytext]  (oldest) {%
  {\small\bfseries oldest\_ptr} \\ Points to pool of \\ free pages.};
\node [left=of pg6,mytext]  (oldest-valid) {%
  {\small\bfseries oldest\_valid\_ptr} \\ Points to oldest vaild \\ cache page, else NULL if \\ cache is empty.};
\node [left=of pg8,mytext] (newest) {%
  {\small\bfseries newest\_ptr} \\ Points to newest vaild \\ cache page.};           
\end{scope}

    % Draw edges
    \path [line] (oldest.north east) -- (free);
    \path [line] (oldest-valid.north east) -- (pg6);
    \path [line] (newest.north east) -- (pg8);
\end{tikzpicture}
\end{center}

\end{document}

enter image description here

By the way, \tiny doesn't receive arguments; it's a declaration.

share|improve this answer
1  
Rather than using \parbox and \centering, it seems easier to add the options text width=8em and align=center to each node (or via a re-usable style) –  Paul Gaborit Sep 13 '12 at 21:33
    
@PaulGaborit perhaps it's shorter that way; I'll add it to my answer. –  Gonzalo Medina Sep 13 '12 at 21:45

Here is a possibility (I modified your example to use \tikzset instead of oldest \tikzstyle: Should \tikzset or \tikzstyle be used to define TikZ styles?):

enter image description here

\documentclass{standalone}
\usepackage{tikz}

% \input{../tikz-setup.tex}
\usetikzlibrary{shapes, arrows, calc, positioning, matrix }

% Define block styles
\tikzset{
  line/.style = { draw, -triangle 45 },
  list/.style = { rectangle, draw, minimum width = 6em },
  ptr-box/.style  = { rectangle, text width = 30em , font=\tiny },
  comment/.style = {text width=2.5cm, align=center,inner ysep=0},
  note/.style = {font=\tiny,align=center,text width=2.5cm,inner ysep=0},
}
\begin{document}
\begin{tikzpicture}[align=flush center,font=\small]
  % Place nodes
  \matrix [matrix of nodes, row sep = 0em] (age)
  {    
    |[list] (free)| Free Page \\    
    |[list] (free2)| Free Page \\    
    |[list] (pg6)| Page 6 \\    
    |[list] (pg12)| Page 12 \\
    |[list] (pg4)| Page 4 \\
    |[list] (pg8)| Page 8 \\
  };

  \node [left=of free, comment]  (oldest) {\textbf{oldest\_ptr}};
  \node [below=1pt of oldest,note]{Points to pool of free pages.};

  \node [left=of pg6, comment]  (oldest-valid) {\textbf{oldest\_valid\_ptr}};
  \node [below=1pt of oldest-valid,note]
  {Points to oldest valid cache page, else NULL if cache is empty};

  \node [left=of pg8,comment] (newest) {\textbf{newest\_ptr}};
  \node [below=1pt of newest,note]{Points to newest vaild cache page.};           

  % Draw edges
  \path [line] (oldest) -- (free);
  \path [line] (oldest-valid) -- (pg6);
  \path [line] (newest) -- (pg8);
\end{tikzpicture}
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.