是否可以将两端对齐的文本块最后一行的文本右对齐?

是否可以将两端对齐的文本块最后一行的文本右对齐?

有没有办法让文本右对齐,同时又能保证两端对齐?这特别适用于段落的最后一行,该行通常是左对齐的,或者例如非常短的一行段落,虽然是两端对齐的,但也会出现左对齐的情况。

谢谢您的帮助! :)

答案1

TeX\leftskip基元寄存器保存段落行左侧使用的跳过。跳过可以是可拉伸的,例如 0pt plus1fil。TeX 基元寄存器\rightskip保存段落行右侧使用的跳过。它可以是“负可拉伸的”。这并不意味着可收缩,但它会从中消除正可拉伸量\leftskip。TeX\parfillskip基元寄存器默认设置为(例如,通过纯 TeX)0pt plus1fil。它被添加到段落最后一行的末尾。如果我们设置:

\leftskip=0pt plus1fil
\rightskip=0pt plus-1fil

test text ...
\bye

然后段落的所有行(除了最后一行)都只有\leftskip左侧和\rightskip右侧。它们的和为零,因此只有单词之间的 glu 用于对齐。最后一行有 -1fil 形式和右侧的\rightskip1fil 。它们的和为零。但是还有另一个 1fil 。这个跳过被拉伸,结果就像这里的另一个答案中所示的那样。这个另一个答案使用 LaTeX 特定的语法来设置 TeX 原始寄存器。\parfillskip\leftskip

答案2

你只需要平衡跳跃,

在此处输入图片描述

\documentclass{article}

\begin{document}

\setlength\leftskip    {\stretch{1}}
\setlength\parfillskip {\stretch{1}}
\setlength\rightskip   {\stretch{-1}}

One two three One two three One two three One two three 
One two three One two three One two three One two three 
One two three One two three One two three One two three 
One two three One two three One two three One two three 
One two three One two three One two three One two three 
One two three One two three One two three One two three 
One two three One two three One two three One two three 



One two three One two three One two three One two three 
One two three One two three One two three One two three 
One two three One two three One two three One two three 
One two three One two three One two three One two three 
One two three One two three One two three One two three 
One two three One two three One two three One two three 
One two three One two three One two three One two three 
One two three One two three One two three One two three 
One two three One two three One two three One two three 
One two three One two three One two three One two three 
One two three One two three One two three One two three 
One two three One two three One two three One two three 
One two three One two three One two three One two three 
One two three One two three One two three One two three 
\end{document}

答案3

wipet 的答案起了作用。我只是想发布一个带有工作环境定义的小示例。

\documentclass{book}
\usepackage{lipsum}
\usepackage{ragged2e}

\newenvironment{justifyright}%
               {\justifying
                \leftskip=0pt plus1fil
                \rightskip=0pt plus-1fil}%
               {\par}

\begin{document}

\mainmatter
\begin{justifyright}
    \lipsum[1]
    \lipsum[2]
    \lipsum[3]
\end{justifyright}

\lipsum[1]
\lipsum[2]
\lipsum[3]


\end{document}

相关内容