我怎样才能制作下面代码中的标签{stable \\ equilibrium}
,以便有一个换行符,并且与文本中心对齐?
\documentclass{article}
\usepackage{lipsum, pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=0, width=\textwidth]
\addplot [domain=0:1] {30 + 70*x};
\addplot [domain=0:1] {40 + 20*x};
\node [label={[label distance=2em]80: {stable equilibrium}}] at (0, 40) {};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
如果节点仅由文本组成,则将文本放入括号中可能会更容易{}
。这使得处理节点/文本变得更容易一些,例如当您决定用箭头将其连接到某个点时。
\documentclass{article}
\usepackage{lipsum, pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=0, width=\textwidth]
\addplot [domain=0:1] {30 + 70*x};
\addplot [domain=0:1] {40 + 20*x};
\node [yshift=2.7em,anchor=south west,align=center,text width=2cm] at (0, 40){stable\\ equilibrium};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
也许你会喜欢:
使用的是tikz
库intersections
,也是重新定义的pin
节点选项:
\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}[
every pin/.append style = {pin edge={<-, shorten <=2pt, semithick}, align=center},
]
\begin{axis}[
xmin=0,
width=\linewidth,
domain=0:1]
\addplot [name path=A] {30 + 70*x};
\addplot [name path=B] {40 + 20*x};
\path [name intersections ={%
of=A and B, by={[pin=300:stable\\ equilibrium]}
}];
\end{axis}
\end{tikzpicture}
\end{document}