Text FormattingForce justification on one line of text

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
Bram
Posts: 20
Joined: Sat Jul 14, 2012 12:54 pm

Force justification on one line of text

Post by Bram »

I have a line of text in my document that almost fill a printed line. It is nicer to have them completely fill the printed line, so that they align with the rest of the text. How can I force justification?

Any help would be appreciated!

Code: Select all

\documentclass{memoir}
\begin{document}
This is a text that almost fills a complete printed line.
\end{document}

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Re: Force justification on one line of text

Post by cgnieder »

Does this line build a paragraph of its own?

Regards
site moderator & package author
Bram
Posts: 20
Joined: Sat Jul 14, 2012 12:54 pm

Re: Force justification on one line of text

Post by Bram »

Yes it is a paragraph of its own in this simplified example. In the layout I have in mind it is a kind of subtitle for a chapter, with some keywords that almost fill one line, bit I'ld rather have it exactly fill one line.
alainremillard
Posts: 45
Joined: Fri Mar 16, 2012 8:22 pm

Force justification on one line of text

Post by alainremillard »

You could use the \makebox command like this

Code: Select all

\documentclass{memoir}
\begin{document}
\makebox[\textwidth][s]{This is a text that almost fills a complete printed line.}
\end{document}
The first optional argument il the lenght of the box, and the second is the aligment of the text inside the box. "s" stand for spread. latex will make the interword space bigger to fit the text in the whole line.

If your parindent is greater than 0, you might have to set the lenght of the box manually.

have a good day
Alain Remillard
Bram
Posts: 20
Joined: Sat Jul 14, 2012 12:54 pm

Re: Force justification on one line of text

Post by Bram »

Great! That's exactly what I was looking for. Thanks for the help!
Post Reply