[Tex/LaTex] Drawing graphs with multiline labels for vertex/edge

graphstikz-pgf

I have been using tikz-graph to draw graphs representing two-part protocols. Now I'd like to add comments to some nodes of the graph (multiline text, to the side of the vertex).
I'm not sure how to do that. I have been adding labels to vertices and putting them outside with LabelOut, but then I can't do multiline text. This is a toy/minimalistic example:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows}
\usepackage{tkz-graph}

\usepackage{graphicx}  
\usepackage[T1]{fontenc}

\begin{document}

\begin{tikzpicture}
  \SetUpEdge[lw = 1.5pt,
             color=black,
             labelstyle = {sloped}]
  \SetVertexNoLabel
  \GraphInit[vstyle=Art]
  \tikzset{EdgeStyle/.style={post}}
  \tikzset{node distance = 6 cm}
  \SetVertexMath

  % Two top symbols, displayed as two invisible
  % vertices with visible labels:
  {\tikzset{VertexStyle/.style = {color=white,text=black}}
    \SetVertexLabel
    \Vertex[L=\alpha]{P}
    \SetVertexLabel
    \Vertex[position={right of=P}, L={\beta}]{X}}

  \tikzset{node distance = 1 cm}
  {\SetVertexLabel
   %%%
   %%% HERE: in the next line the label can't be split in two lines...
   \Vertex[LabelOut,Lpos=180,position={below of=P}, L={the protocol starts here}]{X1}
  }
  \tikzset{node distance = 2 cm}
  \SO(X1){X2}
  \SO(X2){X3}
  \tikzset{node distance = 6 cm}

  \EA(X1){A1}
  \EA(X2){A2}
  \Edge[label={220 ESMTP}](X1)(A1)
  \Edge[label={EHLO client-host}](A1)(X2)
  \Edge[label={250 DSN}](X2)(A2)
  \Edge[label={mail from: email-address}](A2)(X3)
\end{tikzpicture}
\end{document}

What wold be the usual, easy way to do what I'm trying to do?

Best Answer

I'm the author of this package. The good news are the new versions of tkz-graph and tkz-berge will be on the ctan servers this week (i'm working on the docs actually), the bad news are that I modified some macros. I'm not sure to understand exactly what you want but an answer is that you can put TikZ's code inside you code.

Vertices are nodes so you can add multiple labels if you want with the option label= , if you want adding a text you can use the option text width

something like :

  \SO(P){X1}
  \node[text width=2cm,left=1cm] (X1){the protocol starts here};

Another possibility :

\begin{tikzpicture}
{  \SetVertexNoLabel   
   \Vertex[style={label=60:A}]{A}}
 \SO[Lpos=180,
     LabelOut,
     L= {the protocol starts here},
     style={text width=2cm}](A){B}
 \end{tikzpicture}

But there are other ways to do this. You can use label. In your code you used "position" , it's not very fine because it's a problem to use "scale".

In 12 hours, I will upload the new version of tkz-graph. I the new version node distanceis obsolete, now I added an option unit and a macro \tkzGraphUnit=6 instead of `\tikzset{node distance=6cm}.