我似乎无法让我的节点正确运行。贝塞尔曲线上的一条简单割线。确定该割线的 delta-X 和 delta-Y。问题出在我尝试将 delta-X 段向下延伸到 x 轴时。请参阅以下代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}
\draw[thick,->] (0,0) -- (12,0) node[anchor=north west] (X) {x};
\draw[thick,->] (0,0) -- (0,6) node[anchor=south east] (Y) {f(x)};
\draw (1,1) .. controls (7,1) and (8,2) .. (9,5)
node[inner sep=0cm,pos=.3](P){}
node[inner sep=0cm,pos=.8](Q){};
\draw[blue,thick] (P) -- (Q);
\draw[gray] (P) -- node[below] {$\Delta{X}$} (P -| Q);
\draw[gray] (P -| Q) -- node[right] {$\Delta{Y}$} (Q);
\draw[fill] (P) circle [radius=0.075] node[above left] (P) {P};
\draw[fill] (Q) circle [radius=0.075] node[right] (Q) {Q};
\node [above] at (9,5) {y = f(x)};
\draw[->,red] (P) -- (P |- X);
\draw[red] (P -| Q) -- (Q |- X);
\end{tikzpicture}
\end{document}
解决了!
现在我只需要添加一些标签...希望一切顺利!
答案1
一切都正确,除了坐标(X)
位于节点的中心锚点,因此箭头延伸得太远。
只需放置坐标(X)
,而不是命名标签节点(X)
:
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[thick,->] (0,0) -- (12,0) coordinate (X) node[anchor=north west] {x};
\draw[thick,->] (0,0) -- (0,6) node[anchor=south east] (Y) {f(x)};
\draw (1,1) .. controls (7,1) and (8,2) .. (9,5)
node[inner sep=0cm,pos=.3](P){}
node[inner sep=0cm,pos=.8](Q){};
\draw[blue,thick] (P) -- (Q);
\draw[gray] (P) -- node[below] {$\Delta{X}$} (P -| Q);
\draw[gray] (P -| Q) -- node[right] {$\Delta{Y}$} (Q);
\draw[fill] (P) circle [radius=0.075] node[above left] (P) {P};
\draw[fill] (Q) circle [radius=0.075] node[right] (Q) {Q};
\node [above] at (9,5) {y = f(x)};
\draw[->,red] (P) -- (P |- X);
\draw[red] (P -| Q) -- (Q |- X);
\end{tikzpicture}
\end{document}
如果这些对齐方式不符合您的预期,您可以对其他节点名称(、等)P
采用类似的方法。Q