如何使每行背景适应 parshape?

如何使每行背景适应 parshape?

我一直在 LuaTeX 中通过填充\localleftbox一个宽度设置为 0 但内容为长度为 的规则的框来在每行文本后面添加规则\textwidth。只要我有标准形状的段落,这种方法就可以正常工作。但是,我现在遇到了一种情况,我想对已使用 操纵形状的段落执行相同的操作\parshape

在下面的 MWE 中,由于规则是在文档开头以固定宽度创建的,因此它们不适应段落形状。有没有办法让它们适应段落形状?

\documentclass{article}

\usepackage{blindtext}

\newdimen\lefttest
\lefttest=1.5in
\newdimen\righttest
\righttest=1in

\localleftbox{\hbox to 0pt{\rule{\textwidth}{0.4pt}}}

\begin{document}

\noindent
\parshape=5
0in \dimexpr\textwidth-\righttest\relax
\lefttest \dimexpr\textwidth-\lefttest-\righttest\relax
\lefttest \dimexpr\textwidth-\lefttest-\righttest\relax
\lefttest \dimexpr\textwidth-\lefttest\relax
0in \textwidth
\blindtext

\end{document}

答案1

正如其他人在评论中所说的那样,\localleftbox这不是一个好的解决方案,因为它只接受一个不会改变的固定框,因此\localleftbox每当行长发生变化时,您都需要设置一个新的,这反过来又需要您知道行将如何断开。此时,您也可以手动添加背景。

尤其是如果您的背景由“规则”组成(规则应以 LuaTeX 的意义来解释,因此例如图像也是“规则”),您可以按照 Werner 的建议,通过查看用于下划线的包来使用预先存在的包。我显然有偏见,但我会lua-ul在这里推荐我的包:

\documentclass{article}

\usepackage{blindtext}
\usepackage{lua-ul}

\newdimen\lefttest
\lefttest=1.5in
\newdimen\righttest
\righttest=1in

% You can easily add more \newunderlinetype lines as long as you replace
% \paragraphlines with a unique name for each.
\newunderlinetype\paragraphlines[]{\leaders\vrule height 0.4pt depth 0pt}
\newunderlinetype\topparagraphlines[]{\leaders\vrule height 10pt depth -9.6pt}

\begin{document}

% Now activate the lines. This has to come after \begin{document}. These respect TeX groups if you only want to apply them to some parts. 
\paragraphlines
\topparagraphlines

\noindent
\parshape=5
0in \dimexpr\textwidth-\righttest\relax
\lefttest \dimexpr\textwidth-\lefttest-\righttest\relax
\lefttest \dimexpr\textwidth-\lefttest-\righttest\relax
\lefttest \dimexpr\textwidth-\lefttest\relax
0in \textwidth
\blindtext

\end{document}

在此处输入图片描述

相关内容