LaTeX forum ⇒ Graphics, Figures & TablesCausal Diagrams with Common Grandchild

Information and discussion about graphics, figures & tables in LaTeX documents.
asmithb
Posts: 20
Joined: Tue Feb 23, 2021 12:04 pm

Causal Diagrams with Common Grandchild

Postby asmithb » Sun Nov 21, 2021 11:36 am

Dear all,

I want to make the the following diagram type, but with a vertical orientation:

Common Grandchild.png
Common Grandchild.png (3 KiB) Viewed 724 times


Specifically, I want the 3 children from my diagram to end up having a common grandchild. So far, I have the following code but do not know how to draw the common grandchild:

\documentclass[12pt]{article}

\usepackage{amssymb,amsmath,amsfonts,eurosym,geometry,ulem,graphicx,caption,subcaption, color,setspace,sectsty,comment,footmisc,caption,natbib,pdflscape,subfigure,array, enumerate, natbib, indentfirst, float, tikz, rotating, lipsum, adjustbox, booktabs, multirow, soul, changepage,threeparttable}

\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\usepackage[unicode, bookmarks, colorlinks, breaklinks]{hyperref}  

\hypersetup{colorlinks=true, pdfstartview=FitV, linkcolor=blue, citecolor=black, plainpages=false, pdfpagelabels=true, urlcolor=blue}


\usepackage[nameinlink, capitalise, noabbrev]{cleveref}
\bibliographystyle{abbrvnat}
\setcitestyle{authoryear,open={(},close={)}} %Citation-related commands

\normalem

\onehalfspacing
\newtheorem{theorem}{Theorem}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{proposition}{Proposition}
\newtheorem{conj}{Conjecture}

\newenvironment{proof}[1][Proof]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}

\newtheorem{hyp}{Hypothesis}
\newtheorem{subhyp}{Hypothesis}[hyp]
\renewcommand{\thesubhyp}{\thehyp\alph{subhyp}}

