Graphics, Figures & TablesMultibranched tree in TikZ with arrows[solved]

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Turbomichi
Posts: 2
Joined: Wed Jul 12, 2017 12:56 pm

Multibranched tree in TikZ with arrows[solved]

Post by Turbomichi »

Hello people,

I want to create a tree in TikZ with more than two branches.
With the code below I get the first shown image, but I need a tree as shown
in the second picture. The arrow positions should not given in explicit coordinates, but
relative to the boxes. The arrows should all start on the same point and end on top of the boxes in the middle.

Thank you for your help

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usepackage{nicefrac}
\usepackage{amssymb} 
\usetikzlibrary{positioning,arrows,automata,calc,shapes}
\begin{document}
\newcommand{\Symmetry}[3]
{
  \begin{minipage}{1.5cm}
    \centering
      {{#1}}%
      \linebreak 
      {{#2}}%
      \linebreak 
      {{#3}}%
  \end{minipage}
}

\newcommand{\Wyckoff}[3]
{
  \begin{minipage}{1.5cm}
    \centering
      {{#1}}%
      \linebreak 
      {{#2}}%
      \linebreak 
      {{#3}}%
  \end{minipage}
}



\begin{tikzpicture}[->,>=stealth',shorten >=1pt,node distance=3.0cm]
%% Fill Color Styles
  \tikzstyle{ElementFill} = [fill=yellow!15]


%% Element Styles
  \tikzstyle{Element} = [draw=black, ElementFill, minimum width=1.75cm, minimum height=1.75cm, node distance=1.75cm]
  \tikzstyle{every state}=[fill=white,draw=black,text=black,minimum size=45pt]

\node[name=Na11, Element] {\Symmetry{Na:}{1\textit{a}}{$\bar{3}$\textit{m}}};
\node[name=KoNa11, below of=Na11, Element]  {\Wyckoff{0}{0}{0}} ;
\node[name=Na12, below=2cm of KoNa11, Element] {\Symmetry{Na:}{2\textit{a}}{2/\textit{m}}};        
\node[name=KoNa12, below of=Na12, Element] {\Wyckoff{0}{0}{0}} ;
\node[name=Na13, below=2cm of KoNa12, Element] {\Symmetry{Na1:}{4\textit{g}}{2}};
\node[name=KoNa13, below of=Na13, Element] {\Wyckoff{0}{0.1578}{0}};
\node[name=Na14, right of=Na13, Element] {\Symmetry{$\Box$:}{2\textit{a}}{2/\textit{m}}};
\node[name=KoNa14, below of=Na14, Element] {\Wyckoff{0}{0}{0}};
\node[name=Na21, right of=Na14, Element] {\Symmetry{$\Box$:}{2\textit{a}}{2/\textit{m}}};
\node[name=KoNa21, below of=Na21, Element] {\Wyckoff{0}{0}{0}};
\node[name=Na22, right of=Na21, Element] {\Symmetry{$\Box$:}{2\textit{a}}{2/\textit{m}}};
\node[name=KoNa22, below of=Na22, Element] {\Wyckoff{0}{0}{0}};
\node[name=Na23, right of=Na22, Element] {\Symmetry{$\Box$:}{2\textit{a}}{2/\textit{m}}};
\node[name=KoNa23, below of=Na23, Element] {\Wyckoff{0}{0}{0}};



\node[name=Mn, right of=Na11, Element] {\Symmetry{Mn:}{2\textit{d}}{3\textit{m}}};
\node[name=KoMn, below of=Mn, Element] {\Wyckoff{\nicefrac{1}{3}}{\nicefrac{2}{3}}{0.6247}};        
\node[name=Te, right of=Mn, Element] {\Symmetry{Te:}{2\textit{d}}{3\textit{m}}};
\node[name=KoTe, below of=Te, Element] {\Wyckoff{\nicefrac{1}{3}}{\nicefrac{2}{3}}{0.2571}};

\draw[->, blue!50, very thick] (KoNa11) to (Na12);
\draw[->, blue!50, very thick] (KoNa12) to (Na13);
\draw[->, blue!50, very thick] (KoNa12) to (Na14);
\draw[->, blue!50, very thick] (KoNa12) to (Na21);
\draw[->, blue!50, very thick] (KoNa12) to (Na22);
\draw[->, blue!50, very thick] (KoNa12) to (Na23);

\end{tikzpicture}
\end{document}
tree.png
tree.png (4.53 KiB) Viewed 3822 times
tree3.png
tree3.png (4.63 KiB) Viewed 3822 times

[solved]
Adding ".south"/".north" to the node names.
"north east" resp. "south west" etc. works too.

\draw[->, blue!50, very thick] (KoNa11) to (Na12);
\draw[->, blue!50, very thick] (KoNa12) to (Na13);
\draw[->, blue!50, very thick] (KoNa12.south) to (Na14.north);
\draw[->, blue!50, very thick] (KoNa12.south) to (Na21.north);
\draw[->, blue!50, very thick] (KoNa12.south) to (Na22.north);
\draw[->, blue!50, very thick] (KoNa12.south) to (Na23.north);

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10328
Joined: Mon Mar 10, 2008 9:44 pm

Multibranched tree in TikZ with arrows[solved]

Post by Stefan Kottwitz »

Welcome to the forum!

Great to read that you could already solve it! Maybe I can help with the next TikZ question later on.

Just by the way, there's a new syntax now as replacement for \tikzstyle:

Code: Select all

%% Fill Color Styles
  \tikzset{
    ElementFill/.style = {fill = yellow!15},
        Element/.style = {draw=black, ElementFill, minimum width=1.75cm,
                          minimum height=1.75cm, node distance=1.75cm},
    every state/.style = {fill=white, draw=black, text=black, minimum size=45pt}
  }
It can also be used as argument to the tikzpicture environment:

Code: Select all

\begin{tikzpicture}[->, >=stealth', shorten >=1pt, node distance=3.0cm,
    %% Fill Color Styles
    ElementFill/.style = {fill = yellow!15},
        Element/.style = {draw=black, ElementFill, minimum width=1.75cm,
                          minimum height=1.75cm, node distance=1.75cm},
    every state/.style = {fill=white, draw=black, text=black, minimum size=45pt}
  ]
  \node ...
Stefan
LaTeX.org admin
Turbomichi
Posts: 2
Joined: Wed Jul 12, 2017 12:56 pm

Multibranched tree in TikZ with arrows[solved]

Post by Turbomichi »

Hi Stefan,

thank you for the information. I will try it.

Greetz Turbomichi
Post Reply