缺失数字视为零误差

缺失数字视为零误差

我已阅读了几篇有类似错误的帖子,但找不到我的错误在哪里。

我有以下代码用于在alignat*环境中的顺序不等式旁边添加注释。不幸的是,每次我使用\cm命令时,latex 都会给出错误,指出缺失的数字被视为零。我想我的某个长度命令中可能缺少一些参数,但我不知道在哪里。提前致谢。

\newlength{\argwidth}
\newlength{\whatsleft}
\newcommand{\measureremainder}[1]{%
\begin{tikzpicture}[overlay,remember picture]
    \path (current page.north west) ++(\hoffset, -\voffset)
        node[anchor=north west, shape=rectangle, inner sep=0, minimum             width=\paperwidth, minimum height=\paperheight]
        (pagearea) {};
    \path (pagearea.north west) ++(1in+\currentsidemargin,-1in-\topmargin-\headheight-\headsep)
        node[anchor=north west, shape=rectangle, inner sep=0, minimum width=\textwidth, minimum height=\textheight]
        (textarea) {};
    \path let \p0 = (0,0), \p1 = (textarea.east) in
        [/utils/exec={\pgfmathsetlength#1{\x1-\x0}\global#1=#1}];
\end{tikzpicture}%
}

\newcommand{\cm}[1]{&\quad&\hspace{1.3mm}\measureremainder{\whatsleft}\settowidth{\argwidth}{#1}\ifthenelse{\lengthtest{\argwidth < \whatsleft}}{\text{{#1}}}{\begin{minipage}[c]{\whatsleft} \raggedright {#1} \vspace{2mm}\end{minipage}}}

例如,我将按如下方式使用它:

\documentclass[12pt]{report}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[margins = 1.0in]{geometry}
\usepackage{MnSymbol}
\usepackage{tikz}
\usepackage{mathtools}
\usepackage{calc}
\usepackage{tkz-fct}
\usepackage{ifthen}
\usepackage{xifthen}

\newlength{\whatsleft}
\newlength{\argwidth}
\newcommand{\measureremainder}[1]{%
\begin{tikzpicture}[overlay,remember picture]
    \path (current page.north west) ++(\hoffset, -\voffset)
        node[anchor=north west, shape=rectangle, inner sep=0, minimum width=\paperwidth, minimum height=\paperheight]
        (pagearea) {};
    \path (pagearea.north west) ++(1in+\currentsidemargin,-1in-\topmargin-\headheight-\headsep)
        node[anchor=north west, shape=rectangle, inner sep=0, minimum width=\textwidth, minimum height=\textheight]
        (textarea) {};
    \path let \p0 = (0,0), \p1 = (textarea.east) in
        [/utils/exec={\pgfmathsetlength#1{\x1-\x0}\global#1=#1}];
\end{tikzpicture}%
}

\newcommand{\cm}[1]{&\quad &\hspace{1.3mm}\measureremainder{\whatsleft}\settowidth{\argwidth}{#1}\ifthenelse{\lengthtest{\argwidth < \whatsleft}}{\text{{#1} }}{\begin{minipage}[c]{\whatsleft} \raggedright {#1} \vspace{2mm}\end{minipage}}}

\begin{document}

\begin{alignat*}{2}
\lim_{x \to 3} x^2 - 4x + 3 &= \lim_{x \to 3} x^2 - \lim_{x \to 3} 4x + \lim_{x \to 3} 3 \cm{Using the sum rule} \\
&= \left(\lim_{x \to 3} x\right)\left(\lim_{x \to 3} x\right) - \left(4\lim_{x \to 3} x\right) + \lim_{x \to 3} 3 \cm{Using the product rule} \\
&= 3 \cdot 3 - 4 \cdot 3 + 3 \\ 
&= 0 \end{alignat*}

\end{document}

在此先感谢您的帮助。

答案1

错误发生在\lim之后的第一个位置\begin{alignat*}。此环境需要一个参数,即“方程列”的数量。由于\lim不是数字,TeX 会抛出错误。

除非您重新定义了\(\),否则它们会引起更多麻烦,因为它们通常用于内联数学模式。因此,我用普通括号替换了它们。我不认为,尽管有酸橙的索引,但这里需要\left\right。在我看来,普通括号在这里看起来更好。

完整示例(需要运行两次 LaTeX):

\documentclass{article}
\usepackage{ifthen}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc}

\newlength{\currentsidemargin}
\newlength{\argwidth}
\newlength{\whatsleft}
\newcommand{\measureremainder}[1]{%
  \begin{tikzpicture}[overlay,remember picture]
    \path
      (current page.north west) ++(\hoffset, -\voffset)
      node[
        anchor=north west,
        shape=rectangle,
        inner sep=0,
        minimum width=\paperwidth,
        minimum height=\paperheight
      ] (pagearea) {}
    ;
    \path
      (pagearea.north west)
      ++(1in+\currentsidemargin,-1in-\topmargin-\headheight-\headsep)
      node[
        anchor=north west,
        shape=rectangle,
        inner sep=0,
        minimum width=\textwidth,
        minimum height=\textheight
      ] (textarea) {}
    ;
    \path
      let \p0 = (0,0),
          \p1 = (textarea.east)
      in
        [/utils/exec={\pgfmathsetlength#1{\x1-\x0}\global#1=#1}]
    ;
  \end{tikzpicture}%
}

\newcommand{\cm}[1]{%
  &\quad
  &\hspace{1.3mm}%
  \measureremainder{\whatsleft}%
  \settowidth{\argwidth}{#1}%
  \ifthenelse{\lengthtest{\argwidth < \whatsleft}}{%
    \text{#1}
  }{%
    \begin{minipage}[c]{\whatsleft}
      \raggedright
      #1\par
      \vspace{2mm}%
    \end{minipage}%
  }%
}

\begin{document}
  \begin{alignat*}{2}
    \lim_{x \to 3} (x^2 - 4x + 3) &= \lim_{x \to 3} x^2 - \lim_{x \to 3} 4x +
    \lim_{x \to 3} 3 \cm{Using the sum rule} \\
    &= (\lim_{x \to 3} x)
       (\lim_{x \to 3} x)
       - 4(\lim_{x \to 3} x) +
    \lim_{x \to 3} 3 \cm{Using the product rule} \\
    &= 3 \cdot 3 - 4 \cdot 3 + 3 \\
    &= 0
  \end{alignat*}
\end{document}

结果

相关内容