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?
5 Answers
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:

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

\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.
-
Thanks all. This is exactly what I meant, however: I was looking for a method that spreads text evenly on a horizontal line by increasing the letter-space, instead of the word-space. Is that possible too? – grrrbytes Apr 02 '12 at 21:17
-
So, 'exactly' was not the right wording. It is very close to what I want – grrrbytes Apr 02 '12 at 21:30
-
spread as a command to a box instruction is built into tex (texbook, p.77):
\documentclass{article}
\begin{document}
\hbox spread \linewidth{Here is some text.}
\end{document}

- 88,848
Using the soul package

\documentclass{article}
\usepackage{soul}
\sodef\ugg{}{.4em plus 1fill}{1em plus 2 fill}{2em plus 2fill minus.1em}
\begin{document}
\noindent\ugg{one two three\\four five six}
\end{document}
- 757,742
if you want to stretch all the letters evenly rather than words you can use:
\makeatletter
\def\spreadeven#1{%
\@tfor\next:=#1\do{%
\next\hfill
}%
}
\spreadeven{A fox jumped over the lazy dog}
\madeatother
This uses the LaTeX kernel @tfor to iterate over all the letters and add hfill between them.
- 117,160
-
Thanks for that. It almost does it as I wanted it, however it seems not to take spaces into consideration, so spaces won't be doubled. I can't differentiate between words anymore – grrrbytes Apr 02 '12 at 21:57
-
@Mixhael I answered this way based on your comments in Werner's answer. i think what you are looking is
\so{}using thesoulpackage. – yannisl Apr 02 '12 at 22:03
In ConTeXt there is the \stretched macro for this purpose. Example:
\starttext
\stretched{Here is some text}
\stoptext

- 26,055
\hfillbetween each word should produce the output you desire.. – Peter Grill Apr 02 '12 at 20:39