2

I'm completely new to tikz and try to draw a tree structure.

I have tried different options, but could not modify it as I wanted it to look like.
It currently looks like that:

Tikz code

\documentclass{article}

\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{trees} % this is to allow the fork right path

\usepackage[utf8]{inputenc}

\begin{document}

\begin{tikzpicture}[grow'=right,sibling distance=0.1cm]
  \tikzstyle{level 1} = [level distance=3cm, text width = 2cm]
  \tikzstyle{level 2} = [level distance=3cm, text width = 2cm]
  \tikzstyle{level 3} = [level distance=3cm, text width = 2cm]
\Tree 
    [
    [.{Pressen}
            [.{uniaxiales Pressen} ]
            [.{isostatisches Pressen} ]
            [.{Vibrationspressen} ]
            [.{Stampfen} ]
        ]
        [.{Plastisches Formen}
            [.{Extrudieren} ]
            [.{Drehen} ]
        ] 
        [.Gießen 
            [.{Schlickergießen} ]
            [.{Druckgießen} ]
            [.{Spritzgießen} ]
            [.{Foliengießen} ]
]
    ]
\end{tikzpicture}
\end{document}

The resulting pdf output:

(red line drawn by hand, see below)

enter image description here

I'd like to achieve the following

  • linebreak in node "Plastisches Formen"
  • edges not straight but horizontal/vertical - like sketched in red for one edge
  • text of each level aligned left
  • is it possible to adjust the level distances automatically to the width of the largest node in the level, so that I do not have to set "level distance" by hand?
4

If forest is an option:

\documentclass[tikz,border=3mm]{standalone}

\usepackage{forest}
\usepackage[utf8]{inputenc}

\begin{document}

\begin{forest}
for tree={grow'=0,
anchor=west, child anchor=west, fit=band, parent anchor=east, edge path={\noexpand\path[\forestoption{edge}](!u.parent anchor)|-(.child anchor)\forestoption{edge label};}, l sep=1cm,}
[, calign=child,  calign child=2
    [Pressen
           [uniaxiales Pressen]
            [isostatisches Pressen]
            [Vibrationspressen]
            [Stampfen]
        ]
        [Plastisches\\Formen, align=center
            [Extrudieren]
            [Drehen]
        ] 
        [Gießen 
            [Schlickergießen ]
            [Druckgießen ]
            [Spritzgießen ]
            [Foliengießen ]
]
    ]
\end{forest}
\end{document}

enter image description here

2nd version:

I'm not sure to understand what all nodes "raggedright" means, but may be option align=right does it.

The other comment about aligning all same level nodes can be done with tier/.pgfmath=level() option.

\documentclass[tikz,border=3mm]{standalone}

\usepackage{forest}
\usepackage[utf8]{inputenc}

\begin{document}

\begin{forest}
for tree={grow'=0, l=0, l sep=2em, 
         child anchor=west, anchor=west,  
          parent anchor=east, 
          tier/.pgfmath=level(),
          align=right,
          edge path={\noexpand\path[\forestoption{edge}](!u.parent anchor)|-(.child anchor)\forestoption{edge label};},
          }
[, calign=child,  calign child=2
    [Pressen
           [uniaxiales\\ Pressen]
            [isostatisches Pressen]
            [Vibrationspressen]
            [Stampfen]
        ]
        [Plastisches\\Formen
            [Extrudieren]
            [Drehen]
        ] 
        [Gießen 
            [Schlickergießen ]
            [Druckgießen ]
            [Spritzgießen ]
            [Foliengießen ]
]
    ]
\end{forest}
\end{document}

enter image description here

  • thanks a lot - that looks quite nice already. However, how can I get the text of all nodes "raggedright" and all texts of level 2 aligned left on the same vertical line? – MostlyHarmless Mar 12 '15 at 12:42
  • 1
    @Martin. Please, look at updated answer. If you also want first level nodes aligned to the right like second level ones do to the left, I don't know how to do it. My expertise in forest is not enough. But you can always make a new question. I'm sure our forest experts will help you. – Ignasi Mar 13 '15 at 9:20
  • thanks a lot. No, with "raggedright" I meant left justified (like here sharelatex.com/learn/Text_alignment#Left-justified_text ) so align = left should be the needed option. (In your first example the text in each node was centered) – MostlyHarmless Mar 13 '15 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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