2

I tried to reproduce a tikz-example of a book's companion website.

Code shown below is coming from this website. The desired output can be seen in Fig. 2. However, compiling this code cunk gives me many errors and results in picture with overlapping elements. What is wrong here? If it's a general issue, I would like to share the solution with the author.

http://blogs.baylor.edu/rlatentvariable/files/2013/12/AppendixCreatingPathModels-211jclc.pdf

MWE:

\documentclass[]{article}

\usepackage{tikz}
\usetikzlibrary{shapes,arrows}

%opening
\title{}
\author{}

\begin{document}

\maketitle

\section{}

\begin{tikzpicture}[auto,>=latex,align=center,
latent/.style={circle,draw, thick,inner sep=0pt,minimum size=10mm},
manifest/.style={rectangle,draw, thick,inner sep=2pt,minimum size=10mm},
mean/.style={regular polygon,regular polygon sides=3,draw,thick,inner sep=0pt,minimum
    size=10mm},
paths/.style={->, very thick, >=stealth'},
variance/.style={<->, thick, >=stealth', bend left=270, looseness=2},
]
\node [manifest] (WR) [below =of LV1]  {Word\\Reasoning};
\node [manifest] (SI) [left =of WR]  {Similarities};
\node [manifest] (IN) [left =of SI]  {Information};
\node [manifest] (MR) [right =of WR]  {Matrix\\Reasoning};
\node [manifest] (PS) [right =of MR]  {Picture\\Similarities};
\node [latent] (EIN) [below =of IN]  {Error};
\node [latent] (ESI) [below =of SI]  {Error};
\node [latent] (EWR) [below =of WR]  {Error};
\node [latent] (EMR) [below =of MR]  {Error};
\node [latent] (EPS) [below =of PS]  {Error};
\draw [paths,above] (LV1) to node   {a}   (IN);
\draw [paths,above] (LV1) to node [pos=.75]   {b}   (SI);
\draw [paths] (LV1) to node   {c}   (WR);
\draw [paths] (LV1) to node  [pos=.75]  {d}  (MR);
\draw [paths] (LV1) to node   {e}   (PS);
\foreach \e in {IN, SI, WR, MR, PS}
\draw [paths] (E\e) to node   {1}   (\e);
\foreach \x/\xlab in {EIN/f, ESI/g,EWR/h, EMR/i, EPS/j}
\draw [variance] (\x.south west) to node [swap] {\xlab}  (\x.south east);
\end{tikzpicture}


\end{document}
3

There are two problems preventing that from compiling:

  1. The positioning library is not loaded, which is required to use the left=of <nodename> syntax. I.e. add \usetikzlibrary{positioning}.

  2. The top node, named LV1 has disappeared from the code during copy-pasting. Look again at the code in that PDF and you'll see \node [latent] (LV1) at (0,0) {g}; at the start of the tikzpicture. (The at (0,0) part is actually not necessary.)

enter image description here

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning,shapes,arrows}


\begin{document}

\begin{tikzpicture}[auto,>=latex,align=center,
latent/.style={circle,draw, thick,inner sep=0pt,minimum size=10mm},
manifest/.style={rectangle,draw, thick,inner sep=2pt,minimum size=10mm},
mean/.style={regular polygon,regular polygon sides=3,draw,thick,inner sep=0pt,minimum
    size=10mm},
paths/.style={->, very thick, >=stealth'},
variance/.style={<->, thick, >=stealth', bend left=270, looseness=2},
]

\node [latent] (LV1) at (0,0) {g};

\node [manifest] (WR) [below =of LV1]  {Word\\Reasoning};
\node [manifest] (SI) [left =of WR]  {Similarities};
\node [manifest] (IN) [left =of SI]  {Information};
\node [manifest] (MR) [right =of WR]  {Matrix\\Reasoning};
\node [manifest] (PS) [right =of MR]  {Picture\\Similarities};
\node [latent] (EIN) [below =of IN]  {Error};
\node [latent] (ESI) [below =of SI]  {Error};
\node [latent] (EWR) [below =of WR]  {Error};
\node [latent] (EMR) [below =of MR]  {Error};
\node [latent] (EPS) [below =of PS]  {Error};
\draw [paths,above] (LV1) to node   {a}   (IN);
\draw [paths,above] (LV1) to node [pos=.75]   {b}   (SI);
\draw [paths] (LV1) to node   {c}   (WR);
\draw [paths] (LV1) to node  [pos=.75]  {d}  (MR);
\draw [paths] (LV1) to node   {e}   (PS);
\foreach \e in {IN, SI, WR, MR, PS}
\draw [paths] (E\e) to node   {1}   (\e);
\foreach \x/\xlab in {EIN/f, ESI/g,EWR/h, EMR/i, EPS/j}
\draw [variance] (\x.south west) to node [swap] {\xlab}  (\x.south east);
\end{tikzpicture}


\end{document}

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.