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.

I need to try to replicate a similar structure to this

enter image description here

but am a novice when it comes to tikz. I'm not sure whether to use chains, explicit node positioning, etc. And, in my experience of drawing graphs, I could never get the arrows to bend properly.

This is a problem that is beyond my TeX abilities...

share|improve this question

2 Answers 2

up vote 13 down vote accepted

You can use the following template to finish off and make the final tweaks. I have put two arrows to show how one can adjust the positioning.

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

\begin{document}
\begin{tikzpicture}
\matrix (m) [matrix of nodes,
nodes in empty cells,
nodes={font={\ttfamily}},
column sep=0,row sep=0,
column 1/.style={},
column 2/.style={nodes={text width=1.5cm,align=center}},
column 3/.style={nodes={minimum width=5mm}}
]{
1 &JEFF &\\
2 &AUDREY&\\
3 & & \\
4 &DONNA &\\
5 & & \\[1pt]
(9)  &DAVE &\\
(10)&MARK &\\
(11)&AL &\\
};

\draw (m-1-2.north west) rectangle (m-5-2.south east);
\draw (m-1-2.north east) rectangle (m-5-3.south east);
\draw (m-6-2.north west) rectangle (m-8-2.south east);
\draw (m-6-2.north east) rectangle (m-8-3.south east);

\foreach \x in {1,...,4,6,7} {
\draw (m-\x-2.south west) -- (m-\x-3.south east);
};

\draw[->,rounded corners] (m-2-3.mid) -| ++(1cm,-1cm) |- (m-7-3.east);
\draw[->,rounded corners] (m-3-3.mid) -| ++(1cm,-1cm) |- ([xshift=3mm]m-8-3.east);
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
Wouldn´t we run into trouble when one of those entries had a descender like 'god'? –  bloodworks Jul 23 '12 at 20:05
    
@bloodworks I always run into trouble because of god :P I think I don't understand. –  percusse Jul 23 '12 at 20:07
    
well the part of the letter which extends below the baseline i think they call it descender: en.wikipedia.org/wiki/Descenders So when i relpace JEFF with JEFFg for instance i´ll get angled lines –  bloodworks Jul 23 '12 at 20:15
    
@bloodworks Indeed, then we need to add text depth=x to avoid that. –  percusse Jul 23 '12 at 20:23

User interfaces:

% user defined data
\def\list
{
    Jeff,
    Audrey,
    ,
    Donna,
    A.L.,
    ,
    Tootie,
    ,
    Dave,
    Mark,
    Al
}% list of elements


\const{_X1}{1}% column 1 width
\const{_X2}{2}% column 2 width
\const{_X3}{1}% column 3 width
\const{_X4}{1}% space for arrow arms
\const{_Y}{0.5}% row height

enter image description here

\documentclass[pstricks,border=3pt]{standalone}
\usepackage{pstricks-add,fp}
\psset{dimen=middle}

\makeatletter
\newcommand\const[3][\FPeval]{% #1=method, #2=name, #3=data
   \expandafter#1\csname#2\endcsname{#3}%
   \begingroup\edef\x{\endgroup
     \noexpand\pstVerb{/#2 \csname#2\endcsname\space def}}\x
}

\newcount\const@count
\def\FPnset#1#2{%
  \const@count=\z@
  \@for\next:=#2\do{\advance\const@count\@ne}%
  \edef#1{\number\const@count}%
}
\makeatother

% user defined data
\def\list
{
    Jeff,
    Audrey,
    ,
    Donna,
    A.L.,
    ,
    Tootie,
    ,
    Dave,
    Mark,
    Al
}% list of elements

\const{_X1}{0.6}% column 1 width
\const{_X2}{2}% column 2 width
\const{_X3}{1}% column 3 width
\const{_X4}{1.03}% space for arrow arms
\const{_Y}{0.5}% row height


% internal used constants
\const[\FPnset]{_N}{\list}% number of nodes
\const{_x1}{_X1*0.5}
\const{_x2}{_X1+_X2*0.5}
\const{_x3}{_X1+_X2+_X3*0.5}
\const{_OX1}{_X1}
\const{_OX2}{_X1+_X2}
\const{_OX3}{_X1+_X2+_X3}
\const{_y}{_Y/2}
\const{_OY}{_Y}

\const{CanvasHeight}{_OY*_N}
\const{CanvasWidth}{_OX3+_X4}


\def\node#1#2{%
    \const{counter}{round((#2+1):0)}%   
    \rput(!0 _OY neg counter mul){%
        \psframe(!_OX1 0)(!_OX3 _OY)%
        \rput(!_x1 _y){\counter}
        \rput(!_x2 _y){#1}%
        \psline(!_OX2 0)(!_OX2 _OY)%
        \pnode(!_x3 _y){node\counter}%   
    }}




\begin{document}

\begin{pspicture}(\CanvasWidth,-\CanvasHeight)
    \psforeach{\i}{\list}{\node{\i}{\the\psLoopIndex}}
    \psset
    {
        arrowscale=2,
        dotsize=1pt,
        arrows=*->,
        linearc=\pslinewidth,
        linecolor=blue,
    }
    \ncdiag[arm=1.5]{node2}{node11}
    \ncbar[arm=1]{node5}{node10}
    \ncdiag[arm=0.75,angle=180]{node11}{node9}
\end{pspicture}

\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.