我想输出 n 行“=......”形式的代码。学生必须在每一行上写下推导的一个步骤。我设法让它在 3 行上工作,但我的 n 行宏不起作用。
我的最小工作示例是:
\documentclass[11pt, a4paper, parskip=full]{scrartcl}
\usepackage{pgffor}
\usepackage{amsmath}
\newcommand*{\mystrut}{\rule[-0.05\baselineskip]{0pt}{1.2\baselineskip}}
\newcommand*{\mybox}[1]{\framebox{\mystrut #1}}
\newcommand{\derivblank}[1]{
\begin{align*}
\foreach \line in {1, ..., #1}{%
&= \hspace{0.2cm}\underline{\mystrut\hspace{3cm}} \\
}
&= \hspace{0.2cm} \mybox{\underline{ \hspace{3cm}}}
\end{align*}
}
\begin{document}
\section*{Derivation of 3 steps}
Write your derivation below in 3 steps:
\begin{align*}
&= \hspace{0.2cm}\underline{\mystrut\hspace{3cm}} \\
&= \hspace{0.2cm}\underline{\mystrut\hspace{3cm}} \\
&= \hspace{0.2cm} \mybox{\underline{ \hspace{3cm}}}
\end{align*}
\section*{Fails for arbitrary number of lines}
Write your derivation below in $n$ steps:
%\derivblank{2}
\end{document}
答案1
比对的每个单元都是一个本地组,您在一个单元中启动 pgf 循环,这样一旦插入&
范围结束,循环代码就会中断。
这是一个没有进行任何分配的版本,因此不受单元格范围的影响。
\documentclass[11pt, a4paper, parskip=full]{scrartcl}
\usepackage{pgffor}
\usepackage{amsmath}
\newcommand*{\mystrut}{\rule[-0.05\baselineskip]{0pt}{1.2\baselineskip}}
\newcommand*{\mybox}[1]{\framebox{\mystrut #1}}
\newcommand{\derivblank}[1]{%
\begin{align*}
\xderivblank{#1}%
&= \hspace{0.2cm} \mybox{\underline{ \hspace{3cm}}}
\end{align*}
}
\newcommand\xderivblank[1]{%
\ifnum#1=0 \else
&= \hspace{0.2cm}\underline{\mystrut\hspace{3cm}} \\
\xderivblank{\numexpr#1-1}\fi}
\begin{document}
\section*{Derivation of 3 steps}
Write your derivation below in 3 steps:
\begin{align*}
&= \hspace{0.2cm}\underline{\mystrut\hspace{3cm}} \\
&= \hspace{0.2cm}\underline{\mystrut\hspace{3cm}} \\
&= \hspace{0.2cm} \mybox{\underline{ \hspace{3cm}}}
\end{align*}
\section*{Fails for arbitrary number of lines}
Write your derivation below in $n$ steps:
\derivblank{2}
\end{document}