Latex 試験クラス: 回答の線幅

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

b

\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}

関連情報