2

I am trying to align this tikz tree but I can't figure it out how to have it well aligned as it was a graph that fits in a figure and in the textwidth. Anyone can help?

    \documentclass{article}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{adjustbox}

\begin{document}
\begin{figure}[tbp]
    \centering
    \begin{adjustbox}{width=\textwidth}
\begin{tikzpicture}[sibling distance=10em,
  every node/.style = {shape=rectangle, rounded corners,
    draw, align=center,
    top color=white, bottom color=blue!20}]]
  \node {AM integration \\ in injection molding}
    child { node {Something\\ Something} 
        child { node {Something \& Something}}
        child { node {Something}}
        child { node {Something}} 
        child { node {Something}}
        child { node {Something}}
        child { node {Something} }
        child { node{Something}}
        }
    child { node {Something} }
    child { node {Something}};
\end{tikzpicture}
\end{adjustbox}
    \caption{Caption}
    \label{fig:my_label}
\end{figure}
\end{document}
  • Align what and how, exactly? – Torbjørn T. Dec 15 '16 at 14:05
  • Align the node child so the parent is in the center and the child node are around the parent. Also, if possible to have a even distribution of the node in the graph so every node can be correctly displayed because as it is now, some boxes overlaps each other – Alexis Charalambis Dec 15 '16 at 14:07
  • Use Forest? ... – cfr Dec 17 '16 at 0:34
3

Here is a solution that doesn't need scaling.

enter image description here

\documentclass{article}
\usepackage{tikz}
\begin{document}
\noindent
\begin{tikzpicture}%
  [level 1/.style = {sibling distance=8em,font=\small},
   level 2/.style = {sibling distance=5em,level distance=12ex,font=\scriptsize},
   every node/.style =
     {shape=rectangle, rounded corners, draw, align=center,
      top color=white, bottom color=blue!20
     }
  ]
  \node {AM integration \\ in injection molding}
    child { node {3D printer\\ manufacturers} }
    child
      { node {The LEGO Group\\ departments} 
        child { node {Jigs \&\\ Fixtures}}
        child { node {Assembly}}
        child { node {R\&D}} 
        child { node {Quality \&\\ Control}}
        child { node {Packaging \&\\ Logistics}}
        child { node {Health \&\\ Safety} }
        child { node{Production\\ (tooling)}}
      }
    child { node {Universities}};
\end{tikzpicture}
\end{document}
2

Only two additions were made: text width (must be less than sibling distance) and level distance (to prevent lines from hitting nodes).

\documentclass{article}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{adjustbox}

\begin{document}
\begin{figure}[tbp]
    \centering
    \begin{adjustbox}{width=\textwidth}
\begin{tikzpicture}[sibling distance=10em, level distance=8em,
  every node/.style = {shape=rectangle, rounded corners,
    draw, align=center, text width=8em,
    top color=white, bottom color=blue!20}]]
  \node {AM integration \\ in injection molding}
    child { node {The LEGO Group departments} 
        child { node {Jigs \& Fixtures}}
        child { node {Assembly}}
        child { node {R\&D}} 
        child { node {Quality \& Control}}
        child { node {Packaging \& Logistics}}
        child { node {Health \& Safety} }
        child { node{Production (tooling)}}
        }
    child { node {3D printer manufacturers} }
    child { node {Universities}};
\end{tikzpicture}
\end{adjustbox}
    \caption{Caption}
    \label{fig:my_label}
\end{figure}
\end{document}

demo

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.