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.

The node/child layout of the trees allows to break node text into multiple lines. I tried the same with graph but luaLatex compilation never completed (using Texmaker) and I had to stop it, which produced errors such as Undefined control sequence \\

Is it possible to break node text with graphs too?

\documentclass[10pt,landscape,letterpaper]{article}
\usepackage{tikz}

\usetikzlibrary{graphs, graphdrawing}
\usegdlibrary{trees, layered}

\begin{document}

\begin{tikzpicture}
\graph [
    binary tree layout,
    sibling distance=4mm,
    level distance=8mm,
    components go right top aligned,
    component sep=1pt,
    nodes=draw
]
{
    Supervisor
    -- Current Employee %\\ Current Employee Position
        -- {
            Subordinate 1--{Worker 01,Worker 02},
            Subordinate 2--{SubSubordinate 21--{Worker 21,Worker 22,Worker 23}
        },
        Subordinate 3-- SubSubordinate01--{Worker 11,Worker 12}
    };
};
\end{tikzpicture}
\end{document}

The above MWE works, but if I removed the comment, it would not...

The purpose of this MWE is to avoid having to do lots of node size and position calculations for the org chart I am working on.

EDIT:

Just to clarify, it seems that node text in the graph layout is directly used as a node name for the purposes of linking nodes together, aligning layers/levels etc, thus new lines and even comas break the compilation.

It appears as graph layout is in very beta state at the moment, usable only for the very simplistic one-two word nodes with no punctuation involving new lines or comas :(

I'll try to bring this to Till's attention on Sourceforge, let's see what comes out of that.

share|improve this question
    
try enclosing it in braces, perhaps –  Sean Allred May 27 at 19:27
    
Nope :( Same error. I guess that has to do with the fact that in graphs node text is also node name for all purposes... I even tried putting a node in there to no avail. Ultimately, I wanted to be able to include pictures into the graph nodes, but this seems to be not supported. –  ajeh May 27 at 19:29
    
Ah, that actually makes a lot of sense. I'm not really an expert in the graph drawing library, but I don't think there is a way to get around this limitation yet. I may very well be wrong, though :) –  Sean Allred May 27 at 19:30
1  
Yes, seeing how graph drawing library made its way into PGF from a student's thesis, it is no surprise that this technology is in the emerging state at the moment. There should be separate node name and node text at the very least for this to be versatile and useful. Still an amazing technology for which credit is due! –  ajeh May 27 at 19:33

1 Answer 1

up vote 5 down vote accepted

Use

"Current Employee \\ Current Employee Position"[align=center]

or

CE[as={Current Employee \\ Current Employee Position},align=center]

or

CE/"Current Employee \\ Current Employee Position"[align=center]

where CE is the node name.

enter image description here

Code:

\documentclass[10pt,landscape,letterpaper]{article}
\usepackage{tikz}

\usetikzlibrary{graphs, graphdrawing}
\usegdlibrary{trees, layered}

\begin{document}

\begin{tikzpicture}
\graph [
    binary tree layout,
    sibling distance=4mm,
    level distance=8mm,
    components go right top aligned,
    component sep=1pt,
    nodes=draw
]
{
    Supervisor
    -- CE[as={Current Employee \\ Current Employee Position},align=center]
        -- {
            Subordinate 1--{Worker 01,Worker 02},
            Subordinate 2--{SubSubordinate 21--{Worker 21,Worker 22,Worker 23}
        },
        Subordinate 3-- SubSubordinate01--{Worker 11,Worker 12}
    };
};
\end{tikzpicture}
\end{document}

You can also insert an Image side by side to this node text:

\documentclass[10pt,landscape,letterpaper]{article}
\usepackage{tikz}
\usetikzlibrary{graphs, graphdrawing}
\usegdlibrary{trees, layered}

\usepackage{varwidth}

\usepackage{mwe}% example image

\begin{document}

\begin{tikzpicture}
\graph [
    binary tree layout,
    sibling distance=4mm,
    level distance=8mm,
    components go right top aligned,
    component sep=1pt,
    nodes=draw
]
{
    Supervisor
    -- CE[as={%
          \begin{varwidth}[b]{.5\linewidth}
            \centering Current Employee \\ Current Employee Position
          \end{varwidth}
          \includegraphics[height=1.5\baselineskip]{example-image}}
       ]
        -- {
            Subordinate 1--{Worker 01,Worker 02},
            Subordinate 2--{SubSubordinate 21--{Worker 21,Worker 22,Worker 23}
        },
        Subordinate 3-- SubSubordinate01--{Worker 11,Worker 12}
    };
};
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
Thanks! Where is this documented? Is it possible to include the images into the nodes similarly? –  ajeh May 27 at 19:52
1  
In the pgfmanual ;-) The Option as= for example on page 270. –  esdd May 27 at 19:58
    
includegraphics seems to work, but not being figure –  ajeh May 27 at 20:00
2  
@ajeh Do you mean \begin{figure}..\end{figure}? Why would you want to use a floating environment inside a tree? (In other words: Don't. Just add \includegraphics{image} directly, as you have already found that works.) –  Torbjørn T. May 27 at 20:23
1  
@ajeh I have added an example with an image side by side to the text in this node. –  esdd May 27 at 23:34

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.