![有没有办法在行末自动打破方框(例如 \raisebox)?](https://linux22.com/image/420836/%E6%9C%89%E6%B2%A1%E6%9C%89%E5%8A%9E%E6%B3%95%E5%9C%A8%E8%A1%8C%E6%9C%AB%E8%87%AA%E5%8A%A8%E6%89%93%E7%A0%B4%E6%96%B9%E6%A1%86%EF%BC%88%E4%BE%8B%E5%A6%82%20%5Craisebox%EF%BC%89%EF%BC%9F.png)
我是 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}