我现在才遇到这个错误。我该如何解决它,错误位于代码的哪个位置?我还附上了代码的图片。
\begin{tasks}[style=itemize, label=\Alph*., after-item-skip=10pt, label-width = 2em, item-indent = 27pt](2)
\task \\ \begin{tikzpicture}\begin{axis}[axis lines=middle,axis on top,xlabel=$x$,ylabel=$y$,xmin=-4,xmax=4,ymin=-1.45,ymax=2,ytick={-4},yticklabels={$-4$}, xtick={1.5},xticklabels={$2$}] \addplot[smooth,color=black] coordinates{(\empty) (-1.3,-0.2)} node {$-2$};\end{axis}
\draw[ultra thick] (1.2,5) .. controls (1.4,4) and (1.8,2.4) .. (2.3,2.4);\draw[ultra thick] (3.5,3.7) .. controls (3.2,3.8) and (2.8,2.4) .. (2.3,2.4);\draw[ultra thick] (3.5,3.7) .. controls (3.7,3.8) and (4.1,2.4) .. (4.6,2.4);\draw[ultra thick] (5.7,5.2) .. controls (5.5,4.1) and (5.1,2.4) .. (4.6,2.4); \node at (3.7,2.1) {$0$};\end{tikzpicture}
\task \\ \begin{tikzpicture}\begin{axis}[axis lines=middle,axis on top,xlabel=$x$,ylabel=$y$,xmin=-4,xmax=4,ymin=-1.45,ymax=2,ytick={-4},yticklabels={$-4$}, xtick={1.5},xticklabels={$2$}] \addplot[smooth,color=black] coordinates{(\empty)(-1.3,-0.2)} node {$-2$};\end{axis}
\draw[ultra thick] (1.2,5) .. controls (1.4,4) and (1.8,2.4) .. (2.3,2.4);
\draw[ultra thick] (5.7,5.2) .. controls (5.5,4.1) and (5.1,2.4) .. (4.6,2.4);\node at (3.7,2.1) {$0$};\end{tikzpicture}
\task \\ \begin{tikzpicture}\begin{axis}[axis lines=middle,axis on top,xlabel=$x$,ylabel=$y$,xmin=-4,xmax=4,ymin=-1.45,ymax=2,ytick={-4},yticklabels={$-4$}, xtick={1.6},xticklabels={$2$}] \addplot[smooth,color=black] coordinates{(\empty)(-1.3,-0.2)} node {$-2$};\node at (3.7,2.1) {$0$};\end{axis}
\draw[ultra thick] (.4,4) .. controls (1.6,4) and (2.25,2.2) .. (2.15,2.4);
\draw[ultra thick] (3.5,3.7) .. controls (3.2,3.8) and (2.4,3) .. (2.15,2.4);
\draw[ultra thick] (3.5,3.7) .. controls (4.3,3.2) and (4.93,2.5) .. (4.8,2.4);
\draw[ultra thick] (6.7,4.2) .. controls (5.5,3.8) and (5.1,2.9) .. (4.8,2.4);\node at (3.7,2.1) {$0$};\end{tikzpicture}
\task \\ \begin{tikzpicture}\begin{axis}[axis lines=middle,axis on top,xlabel=$x$,ylabel=$y$,xmin=-4,xmax=4,ymin=-1.4,ymax=2,ytick={-4},yticklabels={$-4$}, xtick={1.65},xticklabels={$2$}] \addplot[smooth,color=black] coordinates{(\empty)(-1.3,-0.2)} node {$-2$};\end{axis}
\draw[ultra thick] (.4,4.2) .. controls (2,4) and (2.2,2) .. (2.2,2.4);
\draw[ultra thick] (6.7,4.2) .. controls (5.5,3.8) and (5.1,2.9) .. (4.8,2.35);
\node at (3.7,2.1) {$0$};
\end{tikzpicture}
\end{tasks}
答案1
仅关注图像:
- 我会把它们画成纯粹
tikzpicture
的 - 图中曲线最好(也更简单)绘制为一条相对于给定坐标具有明确方向的线。例如,第一个代码
tikzpicture
可以是:
\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\tikzset{lbl/.style = {below, fill=white, font=\footnotesize}}
\begin{tikzpicture}
% axis
\draw (-3,0) -- ++(6,0) node[below left] {$x$}
(0,-1) -- ++(0,5) node[below left] {$y$};
\foreach \x in {-2,0,2}
\draw (0.5*\x,0.1) -- ++ (0,-0.2) node[lbl] {$\x$};
\draw[very thick, red]
(-2,3) .. controls +(0.2,-1) and +(-0.5,0) .. (-1,0)
.. controls +(0.5,0) and +(-0.3,0) .. (0,1)
.. controls +(0.3,0) and +(-0.5,0) .. (1,0)
.. controls +(0.5,0) and +(-0.2,-1) .. (2,3);
\end{tikzpicture}
\end{document}
用类似的方法可以画出其他图片。当曲线包含两个(不相连的)线段时,分别画出它们。
当然,你可以把这个图像画成pgfplots
图表。但在这种情况下,定义函数和你想画的域会很方便。