![减少“右上方”的垂直距离来标记地块](https://linux22.com/image/280994/%E5%87%8F%E5%B0%91%E2%80%9C%E5%8F%B3%E4%B8%8A%E6%96%B9%E2%80%9D%E7%9A%84%E5%9E%82%E7%9B%B4%E8%B7%9D%E7%A6%BB%E6%9D%A5%E6%A0%87%E8%AE%B0%E5%9C%B0%E5%9D%97.png)
above right
我如何使用但减少垂直距离来标记地块?我尝试了类似的语法above right= value1 and value2
,但这对我来说不起作用。
例如下面的情节:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ymin=0, ymax=12]
\addplot[black] {1} node[pos=0.1, above right]{$y=1$};
\addplot[black] {2} node[pos=0.1, above right]{$y=2$};
\addplot[black] {3} node[pos=0.1, above right]{$y=3$ long info};
\addplot[black] {4} node[pos=0.1, above right]{$y=3$};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您可以定义一种名为的新样式mylabel
,并将其垂直移动一点(y
)。这样,您只需重新定义样式,这样放置的所有标签看起来都会相同(3 和 4)。
使用 tikzlibrary,positioning
您可以执行类似“右上方= 和 ”的操作。参见图 5 和图 6。感谢 @HarishKumar 指出这一点。
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9,
}
\usetikzlibrary{positioning}
\tikzset{
mylabel/.style={above right, yshift=-2pt}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ymin=0, ymax=12]
\addplot[black] {1} node[pos=0.1, above right]{$y=1$};
\addplot[black] {2} node[pos=0.1, above right]{$y=2$ long info};
\addplot[black] {3} node[pos=0.1, mylabel]{$y=3$ long info};
\addplot[black] {4} node[pos=0.1, mylabel]{$y=3$};
\addplot[black] {5} node[pos=0.1, above right=-2pt and 1pt]{$y=5$};
\addplot[black] {6} node[pos=0.1, above right=-2pt and 8pt]{$y=6$ long info};
\end{axis}
\end{tikzpicture}
\end{document}