當行包含“makebox”時如何管理換行符?

當行包含“makebox”時如何管理換行符?

如果我在課堂上寫填空題exam,如下圖:

\documentclass[addpoints]{exam}

\begin{document}
\begin{questions}
\question [3] The protagonist, originally from \makebox[2in]{\dotfill}, has to travel up the \makebox[2in]{\dotfill} River to retrieve \makebox[2in]{\dotfill}.
\end{questions}
\end{document}

這些線條沒有正確斷開,而是一直延伸到頁面邊緣,如下所示:

在此輸入影像描述

我可以強制\\換行,這確實會產生可接受的結果:

在此輸入影像描述

但這似乎很笨拙。有沒有更優雅的方法來處理這種情況?

答案1

你不妨讓點擴大而不是空白,這樣換行就容易多了

在此輸入影像描述

\documentclass[addpoints]{exam}

\newcommand\mydotfill[1]{{\def\hfill{\hskip #1 plus 1fill\relax}\nolinebreak\dotfill}}
\begin{document}
\begin{questions}
\question [3] The protagonist, originally from \mydotfill{2in}, has to travel up the \mydotfill{2in} River to retrieve \mydotfill{2in}.
\end{questions}
\end{document}

相關內容