考虑以下代码:
\documentclass[12pt]{文章}
\begin{document}
\begin{center}
\begin{LARGE}
\begin{minipage}{5.75in}
\textbf{\textit{Objective:} Though All the Lines (Except the Last) in This Paragraph (Which is to Serve as a Title) are Both Left and Right Justified, I Would Like the Last Line of a Paragraph of This Sort to Always be ``Centered''}
\end{minipage}
\end{LARGE}
\end{center}
\end{document}
输出结果如下:
我想将文本的最后一行居中,同时保持前几行的左右对齐。因此,我修改了上述代码
\begin{minipage}{5.75in}
\textbf{\textit{Objective:} Though All the Lines (Except the Last) in This Paragraph (Which is to Serve as a Title) are Both Left and Right Justified, I Would Like the Last Line of a Paragraph of This Sort to Always be \vskip 1pt \hfill \hskip 12pt ``Centered'' \hfill}
\end{minipage}
生成结果:
最后,这个修改
\begin{center}
\begin{LARGE}
\begin{minipage}{5.75in}
\textbf{\textit{Objective:} Though All the Lines (Except the Last) in This Paragraph (Which is to Serve as a Title) are Both Left and Right Justified, I Would Like the Last Line of a Paragraph \hfill of \hfill This \hfill Sort \hfill to \hfill Always \hfill be \vskip 1pt \hfill \hskip 12pt ``Centered'' \hfill}
\end{minipage}
\end{LARGE}
\end{center}
产生我正在寻找的内容:
正如我们所见,为了完成这项任务,需要进行大量的“强制”措施。
问题:有没有一种更 (最) 有效的方法来生成我想要的输出,而无需不断进行手动调整。有没有办法在 Latex 中自动完成此操作?我倾向于在文档中生成许多这种类型的“标题”,并正在寻找一种有效的方法。
谢谢。
答案1
无论您是否minipage
可以平衡,任何段落的换行算法都是相同的\leftskip
,\rightskip+\parfillskip
因此最后一行位于中央。
\documentclass[12pt]{article}
\begin{document}
\begin{center}
\begin{LARGE}
\begin{minipage}{5.75in}\leftskip\fill\rightskip-\leftskip\parfillskip\stretch{2}%
\textbf{\textit{Objective:} Though All the Lines (Except the Last) in This Paragraph (Which is to Serve as a Title) are Both Left and Right Justified, I Would Like the Last Line of a Paragraph of This Sort to Always be ``Centered''}
\end{minipage}
\end{LARGE}
\end{center}
\end{document}