\newcommand{\red}[1]{{\color{red} #1}}
\newcommand{\blue}[1]{{\color{blue} #1}}

\newcolumntype{L}[1]{>{\raggedright\let\newline\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\arraybackslash\hspace{0pt}}m{#1}}

\geometry{left=1.0in,right=1.0in,top=1.0in,bottom=1.0in}


\usetikzlibrary{shapes,arrows,intersections,arrows.meta,shadows,positioning}
\newcommand{\FixedLengthArrow}{2,0}

\begin{document}

\begin{figure}[H]
\centering
\begin{tikzpicture}[
  sibling distance=6cm,
  edge from parent/.append style={->},
  growth parent anchor=south,
  >=Latex
]

% root of the the initial tree, level 1
\node [root] (root) {Grandpa}
  % The first level, as children of the initial tree

    child {node {Father}  
      child {node (C1){Child}}
      child {node (C2) {Child}}
      child {node (C3) {Child}}
  }
    
\path (root-1-1-1.south)  -- coordinate (midway)   (root-1-1-1.south) ;

;
\end{tikzpicture}
\caption{Common Grandchild} 
\label{fig: Causal}
\end{figure}    

\end{document}

Recommended reading 2021:

LaTeXguide.org • LaTeX-Cookbook.net
LaTeX Beginner's Guide LaTeX Cookbook
User avatar
Stefan Kottwitz
Site Admin
Posts: 9794
Joined: Mon Mar 10, 2008 9:44 pm

Causal Diagrams with Common Grandchild

Postby Stefan Kottwitz » Sun Nov 21, 2021 1:40 pm

You can add the node manually, use the same level distance and styles.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning}
\begin{document}
\begin{tikzpicture}[
  sibling distance=6cm,
  level distance = 1.5cm,
  edge from parent/.append style={->},
  growth parent anchor=south,
  >=Latex,
  root/.style = {black},
]
% root of the the initial tree, level 1
\node [root] (root-1-1-1) {Grandpa}
  % The first level, as children of the initial tree
    child {node {Father}  
      child {node (C1){Child}}
      child {node (C2) {Child}}
      child {node (C3) {Child}}
  };
% use same level distance as above
\node [below = 1.5cm of C2.center] (C4) {Grandchild};
\foreach \kid in {C1, C2, C3} \draw[->] (\kid) -- (C4);
\end{tikzpicture}
\end{document}


Stefan
LaTeX.org admin

Bartman
Posts: 248
Joined: Fri Jan 03, 2020 2:39 pm

Causal Diagrams with Common Grandchild

Postby Bartman » Mon Nov 22, 2021 7:38 am

Some more approaches:

with \tikzleveldistance

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{arrows.meta,positioning}

\begin{document}
\begin{tikzpicture}[
  sibling distance=6cm,
%  level distance = 1.5cm,% initial value
  edge from parent/.append style={->},
  growth parent anchor=south,
  >=Latex
]
% root of the the initial tree, level 1
\node {Grandpa}
  % The first level, as children of the initial tree
    child {node {Father}  
      child {node (C1) {Child}}
      child {node (C2) {Child}}
      child {node (C3) {Child}}
  };
% use same level distance as above
\node [below = \tikzleveldistance of C2.center] (C4) {Grandchild};
\foreach \kid in {1, 2, 3} 
  \draw[->] (C\kid) -- (C4);
\end{tikzpicture}
\end{document}


with another child

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{arrows.meta}

\begin{document}
\begin{tikzpicture}[
  sibling distance=6cm,
%  level distance = 1.5cm,% initial value
  edge from parent/.append style={->},
  growth parent anchor=south,
  >=Latex
]
% root of the the initial tree, level 1
\node {Grandpa}
  % The first level, as children of the initial tree
    child {node {Father}  
      child {node (C1) {Child}}
      child {node (C2) {Child}
        child {node (C4) {Grandchild}}
      }
      child {node (C3) {Child}}
  };
\foreach \kid in {1, 3} 
  \draw[->] (C\kid) -- (C4);
\end{tikzpicture}
\end{document}

asmithb
Posts: 20
Joined: Tue Feb 23, 2021 12:04 pm

Causal Diagrams with Common Grandchild

Postby asmithb » Mon Nov 22, 2021 12:57 pm

Thank you very much. I have other question.

How do I add a grand grandchild to the bottom. What about if I want to add 3 grand-grandchild and then one common grand-grand-grandchild as you did above?

Thanks again

asmithb
Posts: 20
Joined: Tue Feb 23, 2021 12:04 pm

Causal Diagrams with Common Grandchild

Postby asmithb » Tue Nov 23, 2021 4:17 pm

How could I move the grandchild and the grand-grandchild to the middle of the diagram?

\documentclass[12pt]{article}

\usepackage{amssymb,amsmath,amsfonts,eurosym,geometry,ulem,graphicx,caption,subcaption, color,setspace,sectsty,comment,footmisc,caption,natbib,pdflscape,subfigure,array, enumerate, natbib, indentfirst, float, tikz, rotating, lipsum, adjustbox, booktabs, multirow, soul, changepage,threeparttable}

\usepackage[utf8]{inputenc}
\usepackage[english]{babel}



\usepackage[unicode, bookmarks, colorlinks, breaklinks]{hyperref}  

\hypersetup{colorlinks=true, pdfstartview=FitV, linkcolor=blue, citecolor=black, plainpages=false, pdfpagelabels=true, urlcolor=blue}


\usepackage[nameinlink, capitalise, noabbrev]{cleveref}
\bibliographystyle{abbrvnat}
\setcitestyle{authoryear,open={(},close={)}} %Citation-related commands

\normalem

\onehalfspacing
\newtheorem{theorem}{Theorem}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{proposition}{Proposition}
\newtheorem{conj}{Conjecture}

\newenvironment{proof}[1][Proof]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}

\newtheorem{hyp}{Hypothesis}
\newtheorem{subhyp}{Hypothesis}[hyp]
\renewcommand{\thesubhyp}{\thehyp\alph{subhyp}}

\newcommand{\red}[1]{{\color{red} #1}}
\newcommand{\blue}[1]{{\color{blue} #1}}

\newcolumntype{L}[1]{>{\raggedright\let\newline\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\arraybackslash\hspace{0pt}}m{#1}}

\geometry{left=1.0in,right=1.0in,top=1.0in,bottom=1.0in}


\usetikzlibrary{shapes,arrows,intersections,arrows.meta,shadows,positioning}
\newcommand{\FixedLengthArrow}{2,0}

\begin{document}
\tikzset{%
  block/.style = {rectangle, draw, fill=yellow, text width=5em, text centered, rounded corners, minimum height=2em},
  line/.style = {draw, -latex'},
}


\tikzset{
  basic/.style={
    draw,
    text width=3cm, 
    drop shadow, 
    font=\sffamily
  },
  root/.style={
    basic, 
    rounded corners=2pt, 
    thin, 
    align=center,
    fill=green!30
  },
  child node/.style={
    basic, 
    rounded corners=6pt, 
    thin,
    align=center, 
    fill=green!60,
    text width=10em,
    anchor=north
  },
  every child node/.style={child node}
}

\begin{figure}[H]
\centering
\begin{tikzpicture}[
  sibling distance=6cm,
  edge from parent/.append style={->},
  growth parent anchor=south,
  >=Latex,
  nodes={draw, fill=cyan,
      text width=4cm,
      text centered}
]
% root of the the initial tree, level 1
\node (root) {Oil Wealth}
  % The first level, as children of the initial tree
    
    child {node (A1)  {Grandparent}  
        child {node (B1) {Parent}
            child {node (C11) {Child}}
            child {node (C12) {Child}}
            child {node (C13) {Child}}}}
    
 
      child {node (D11) {Grandchild}}  
      child {node (D12) {Grandchild}}  
      
      child {node (E12) {Grand-Grandchild}}      
                      
            
    
       
        ;
  \draw [->] (C11) -- (D11);
  \draw [->] (C12) -- (D11);
  \draw [->] (C11) -- (D12);
  \draw [->] (C12) -- (D12);

\end{tikzpicture}
\caption{Mine Editing Tex III} 
\label{fig: Causal}
\end{figure}  


\end{document}


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 7 guests