我已經安裝了 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 行讀取輸入檔時出現問題。