Text FormattingForce last line in paragraph to justify

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
masher
Posts: 9
Joined: Fri Oct 23, 2009 4:24 am

Force last line in paragraph to justify

Post by masher »

How can I force the last line in a paragraph to justify to the right margin?

I am doing some micro-optimisations on my text/figure layout, and I want to insert figures and tables in the middle of paragraphs and have the text flow around them - Just the top and bottom, the figures are the full width of the text.

I would prefer to work with vanilla-LaTeX, and not have to use any external packages.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Force last line in paragraph to justify

Post by gmedina »

Hi,

this can be achieved by adjusting the \leftskip, \rightskip and \parfillskip lengths:

Code: Select all

\documentclass{book}
\usepackage{lipsum}% just to generate some text

\setlength\leftskip{0pt plus 1fil}
\setlength\rightskip{-\leftskip}
\setlength\parfillskip{\leftskip}

\begin{document}

\lipsum[1-4]

\end{document}
You can find an explanation on those parameters in the book TeX by Topic, by Victor Eijkhout, or in The TeXbook.

Edit: if you are planning to use these settings throughout your document, I would also suggest to use

Code: Select all

\setlength\parindent{0pt}
to avoid the situation illustrated at the end of the second paragraph in my example
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Post Reply