Latex 考試課程:答案的線寬

Latex 考試課程:答案的線寬

我正在使用乳膠考試課程來解答簡短的問題,這些問題提供了答案。以下程式碼為我提供了跨越頁面整個寬度的答案行。我想控制這些線的寬度,以便我可以根據我的選擇減少它們(1英寸,2英寸等)

\begin{document}
\begin{questions}
\question What is your name? \fillwithlines{3cm}
\end{questions}
\end{document}

例如,這是我使用現有程式碼得到的結果:

在此輸入影像描述

而我想要以下內容: 在此輸入影像描述

如果您在這方面提供任何幫助,我將不勝感激。謝謝

答案1

正如評論中提到的,使用minipage環境可能是最簡單的解決方案。如果您經常這樣做,您可以建立minipage該命令的版本\fillwithlines。這需要一個可選的寬度參數,\linewidth如果不使用則預設為。

\documentclass{exam}
\NewDocumentCommand{\Fillwithlines}{O{\linewidth}m}{
\par\begin{minipage}{#1}
\fillwithlines{#2}
\end{minipage}}
\begin{document}
\begin{questions}
\question What is the answer to this question?

\Fillwithlines[3in]{1in}

\question What is the answer to this question?

\Fillwithlines{1in}
\end{questions}
\end{document}

程式碼的輸出

答案2

此程式碼將行的硬連線長度 ( ) 替換為可在問題之前設定的\hsize自訂長度 ( )。\linelength

乙

\documentclass{exam}
    
%**************************************** added <<<<<<<<<<<<
\usepackage{xpatch}
\newlength{\linelength}
\setlength{\linelength}{\hsize}% default length
\makeatletter
\xpatchcmd{\do@fillwithlines}
{\hsize}{\linelength}{}{}
\makeatother
%****************************************

\begin{document}
    \begin{questions}
        \setlength{\linelength}{1.5in}% choose the line length <<<<<<<<<<<<<<<<<<<<
        \question What is your name? \fillwithlines{3cm}
                    
        \setlength{\linelength}{2.5in}% choose the line length <<<<<<<<<<<<<<<<<<<<
        \question What is your name? \fillwithlines{3cm}
    \end{questions}

\end{document}

相關內容