2

我正在尝试用箭头绘制图表。我已经能够使用此代码生成图表但没有箭头:

\begin{tikzpicture}

\node (a) at (0,0) {$a$};    
\node (z1) at (3,2) {$z_1$};    
\node (z2) at (3,0) {$z_2$};    
\node (z3) at (3,-2) {$z_3$};


\draw (a) -- (z1);    
\draw (a) -- (z2);    
\draw (a) -- (z3);

\end{tikzpicture}

但是我需要这些段是箭头并向这些段添加标签但是当我尝试这段代码时:

\begin{tikzpicture}

\node (a) at (0,0) {$a$};    
\node (z1) at (3,2) {$z_1$};    
\node (z2) at (3,0) {$z_2$};    
\node (z3) at (3,-2) {$z_3$};

\draw [->] (a) -- (z1) {$1/2$};    
\draw [->] (a) -- (z2) {$1/4$};    
\draw [->] (a) -- (z3) {$1/4$};

\end{tikzpicture}

我在第一\draw行收到一个错误,上面写着:

Argument of \language?@active@arg> has an extra }. 


Runaway argument? 

Missing \endcsname inserted.

然后在\end{tikzpicture}我得到的行中:

Extra }, or forgotten \endgroup.

Missing } inserted. 

我正在使用的完整代码是这样的:

\documentclass[spanish]{article}
\usepackage[utf8]{inputenc}

\usepackage[spanish]{babel}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr} % Required for custom headers
\usepackage{lastpage} % Required to determine the last page for the footer
\usepackage{extramarks} % Required for headers and footers
\usepackage[usenames,dvipsnames]{color} % Required for custom colors
\usepackage{graphicx} % Required to insert images
\usepackage{listings} % Required for insertion of code
\usepackage{courier} % Required for the courier font
\usepackage{lipsum} % Used for inserting dummy 'Lorem ipsum' text into the template
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{natbib}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}

\node (a) at (0,0) {$a$};    
\node (z1) at (3,2) {$z_1$};    
\node (z2) at (3,0) {$z_2$};    
\node (z3) at (3,-2) {$z_3$};

\draw [->] (a) -- (z1)  node[midway,above] {$1/2$};    
\draw [->] (a) -- (z2)  node[midway,above] {$1/4$};    
\draw [->] (a) -- (z3)  node[midway,above] {$1/4$};

\end{tikzpicture}

\end{document}
4

2 回答 2

1

有几个问题:

  • \draw命令没有像\node命令那样的标签。如果要向箭头添加文本,有几种可能性,例如\draw [->] (a) -- (z1) node[midway,above] {$1/2$};

  • 那么你也在加载西班牙文 babel 包。这引入了一些速记来编写干扰 tikz 的西班牙语字符。关闭这些速记或加载 tikzbabel

  • 请不要多次加载包

  • 查看nicefrac包装以获得更好的分数


\documentclass[spanish]{article}
\usepackage[utf8]{inputenc}

\usepackage[spanish]{babel}
%\usepackage[utf8]{inputenc}
\usepackage{fancyhdr} % Required for custom headers
\usepackage{lastpage} % Required to determine the last page for the footer
\usepackage{extramarks} % Required for headers and footers
\usepackage[usenames,dvipsnames]{color} % Required for custom colors
\usepackage{graphicx} % Required to insert images
\usepackage{listings} % Required for insertion of code
\usepackage{courier} % Required for the courier font
\usepackage{lipsum} % Used for inserting dummy 'Lorem ipsum' text into the template
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{natbib}
%\usepackage{graphicx}
%\usepackage{amsmath}
%\usepackage{amssymb}
\usepackage{tikz}

\usetikzlibrary{babel}

\begin{document}

\begin{tikzpicture}

\node (a) at (0,0) {$a$};    
\node (z1) at (3,2) {$z_1$};    
\node (z2) at (3,0) {$z_2$};    
\node (z3) at (3,-2) {$z_3$};

\draw [->] (a) -- (z1)  node[midway,above] {$1/2$};    
\draw [->] (a) -- (z2)  node[midway,above] {$1/4$};    
\draw [->] (a) -- (z3)  node[midway,above] {$1/4$};

\end{tikzpicture}

\end{document}

在此处输入图像描述

于 2020-05-04T16:49:09.040 回答
-1

在节点之间尝试edge命令

\begin{tikzpicture}

\node (a) at (0,0) {$a$};
\node (z1) at (3,2) {$z_1$};
\node (z2) at (3,0) {$z_2$};
\node (z3) at (3,-2) {$z_3$};

\draw [->] (a) edge (z1) (a) edge (z2) (a) edge (z3);

\end{tikzpicture}
于 2020-05-03T09:23:45.903 回答