对齐 tikz 树

对齐 tikz 树

我正在尝试对齐这棵 tikz 树,但我不知道如何将其对齐,因为它是一个适合图形和文本宽度的图形。有人可以帮忙吗?

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

答案1

这是一个不需要扩展的解决方案。

在此处输入图片描述

\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

仅添加了两项:文本宽度(必须小于同级距离)和级别距离(以防止线碰到节点)。

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

演示

相关内容