雙空間環境表現得很奇怪,我不知道該怎麼辦

雙空間環境表現得很奇怪,我不知道該怎麼辦

我是一名高中老師,希望使用 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} 
}

相關內容