考虑以下最小不起作用的示例,其中第一个图形是使用“标准 TikZ”方法绘制的,第二个图形是使用 hobby 包绘制的:
\documentclass{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{calc, hobby}
\tikzset{tangent/.style = {inagle={(180+#1)},
Hobbyfinish,
designated Hobby path=next,
outangle=#1}}
\begin{document}
\begin{figure}[htbp]
\centering
\begin{tikzpicture}
\coordinate (y) at (0,3);
\coordinate (x) at (5,0);
\coordinate (sp0) at (1.5, 0);
\coordinate (ep0) at (3.5, 2);
\coordinate (csp0) at (2.5, 1);
\coordinate (cep0) at (2.75, 0);
\coordinate (sp1) at (ep0);
\coordinate (ep1) at (4.5, 3);
\coordinate (csp1) at (4.25, 4);
\coordinate (cep1) at (4.25, 2);
\coordinate (sp2) at (sp0);
\coordinate (ep2) at (0, -1);
\coordinate (csp2) at (0.5, -1);
\coordinate (cep2) at (0.5, -1);
\draw[<->] (y) node[left] {$f(x)$} -- (0,0) -- (x) node[below] {$x$};
\draw (sp0) .. controls (csp0) and (cep0).. (ep0);
\draw[dashed] (cep0) -- (csp1);
\draw[dotted] let \p1 = (ep0) in (ep0) -- (0, \y1);
\draw[dotted] let \p1 = (ep0) in (ep0)-- (\x1, 0);
\draw (sp1) .. controls (csp1) and (cep1).. (ep1);
\draw (sp2) .. controls (csp2) and (cep2).. (ep2);
\draw let \p1 = (ep0) in (\x1,1pt) -- (\x1,-3pt) node[anchor=north] {$x_0$};
\draw let \p1 = (cep0) in (\x1,1pt) -- (\x1,-3pt) node[anchor=north] {$x_1$};
\draw let \p1 = (ep0) in (1pt, \y1) -- (-3pt, \y1) node [anchor=east] {$f(x_0)$};
\end{tikzpicture}
\caption{Newton's method in action: diagram drawn using ``standard'' TiKZ methods.}
\label{fig:newton_method_1}
\end{figure}
\begin{figure}[htbp]
\centering
\begin{tikzpicture}
\coordinate (y) at (0,3);
\coordinate (x) at (5,0);
\coordinate (sp0) at (1.5, 0);
\coordinate (ep0) at (3.5, 2);
\coordinate (csp0) at (2.5, 1);
\coordinate (cep0) at (2.75, 0);
\coordinate (sp1) at (ep0);
\coordinate (ep1) at (4.5, 3);
\coordinate (csp1) at (4.25, 4);
\coordinate (cep1) at (4.25, 2);
\coordinate (sp2) at (sp0);
\coordinate (ep2) at (0, -1);
\coordinate (csp2) at (0.5, -1);
\coordinate (cep2) at (0.5, -1);
\draw[<->] (y) node[left] {$f(x)$} -- (0,0) -- (x) node[below] {$x$};
% Using \pgfmathanglebetweenpoints to calculate the angle for tangent
% tangent takes a degree unit angle
\draw (ep2) to [curve through ={(sp0) .. ([tangent=\pgfmathanglebetweenpoints{\pgfpointanchor{cep0}{center}}
{\pgfpointanchor{ep0}{center}}]ep0)}] (ep1) ;
\draw[dashed] (cep0) -- (csp1);
\draw[dotted] let \p1 = (ep0) in (ep0) -- (0, \y1);
\draw[dotted] let \p1 = (ep0) in (ep0)-- (\x1, 0);
\draw let \p1 = (ep0) in (\x1,1pt) -- (\x1,-3pt) node[anchor=north] {$x_0$};
\draw let \p1 = (cep0) in (\x1,1pt) -- (\x1,-3pt) node[anchor=north] {$x_1$};
\draw let \p1 = (ep0) in (1pt, \y1) -- (-3pt, \y1) node [anchor=east] {$f(x_0)$};
\end{tikzpicture}
\caption{Newton's method in action: diagram drawn using the \texttt{hobby} package.}
\label{fig:newton_method_2}
\end{figure}
\end{document}
我收到以下错误:
line 79: Package pgfkeys Error: I do not know the key '/tikz/inagle', to which you past. ...\pgfpointanchor{ep0}{center}}]ep0)}] (ep1)
line 79: Package pgfkeys Error: I do not know the key '/tikz/Hobbyfinish' and I am going to ignore it. Perhaps you misspelled it. ...\pgfpointanchor{ep0}{center}}]ep0)}] (ep1)
line 79: Package pgfkeys Error: I do not know the key '/tikz/outangle', to which you pchor {ep0}{center}}', and I am going to ignore it. Perhaps you misspelled it. ...\pgfpointanchor{ep0}{center}}]ep0)}] (ep1)
我tangent
从 hobby's 那里得到了代码文档-- 参见第 17 页。我正在尝试进行设置,以便可以在所有文档中使用切线命令,这就是我尝试使用的原因tikzset
。这样,我就可以将代码片段插入到我的全局 *.sty 文件中。
我该如何解决这些错误?
答案1
您的代码有几个问题。首先,您没有正确地从文档中的示例中复制代码。特别是,您拼错了键;它们应该是:
\tikzset{
tangent/.style = {
in angle={(180+#1)},
Hobby finish,
designated Hobby path=next,
out angle=#1
}
}
注意空格。
但更严重的是,使用\pgfmathanglebetweenpoints
。这不会将答案留在流中,而是将结果存储在 中\pgfmathresult
。因此,要按需要使用它,您必须事先计算它,然后只将答案放在tangent
键中。
\pgfmathanglebetweenpoints{\pgfpointanchor{cep0}{center}}{\pgfpointanchor{ep0}{center}}
\let\angle=\pgfmathresult
\draw (ep2) to [curve through ={(sp0) .. ([tangent=\angle]ep0)}] (ep1) ;
(中间的一行是因为\pgfmathresult
很容易被覆盖。)
在全,
\documentclass{article}
%\url{http://tex.stackexchange.com/q/225878/86}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{calc, hobby}
\tikzset{
tangent/.style = {
in angle={(180+#1)},
Hobby finish,
designated Hobby path=next,
out angle=#1
}
}
\begin{document}
\begin{figure}[htbp]
\centering
\begin{tikzpicture}
\coordinate (y) at (0,3);
\coordinate (x) at (5,0);
\coordinate (sp0) at (1.5, 0);
\coordinate (ep0) at (3.5, 2);
\coordinate (csp0) at (2.5, 1);
\coordinate (cep0) at (2.75, 0);
\coordinate (sp1) at (ep0);
\coordinate (ep1) at (4.5, 3);
\coordinate (csp1) at (4.25, 4);
\coordinate (cep1) at (4.25, 2);
\coordinate (sp2) at (sp0);
\coordinate (ep2) at (0, -1);
\coordinate (csp2) at (0.5, -1);
\coordinate (cep2) at (0.5, -1);
\draw[<->] (y) node[left] {$f(x)$} -- (0,0) -- (x) node[below] {$x$};
\draw (sp0) .. controls (csp0) and (cep0).. (ep0);
\draw[dashed] (cep0) -- (csp1);
\draw[dotted] let \p1 = (ep0) in (ep0) -- (0, \y1);
\draw[dotted] let \p1 = (ep0) in (ep0)-- (\x1, 0);
\draw (sp1) .. controls (csp1) and (cep1).. (ep1);
\draw (sp2) .. controls (csp2) and (cep2).. (ep2);
\draw let \p1 = (ep0) in (\x1,1pt) -- (\x1,-3pt) node[anchor=north] {$x_0$};
\draw let \p1 = (cep0) in (\x1,1pt) -- (\x1,-3pt) node[anchor=north] {$x_1$};
\draw let \p1 = (ep0) in (1pt, \y1) -- (-3pt, \y1) node [anchor=east] {$f(x_0)$};
\end{tikzpicture}
\caption{Newton's method in action: diagram drawn using ``standard'' TiKZ methods.}
\label{fig:newton_method_1}
\end{figure}
\begin{figure}[htbp]
\centering
\begin{tikzpicture}
\coordinate (y) at (0,3);
\coordinate (x) at (5,0);
\coordinate (sp0) at (1.5, 0);
\coordinate (ep0) at (3.5, 2);
\coordinate (csp0) at (2.5, 1);
\coordinate (cep0) at (2.75, 0);
\coordinate (sp1) at (ep0);
\coordinate (ep1) at (4.5, 3);
\coordinate (csp1) at (4.25, 4);
\coordinate (cep1) at (4.25, 2);
\coordinate (sp2) at (sp0);
\coordinate (ep2) at (0, -1);
\coordinate (csp2) at (0.5, -1);
\coordinate (cep2) at (0.5, -1);
\draw[<->] (y) node[left] {$f(x)$} -- (0,0) -- (x) node[below] {$x$};
% Using \pgfmathanglebetweenpoints to calculate the angle for tangent
% tangent takes a degree unit angle
\pgfmathanglebetweenpoints{\pgfpointanchor{cep0}{center}}{\pgfpointanchor{ep0}{center}}
\let\angle=\pgfmathresult
\draw (ep2) to [curve through ={(sp0) .. ([tangent=\angle]ep0)}] (ep1) ;
\draw[dashed] (cep0) -- (csp1);
\draw[dotted] let \p1 = (ep0) in (ep0) -- (0, \y1);
\draw[dotted] let \p1 = (ep0) in (ep0)-- (\x1, 0);
\draw let \p1 = (ep0) in (\x1,1pt) -- (\x1,-3pt) node[anchor=north] {$x_0$};
\draw let \p1 = (cep0) in (\x1,1pt) -- (\x1,-3pt) node[anchor=north] {$x_1$};
\draw let \p1 = (ep0) in (1pt, \y1) -- (-3pt, \y1) node [anchor=east] {$f(x_0)$};
\end{tikzpicture}
\caption{Newton's method in action: diagram drawn using the \texttt{hobby} package.}
\label{fig:newton_method_2}
\end{figure}
\end{document}