0

Consider the code:

\documentclass[12pt]{article}

\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}

which produces the output:

enter image description here

I would like to center the last line of the text, which keeping the right and left justification of the previous lines. So, I modified the above code by

\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}

which produces:

enter image description here

Finally, this modification

\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}

produces what I am looking for:

enter image description here

As one can see, there is a lot of ``forcing'' taking place to accomplish this task.

QUESTION: Is there a more (most) efficient way to produce the output I am looking for without continually having to make manual adjustments. Is there a way to accomplish this automatically in Latex? I tend to produce many ``titles'' of this type in documents and am looking for a way to do this efficiently.

Thank you.

DDS
  • 8,816
  • 4
  • 9
  • 36
  • https://tex.stackexchange.com/questions/99364/how-to-center-the-last-line-of-a-paragraph – David Carlisle Mar 01 '21 at 19:59
  • @David Carlisle Yes; thank you, but I am working with minipage environment---the posting you provide does not. – DDS Mar 01 '21 at 20:20
  • 1
    sure but minipage is not relevent to the question, tex's paragraph line breaker is the same in minipage or table p columns or on the main page, so you can use the same parameters to control the last line. Just as if the question had been "how do I get italic in a minipage" the answer \itshape wouldn't actualy depend on it being in minipage. – David Carlisle Mar 01 '21 at 20:27

1 Answers1

4

The line breaking algorithm is the same for any paragraph, whether or not in a minipage you can balance \leftskip and \rightskip+\parfillskip so the last line is centred.

enter image description here

\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}

David Carlisle
  • 757,742