[Tex/LaTex] fully stretch text horizontally on page

horizontal alignmentletterspacingtext manipulation

Is there a way to fully stretch one line of text on the full width of the page, without manually setting the letter spacing, no matter how many characters on the line?

Best Answer

I assume you are referring to the spacing between words (or inter-word spacing) when you reference "a line text".

If the number of characters will always fit on the line, then the optional s-parameter for \makebox alignment inserts enough inter-word spacing stretch to fill the box. If the text is greater than the box width, an overfull \hbox warning is generated:

enter image description here

\documentclass{article}
\setlength{\parindent}{0pt}% Just for this example.
\begin{document}
\makebox[\linewidth][s]{Here is some text.} \par
\makebox[\linewidth][s]{Here is some more text.} \par
\makebox[\linewidth][s]{Here is a whole whack of text, plus some punctuation.} \par
\makebox[\linewidth][s]{Here is a whole whack of text, plus some punctuation, and then some more text.} \par
\makebox[\linewidth][s]{Here is a whole whack of text, plus some punctuation, and then some more text, and nothing else.} \par
\end{document}​

The last line stretches beyond the text margin. In the above minimal working example (MWE), replacing \linewidth with \textwidth would also work.


For inter-letter spacing, the soul package can be of help. You define your own inter-letter, inner and outer spaces via a command \sodef{<cmd>}{<font>}{<inter-letter>}{<inner space>}{<outer space>}:

enter image description here

\documentclass{article}
\usepackage{soul}% http://ctan.org/pkg/soul
\setlength{\parindent}{0pt}% Just for this example.
\begin{document}
\sodef\spaceout{}{0pt plus 1fil}{.4em plus 1fil}{0pt}
\makebox[\linewidth][l]{\spaceout{Here is some text.}} \par
\makebox[\linewidth][l]{\spaceout{Here is some more text.}} \par
\makebox[\linewidth][l]{\spaceout{Here is a whole whack of text, plus some punctuation.}} \par
\makebox[\linewidth][l]{\spaceout{Here is a whole whack of text, plus some punctuation, and then some more text.}} \par
\makebox[\linewidth][l]{\spaceout{Here is a whole whack of text, plus some punctuation, and then some more text, and nothing else.}} \par
\end{document}​

Since I am unfamiliar with this kind of modification, consider this just a guide to get you going. The soul package documentation (section 3 Letter spacing, p 8 onward) is filled with examples.

I'm sure microtype would also be able to facilitate your needs.

Related Question