为什么下面的代码不能编译?

为什么下面的代码不能编译?

下面的程序在我的一台 Mac 电脑(旧电脑)的 TeXShop 中编译得很好,但在另一台电脑上却出错了。我一定是忘了在新电脑上安装什么东西,但不知道是什么。有什么想法吗?

  \begin{tikzpicture}
  \draw[very thin,color=gray] (1,1) ;
  \foreach \x/\xtext in {0.3/a, 1.58/c, 2*pi/b}
  \draw[shift={(\x,0)}] (0pt,2pt) -- (0pt,-2pt) node[below] {$\xtext$};
  \draw[->] (-0.2,0) -- (9,0) node[right] {$x$};
  \draw[->] (0,-0.2) -- (0,4.5) node[above] {$y$};
        \draw plot[domain=0.3:2*pi] 
            (\x, 0.5+{0.5*(\x)+sin((\x) r)}) node[above right] {$f$};
        \draw[-] [dotted]
           (0.3,0.5+{0.5*(0.3)+sin((0.3) r)})--(2*pi, 0.5+{pi+sin(2*pi r)}) ; 
        \node at (pi/2, 0.5+{0.25*pi+1}){$\bullet$};
        \draw[-] [draw=red]plot[domain=0.2:pi]
        (\x, {0.5+{0.25*pi+1}+0.5*(\x-pi/2)}) node[above]  {$f'(c)={f(b)-f(a)\over b-a}$};
   \end{tikzpicture}

错误信息:

<to be read again> 
               {
l.23 ...0.3:2*pi] (\x, 0.5+{0.5*(\x)+sin((\x) r)})
                                               node[above right] {$f$};

答案1

您的代码在数学表达式的分组方面存在一些语法错误;这里是更正后的版本:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
%\draw[very thin,color=gray] (1,1) ;
\foreach \x/\xtext in {0.3/a, 1.58/c, 2*pi/b}
  \draw[shift={(\x,0)}] (0pt,2pt) -- (0pt,-2pt) node[below] {$\xtext$};
\draw[->] (-0.2,0) -- (9,0) node[right] {$x$};
\draw[->] (0,-0.2) -- (0,4.5) node[above] {$y$};
\draw plot[domain=0.3:2*pi]
  (\x,{0.5 + 0.5*\x + sin((\x) r)}) node[above right] {$f$};
\draw[-] [dotted]
  (0.3,{0.5+0.5*(0.3)+sin((0.3) r)})--(2*pi,{0.5+pi+sin(2*pi r)}) ; 
\node at (pi/2, {0.5+ 0.25*pi+1}){$\bullet$};
\draw[-] [draw=red]plot[domain=0.2:pi]
  (\x, {0.5+0.25*pi+1+0.5*(\x-pi/2)}) node[above]  {$f'(c)={f(b)-f(a)\over b-a}$};

\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容