tikzpicture 代码存在问题

tikzpicture 代码存在问题

我尝试重现一本书的配套网站的 tikz 示例。

下面的代码来自这个网站。所需的输出如图 2 所示。但是,编译此代码时,cunk 会给出许多错误,并导致图片中的元素重叠。这里出了什么问题?如果这是一个普遍问题,我想与作者分享解决方案。

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

梅威瑟:

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

答案1

有两个问题阻碍了编译:

  1. positioning未加载使用语法所需的库。left=of <nodename>即添加\usetikzlibrary{positioning}

  2. LV1在复制粘贴过程中,名为 的顶部节点从代码中消失了。再次查看该 PDF 中的代码,您会\node [latent] (LV1) at (0,0) {g};在 的开头看到tikzpicture。(该at (0,0)部分实际上不是必需的。)

在此处输入图片描述

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

相关内容