[pdftex] [Slightly OT] Width of ragged text
Reinhard Kotucha
reinhard.kotucha at web.de
Sat Dec 27 00:51:55 CET 2003
>>>>> "Magnus" == Magnus Lie Hetland <magnus at hetland.org> writes:
> Hartmut Henkel <hartmut_henkel at gmx.de>:
>>
> [snip]
>> Something similar does varwidth.sty by Donald Arseneau, e. g.:
> Thanks -- that seems very useful. I didn't even think to look
> for a style file, only basic techniques... Ah, well. :)
If manual line breaking is sufficient, there is a quite simple
solution. Recently someone had a similar problem when he wanted to
create flow charts in metapost. My first thought was that I have to
step through the lines, determine each's length, remember the longest
line, create a box... It sounds difficult, but isn't it exactly
something TeX has to do when typesetting tables?
If you have large paragraphs, varwidth.sty is better because it uses
TeX's line breaking algorithm, but if there are only a few short
lines, it might be easier to use the tabular environment.
In the following example, I have put an \fbox around each box to make
it's size visible.
------------------------------------------------------------------
\documentclass{minimal}
\newcommand{\stacklines}[2]{\begin{tabular}
{@{\hspace{0pt}}#1@{\hspace{0pt}}}#2\end{tabular}}
\newcommand{\align}[2]{\multicolumn{1}{#1}{#2}}
\begin{document}
\setlength{\fboxsep}{0pt}
\fbox{\stacklines{l}{aajsdghg\\skafhds\\kfhdkfhdsdfjlf}}
\fbox{\stacklines{c}{aajsdghg\\skafhds\\kfhdkfhdsdfjlf}}
\fbox{\stacklines{r}{aajsdghg\\skafhds\\kfhdkfhdsdfjlf}}
\fbox{\stacklines{l}{aajsdghg\\\align{c}{skafhds}\\kfhdkfhdsdfjlf}}
\end{document}
------------------------------------------------------------------
Regards,
Reinhard
--
----------------------------------------------------------------------------
Reinhard Kotucha Phone: +49-511-4592165
Marschnerstr. 25
D-30167 Hannover mailto:reinhard.kotucha at web.de
----------------------------------------------------------------------------
Microsoft isn't the answer. Microsoft is the question, and the answer is NO.
----------------------------------------------------------------------------
More information about the pdftex
mailing list