【发布时间】:2020-05-01 14:54:24
【问题描述】:
我正在尝试用箭头绘制图表。我已经能够使用此代码生成图表但没有箭头:
\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}
【问题讨论】:
-
语法错误。
\draw没有标签。您希望文本1/2出现在哪里?您是否正在寻找edge命令? -
今后请始终使minimal reproducible example 可编译,而不是仅仅向我们扔代码片段。
-
我需要
1/2出现在箭头旁边。我尝试了edge命令,我得到了同样的错误 -
尝试使用
\draw[->] (a) -- (z1) node[midway,above] {$1/2$};如果仍然报错,您必须提供可编译的minimal reproducible example 而不是这些代码片段。 -
对不起,我在我的问题中添加了完整的代码。
node[midway,above]有效,但我认为错误是由于使用[->]而引起的,因为它仍然无法正常工作。
标签: latex tikz sharelatex