我是一名高中老师,希望使用 TeX 复制常见考试的格式 - 为了让我自己更容易做到这一点,我尝试编写命令来模仿常见问题。我目前在双倍行距环境中遇到了一些问题 - 格式使用双倍行距来创建问题行。这是我实现此功能的一个工作示例:
\newcounter{qnumber}
\newcounter{partnumber}[qnumber]
\newcommand{\writeq}[3][0]{ %simple written question command
\stepcounter{qnumber}
\textbf{Question \arabic{qnumber}\hfill (#2 marks)}\\
#3\\
\begin{doublespace}
\foreach \n in {1,...,#1}{\rule{\linewidth}{0.5pt}\\}
\end{doublespace}
}
\writeq[3]{4}{My question is this one.}
因此,我现在想要创建“多部分问题”,并构建了以下命令:
%Multi-part question commands
\newcommand{\mpqstem}[2]{
\stepcounter{qnumber}
\setcounter{partnumber}{0} % Reset part number
\noindent \textbf{Question \arabic{qnumber}\hfill (#1 marks)}\\ \\
#2 \vspace{0.2cm}
}
\newcommand{\mpq}[3][0]{ %simple written question command
\stepcounter{partnumber}
\alph{partnumber}) \hangindent=1.27cm \hangafter=0 #3\\
\rule{0pt}{1pt}\hfill(#2 marks)\vspace{0.5cm}
\begin{doublespace}
\foreach \n in {1,...,#1}{\rule{\linewidth-1.27cm}{0.5pt}\\}
\end{doublespace}
}
词干用于设置上下文,然后 mpq 命令是与该部分相关的实际问题。但是,使用这种组合,我得到的文本是双倍行距,但行距不是 - 我不知道为什么。请参见下面我尝试使用该命令以及我得到的结果:
\mpqstem{4}{This is the scary question, and thankfully this bit is showing up okay without any double-spacing. But that also makes sense, since this command doesn't touch the spacing.}
\mpq[2]{2}{This is part 1, and it's going to be very long to show what is happening with the spacing and make it clear that this is double-spaced.}
\mpq[2]{2}{This is part 2, and it's also going to be very long to show what is happening with the spacing and make it clear that this is double-spaced.}
答案1
您的代码片段无法编译,因为它缺少很多关键信息。不过,请务必牢记@UlrikeFischer 的建议,不要再使用\\
而不是\par
。例如,对于这三个命令,以下代码可能有助于实现您的最终格式化目标。
\newcounter{qnumber}
\newcounter{partnumber}[qnumber] tie 'partnumber' counter to 'qnumber' counter
\newcommand{\writeq}[3][0]{ %simple written question command
\refstepcounter{qnumber} % use \refstepcounter, not \stepcounter
\par\noindent
\textbf{Question \arabic{qnumber}\hfill(#2 marks)}
\par
#3
\par
\begin{doublespace}
\foreach \n in {1,\dots,#1}{\rule{\linewidth}{0.5pt}}
\par
\end{doublespace}
}
\newcommand{\mpqstem}[2]{
\refstepcounter{qnumber}
%%\setcounter{partnumber}{0} % not needed
\par\noindent
\textbf{Question \arabic{qnumber}\hfill(#1 marks)}
\par
\vspace{1\baselineskip}
#2
\par
\vspace{2mm}
}
\newcommand{\mpq}[3][0]{ %simple written question command
\refstepcounter{partnumber}
\par\noindent \hangindent=1.27cm \hangafter=0
\alph{partnumber}) #3
\par\noindent
\rule{0pt}{1pt}\hfill(#2 marks)
\par
\vspace{5mm}
\begin{doublespace}
\foreach \n in {1,\dots,#1}{\rule{\linewidth-1.27cm}{0.5pt}}
\par
\end{doublespace}
}