是否有任何解决方法可以在“图”后面的节点中使用 [pos=] 或 [midway] 选项来注释路径?以下最小示例将缺少节点文本:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[very thin,color=gray] (-0.1,-0.1) grid (2.9,4.1);
\draw[->] (-0.2,0) -- (3.2,0) node[right] {$x$};
\draw[->] (0,-0.2) -- (0,4.2) node[above] {$f(x)$};
\draw[domain=0:3] plot (\x,{\x^2}) node[midway, sloped] {midway?};
\end{tikzpicture}
\end{document}
答案1
我忘了 decoration
最新版本
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[domain=0:2,label/.style={%
postaction={ decorate,transform shape,
decoration={ markings, mark=at position .5 with \node #1;}}}]
\draw[very thin,color=gray] (-0.1,-1.1) grid (3.9,3.9);
\draw[red,label={[above]{$f(x)=x^2$}}] plot(\x,{\x^2}) ;
\end{tikzpicture}
\end{document}