有没有办法在行末自动打破方框(例如 \raisebox)?

有没有办法在行末自动打破方框(例如 \raisebox)?

我是 LaTeX 的新手,因此非常感谢您的帮助:

每当您在 LaTeX 中输入普通文本时,如果到达行尾,它都会自动换行到下一行。但是,如果您在行尾使用框(例如 \raisebox),它会强制将框放入同一行,即使到达行尾也是如此。(据我所知,这会导致“\hbox 过满”警告。)

\documentclass{article}
\begin{document}
This is some text that automatically goes in the next line if the end of the line is reached.
\raisebox{0.1ex}{This is some text that does not automatically go in the next line if the end of the line is reached. This even goes above the edge of the paper.}
\end{document}

有没有办法自动中断行末的方框并继续处理下一行的方框?如果没有,至少有办法自动将整个方框放到下一行吗?

背景:我是一名教师,我正在尝试为我的学生创建“填空”任务。我通过输入普通文本然后使用以下命令来执行此操作:

\newlength{\diebox}
\newcommand{\blank}[1]{
    \settowidth{\diebox}{#1}
    \ifprintanswers
    \raisebox{0.1ex}{\parbox{2.3\diebox}{\textbf{#1}}}
    \else
    \raisebox{-0.5ex}{\parbox{2.3\diebox}{\hrulefill}}
    \fi}

(\ifprintanswers 来自考试包)

我使用因子“2.3”,这样我的学生就有更多的空间来写答案。

这确实按预期工作,除了在行尾我的答案/ hrulefill 没有换到下一行。

答案1

我通过使用递归来为答案中的每个单词创建一个新框,而不是只创建一个大的水平框,从而解决了这个问题。我还必须在\allowbreak框之间进行操作。此外,使用 2.3 乘数往往会破坏边距,因此我使用\sloppy它来避免这种情况。

\documentclass{exam}
\newcommand\blankit[1]{\blankitaux#1 \relax}
\def\blankitaux#1 #2\relax{%
  \blank{#1}%
  \ifx\relax#2\relax\def\next{}\else\def\next{\blankitaux#2\relax}\fi
  \next
}
\newcommand{\blank}[1]{\allowbreak
    \setbox0=\hbox{#1}%
    \ifprintanswers
    \makebox[2.3\wd0][l]{\textbf{#1}\dotfill}%
    \else
    \raisebox{-0.5ex}{\makebox[2.3\wd0]{\hrulefill}}%
    \fi
}
\begin{document}
\sloppy
This is some text that automatically goes in the next line if the end of the line is reached.
\blankit{This is some text that does not automatically go in the next line if the end of the line is reached. This even goes above and beyond the edge of the paper.}
Returning to normal text.

\printanswerstrue
This is some text that automatically goes in the next line if the end of the line is reached.
\blankit{This is some text that does not automatically go in the next line if the end of the line is reached. This even goes above and beyond the edge of the paper.}
Returning to normal text.
\end{document}

在此处输入图片描述

相关内容