我想在 tikz 中创建一些图形,其中某些点之间有很多线条,因此我首先将它们定义为坐标。现在我想使用左侧点的变量名称来命名左侧的水平线,但所有名称都在同一个位置。我该如何纠正此行为?
平均能量损失
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}
\begin{figure}
\begin{center}
\begin{tikzpicture}
\coordinate (a) at (0,0);
\coordinate (b) at (10,0);
\coordinate (c) at (0,2);
\coordinate (d) at (10,2);
\coordinate (e) at (0,4);
\coordinate (f) at (10,4);
\draw[|-|] (a) -- (b);
\draw[|-|] (c) -- (d);
\draw[|-|] (e) -- (f);
\node[left=5mm of a] {Random length};
\node[left=5mm of c] {Original series};
\node[left=5mm of e] {Bootstrap sample};
\end{tikzpicture}
\end{center}
\end{figure}
\end{document}
答案1
positioning
以下语法需要TikZ 库left=5mm of a
:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{figure}
\begin{center}
\begin{tikzpicture}
\coordinate (a) at (0,0);
\coordinate (b) at (10,0);
\coordinate (c) at (0,2);
\coordinate (d) at (10,2);
\coordinate (e) at (0,4);
\coordinate (f) at (10,4);
\draw[|-|] (a) -- (b);
\draw[|-|] (c) -- (d);
\draw[|-|] (e) -- (f);
\node[left=5mm of a] {Random length};
\node[left=5mm of c] {Original series};
\node[left=5mm of e] {Bootstrap sample};
\end{tikzpicture}
\end{center}
\end{figure}
\end{document}
如果没有库positioning
,则会出现如下错误消息:
! Package PGF Math Error: Unknown operator `o' or `of' (in '5mm of a').
答案2
如果您将线条左侧的 tex 视为标签,那么您可以缩短图片代码并在没有定位库帮助的情况下绘制它:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[label distance=5mm]
\coordinate[label=left:Random length] (a) at (0,0);
\coordinate (b) at (10,0);
\coordinate[label=left:Original series] (c) at (0,2);
\coordinate (d) at (10,2);
\coordinate[label=left:Bootstrap sample](e) at (0,4);
\coordinate (f) at (10,4);
\draw[|-|] (a) edge (b)
(c) edge (d)
(e) to (f);
\end{tikzpicture}
\end{figure}
\end{document}
结果是: