2

I want to create a graphical model (a bit like a Bayesian network) in which some of the arrows are bent. I am using the tikz package.

This is the code:

\documentclass{article}

\usepackage{tikz}
\usepackage{tkz-graph}  
\usetikzlibrary{bayesnet}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{trees}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows.meta}
\tikzset{>={Latex[width=3mm,length=3mm]}}

\begin{document}

\begin{figure}
\begin{center}
\tikz{ %
\node[obs] (C) {C} ; %
\node[obs, right=of C] (M1) {M1} ; %
\node[obs, right=of M1] (M2) {M2} ; %
\node[obs, right=of M2] (E) {E} ; %
\node[ellipse, latent, above=1.5] (Mechanism) {Mechanism} ; %
\edge {C} {M1} ; %
\edge {M1} {M2} ; %
\edge {M2} {E} ; %
\edge[dashed, bend right] {Mechanism} {C}
\edge[dashed, bend right] {Mechanism} {M1}
\edge[dashed, bend left] {Mechanism} {M2}
\edge[dashed, bend left] {Mechanism} {E}
 } 
\tikz{ %
\node[obs] (C) {C} ; %
\node[obs, right=of C, yshift=1.25cm] (E1) {E1} ; %
\node[obs, right=of C] (E2) {E2} ; %
\node[obs, right=of C, yshift=-1.25cm] (E3) {E3} ; %
\node[ellipse, latent, above=1.5] (Mechanism) {Mechanism} ; %
\edge {C} {E1} ; %
\edge {C} {E2} ; %
\edge {C} {E3} ; %
\edge[dashed, bend right] {Mechanism} {C} ;%
\edge[dashed, bend left] {Mechanism} {E1} ;%
\edge[dashed, bend right] {Mechanism} {E2} ;%
\edge[dashed, out = 200, in = 270] {Mechanism} {E3} ;
 } 
 \tikz{ %
\node[obs] (E) {E} ; %
\node[obs, left=of E, yshift=1.25cm] (C1) {C1} ; %
\node[obs, left=of E] (C2) {C2} ; %
\node[obs, left=of E, yshift=-1.25cm] (C3) {C3} ; %
\node[ellipse, latent, above=1.5] (Mechanism) {Mechanism} ; %
\edge {C1} {E} ; %
\edge {C2} {E} ; %
\edge {C3} {E} ; %
\edge[dashed, bend right] {Mechanism} {C1} ;%
\edge[dashed, bend left] {Mechanism} {C2} ;%
\edge[dashed, out = 180, in =180] {Mechanism} {C3} ;%
\edge[dashed, bend left] {Mechanism} {E} ;
}
 \caption{blah}
 \label{fig:mechanism}
\end{center}
\end{figure}

\end{document}

This code had previously generated something that looked like this:

what I want it to look like

However I recently upgraded to my LaTeX editor (Texpad) and now for some reason the bent dashed edges are straight:

not how I want it to look

Would anyone have any ideas how to solve this?

  • This almost certainly does not come from your editor. You need to provide a full [MWE}(tex.meta.stackexchange.com/questions/228/…) for people to help you. – user121799 Mar 27 '18 at 11:40
  • @marmot is that more helpful now? – nathan glass Mar 27 '18 at 11:53
  • Yes and no. You have provided an MWE that runs through without a problem, which is quite something. However, I reproduce the output of your lower screenshot. And I am wondering about the way you are using edges. It is very reminiscent of the \Edge command provided by the tkz-graph package, which you load but don't seem to use. – user121799 Mar 27 '18 at 12:10
  • @marmot thanks for your input, problem solved now – nathan glass Mar 27 '18 at 13:41
1

The problem comes frome the syntax :

enter image description here

\documentclass{article}

\usepackage{tikz}
\usepackage{tkz-graph}  
\usetikzlibrary{bayesnet}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{trees}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows.meta}
\tikzset{>={Latex[width=3mm,length=3mm]}}
\pagestyle{empty}
\begin{document}

\begin{figure}
\begin{center}
\begin{tikzpicture}


\node[obs] (C) {C} ; %
\node[obs, right=of C] (M1) {M1} ; %
\node[obs, right=of M1] (M2) {M2} ; %
\node[obs, right=of M2] (E) {E} ; %
\node[ellipse, latent, above=1.5] (Mechanism) {Mechanism} ; %
\edge {C} {M1} ; %
\edge {M1} {M2} ; %
\edge {M2} {E} ; %

\foreach \x/\y in {C/right,M1/right,M2/left,E/left}
\path (Mechanism) edge [dashed, bend \y,->]  (\x) ;
\end{tikzpicture}


\begin{tikzpicture}[->]
\node[obs] (C) {C} ; %
\node[obs, right=of C, yshift=1.25cm] (E1) {E1} ; %
\node[obs, right=of C] (E2) {E2} ; %
\node[obs, right=of C, yshift=-1.25cm] (E3) {E3} ; %
\node[ellipse, latent, above=1.5] (Mechanism) {Mechanism} ; %
\edge {C} {E1} ; %
\edge {C} {E2} ; %
\edge {C} {E3} ; %
\path (Mechanism) edge[dashed, bend right]  (C) ;%
\path (Mechanism) edge[dashed, bend left] (E1) ;%
\path (Mechanism) edge[dashed, bend right] (E2) ;%
\path (Mechanism) edge[dashed, out = 200, in = 270] (E3) ;

\end{tikzpicture}

\begin{tikzpicture}[->]
\node[obs] (E) {E} ; %
\node[obs, left=of E, yshift=1.25cm] (C1) {C1} ; %
\node[obs, left=of E] (C2) {C2} ; %
\node[obs, left=of E, yshift=-1.25cm] (C3) {C3} ; %
\node[ellipse, latent, above=1.5] (Mechanism) {Mechanism} ; %
\edge {C1} {E} ; %
\edge {C2} {E} ; %
\edge {C3} {E} ; %
\path (Mechanism) edge[dashed, bend right]  (C) ;%
\path (Mechanism) edge[dashed, bend left] (C2) ;%
\path (Mechanism) edge[dashed, out = 180, in =180] (C3) ;%
\path (Mechanism) edge[dashed, bend left] (E) ;

\end{tikzpicture}

 \caption{blah}
 \label{fig:mechanism}
\end{center}
\end{figure}

\end{document}
  • you're an absolute hero – nathan glass Mar 27 '18 at 13:40

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.