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.

Possible Duplicate:
How should I draw a singly/double linked list?

I am currently trying to create an image of a linked list like this one: enter image description here

This is my current try:

enter image description here

What I miss is the dot at the start of the arrow and the second box for each list element.

This is my try:

\documentclass{article}
\usepackage[pdftex,active,tightpage]{preview}
\setlength\PreviewBorder{2mm}

\usepackage{tikz}
\usetikzlibrary{trees,arrows,positioning, calc} 

\tikzset{
    squarecross/.style={
        draw, fill=black!20, rectangle,minimum size=18pt,
        inner sep=0pt, text=black,
        path picture = {
            \draw[black]
            (path picture bounding box.north west) -- 
            (path picture bounding box.south east) --
            (path picture bounding box.south west) -- 
            (path picture bounding box.north east);
        }
    },
    listelement/.style={
        draw, fill=black!20, rectangle,minimum size=18pt,
        inner sep=0pt, text=black,
        path picture = {% 
            \draw[black]
            ($(path picture bounding box.north west)$) --
            ($(path picture bounding box.north west)+(1,0)$) --
            ($(path picture bounding box.south west)+(1,0)$) -- 
            ($(path picture bounding box.south west)$);
        }
    }
}

\usetikzlibrary{trees,arrows,positioning, calc}

\begin{document}
\begin{preview}
\begin{tikzpicture}[font=\sffamily,very thick]
\node [listelement] (a) {12};
\node [listelement] (b) [right=of a] {99};
\node [listelement] (c) [right=of b] {37};
\node [squarecross] (d) [right=of c] {};
\draw [->] (a) -- (b);
\draw [->] (b) -- (c);
\draw [->] (c) -- (d);
\end{tikzpicture}
\end{preview}
\end{document}

How can I make it work? Why does the following part not work?

path picture = {% 
    \draw[black]
    ($(path picture bounding box.north west)$) --
    ($(path picture bounding box.north west)+(1,0)$) --
    ($(path picture bounding box.south west)+(1,0)$) -- 
    ($(path picture bounding box.south west)$);
}
share|improve this question

marked as duplicate by Count Zero, Gonzalo Medina, percusse, Jake, moose Jul 21 '12 at 21:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Thanks, I've just noticed it. Linked List of course. I've corrected it. –  moose Jul 21 '12 at 20:27
    
Look at this answer to How should I draw a singly/double linked list? for a solution using multipart rectangles. –  Gonzalo Medina Jul 21 '12 at 20:28
    
Thank you. I didn't find it, as I've searched for "nested list" instead of "linked list" all the time :-/ –  moose Jul 21 '12 at 20:29
    
Then we can close it as a duplicate? –  Count Zero Jul 21 '12 at 20:31
    
Yes, this topic can be closed. It wasn't directly answered, but the solution is better than a direct answer. - edit: Now it has also been answered. I love this website :-) –  moose Jul 21 '12 at 20:38
add comment

1 Answer

up vote 1 down vote accepted

The path picture is used to put a picture inside the path region so when you draw something out of the path region they are clipped out. Just to illustrate the scaling

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc} 

\tikzset{
    listelement/.style={
        draw, fill=black!20, rectangle,minimum size=5mm,
        inner sep=0pt, text=black,
        path picture = {%
        \pgftransformscale{3}
            \draw[black]
            ($(path picture bounding box.north west)$) rectangle ++(1mm,-1mm);
        }
    }
}
\begin{document}
\begin{tikzpicture}[font=\sffamily,very thick]
\node [listelement] (a) {12};
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
add comment

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