我已经安装了 texlive 完整包:
我使用 TeXmaker,这是我想绘制网格的代码,就像在 tikzpicture 中一样。我只想调用\gridkar
下面定义的函数。所以我在 中定义了它\newcommand
。不幸的是,它返回了两个错误:
Undefined Control Sequence \gridkar
和
Package PGF Math Error: Unknown Function 'x' (in 'x')
\documentclass[12 pt]{exam}
\usepackage[T1]{fontenc}
\usepackage{tgtermes}
\usepackage{amsmath,amssymb,color}
\usepackage{enumerate,graphicx}
\usepackage{tikz}
\usepackage{xargs}
\usepackage{latexsym}
\pagestyle{head}
\firstpageheader{Math110}{October 2}{Quiz 3}
\shadedsolutions
\definecolor{SolutionColor}{rgb}{.87,.87,.87}
\newcounter{x}
\newcounter{y}
\newcommand{\gridkar}[2]
{
\begin{tikzpicture}[scale=0.4]
\forLoop{-#1}{#1}{x}
{
\draw[-] (x,-#2) -- (x,#2);
}
\forLoop{-#2}{#2}{y}
{
\draw[-] (-#1,y) -- (#1,y);
}
\end{tikzpicture}
}
\begin{document}
\noindent Name:\hfill Section: 008
\noindent Directions: For each problem please show all your work in the space provided. Calculators are permitted; however, in order to receive partial or full credit on a problem you must show your work. You could use the blank side of this sheet too.\\
\textbf{Maximum Points: 6}\hspace*{\fill}\textbf{Time Limit: 10 minutes}
\begin{questions}
\question [2]\gridkar{7}{8}
\question [3]
\question [1]
\end{questions}
\end{document}
如何修复?我是否遗漏了任何软件包?
答案1
您不需要 for 循环操作,TikZ 有自己的操作。我提供了一种可能性,但您也可以使用 TikZgrid
键。我还提供了另一个示例。
\documentclass[12 pt]{exam}
\usepackage[T1]{fontenc}
\usepackage{tgtermes}
\usepackage{amsmath,amssymb} % No need and deprecated -> color
\usepackage{enumerate} % % No need -> graphicx
\usepackage{tikz} % Tikz loads graphicx and xcolor
\usepackage{xargs}
\usepackage{latexsym}
\pagestyle{head}
\firstpageheader{Math110}{October 2}{Quiz 3}
\shadedsolutions
\definecolor{SolutionColor}{rgb}{.87,.87,.87}
\newcommand{\gridkar}[2]
{
\begin{tikzpicture}[scale=0.4,baseline]
\foreach\x in {-#1,...,#1}
{
\draw[-] (\x,-#2) -- (\x,#2);
}
\foreach\y in {-#2,...,#2}
{
\draw[-] (-#1,\y) -- (#1,\y);
}
\end{tikzpicture}
}
\begin{document}
\noindent Name:\hfill Section: 008
\noindent Directions: For each problem please show all your work in the space provided.
Calculators are permitted; however, in order to receive partial or full credit on a problem
you must show your work. You could use the blank side of this sheet too.
\textbf{Maximum Points: 6}\hspace*{\fill}\textbf{Time Limit: 10 minutes}
\begin{questions}
\question [2]\gridkar{7}{8}
\question [3]\tikz[baseline,scale=0.4]\draw (-7,-8) grid[step=1] (7,8);
\question [1]
\end{questions}
\end{document}
答案2
你的问题在于你没有很好地读取日志文件。终端和日志文件显示:
! Undefined control sequence.
\gridkar ...gin {tikzpicture}[scale=0.4] \forLoop
{-#1}{#1}{x} { \draw [-] (...
l.40 \question [2]\gridkar{7}{8}
第一行说有未定义的控制序列。仅此而已。这里没有提到序列。第二行在问题的地方被打破了。它包括一部分宏体。左侧提到了当前正在处理哪个宏。问题在 的地方\forLoop
。这意味着这是未定义的控制序列。
最后一行(以 为前缀l.40
)表示在第 40 行读取输入文件时出现问题。此处显示此行的内容。