fully stretch text horizontally on page

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?

-
If it is just one line, adding \hfill between each word should produce the output you desire.. –  Peter Grill Apr 2 '12 at 20:39
I did not really make that clear, sorry for that, but I am looking for a method that solves this by letter-spacing, not word-spacing. See my comment below –  grrrbytes Apr 2 '12 at 21:18
look at the letterspacing tag: tex.stackexchange.com/questions/tagged/letterspacing –  David Carlisle Apr 2 '12 at 21:24
tnx, I am aware of that. However, this gives less flexibility in the sense you have to constantly alter the letter-spacing relative to the amount of characters, font, font-size, font-type and width of page. The examples below are quite close to what I want, however, they distribute on word-spacing –  grrrbytes Apr 2 '12 at 21:29
@Mixhael You could make your intent clearer; letterspacing is generally not a good typographical device for getting justified text. –  egreg Apr 2 '12 at 21:38

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 2 '12 at 21:17
So, 'exactly' was not the right wording. It is very close to what I want –  grrrbytes Apr 2 '12 at 21:30
Tnx @Werner, will look into the soul package –  grrrbytes Apr 2 '12 at 21:54

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}


-
Thanks, see my comment above :) –  grrrbytes Apr 2 '12 at 21:17
spread -- learning something new all the time :) –  yo' Apr 3 '12 at 12:38

if you want to stretch all the letters evenly rather than words you can use:

\makeatletter
\@tfor\next:=#1\do{%
\next\hfill
}%
}

\spreadeven{A fox jumped over the lazy dog}


This uses the LaTeX kernel @tfor to iterate over all the letters and add hfill between them.

-
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 2 '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 the soul package. –  Yiannis Lazarides Apr 2 '12 at 22:03

In ConTeXt there is the \stretched macro for this purpose. Example:

\starttext
\stretched{Here is some text}
\stoptext


-

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}

-
Many thanks @David –  grrrbytes Apr 3 '12 at 0:29