Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

setting parbox to natural width

1,696 views
Skip to first unread message

Carel Fellinger

unread,
Oct 29, 2001, 4:48:32 PM10/29/01
to
Ever so often I come across a typesetting problem for which I think
setting a parbox or a minipage to its natural width would really
solve the problem. But in all those years of happy TeXing I never
discovered the trick of doing it. (Well I know of using a tabbing
environment inside a minipage, but that has it's own pittfalls:)

If any of you guys could help me out, I would be very pleased.
O, and I don't mind if it can only be done with TeX code.


--
groetjes, carel

David Kastrup

unread,
Oct 29, 2001, 5:04:59 PM10/29/01
to
>>>>> "Carel" == Carel Fellinger <cfel...@iae.nl> writes:

Carel> Ever so often I come across a typesetting problem for which
Carel> I think setting a parbox or a minipage to its natural width
Carel> would really solve the problem.

This is utter nonsense. A parbox or a minipage comes into being by
wrapping lines to a specified width. It has no natural width, it only
has an artificial width. Are you sure you don't confuse this with the
single-line lrboxes or \makebox?

--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
Email: David....@t-online.de

Ross Darnell

unread,
Oct 29, 2001, 5:20:12 PM10/29/01
to
Carel Fellinger <cfel...@iae.nl> writes:

> Ever so often I come across a typesetting problem for which I think
> setting a parbox or a minipage to its natural width would really
> solve the problem. But in all those years of happy TeXing I never
> discovered the trick of doing it. (Well I know of using a tabbing

[...]

I am not sure what you mean by "natural width" but does

\begin{minipage}[t]{\linewidth}
\end{minipage}

or

\parbox{\linewidth}{This should be as wide as the lines in the
current environment.}

Ross Darnell

Carel Fellinger

unread,
Oct 29, 2001, 8:02:12 PM10/29/01
to
David Kastrup <David....@t-online.de> wrote:
>>>>>> "Carel" == Carel Fellinger <cfel...@iae.nl> writes:

> Carel> Ever so often I come across a typesetting problem for which
> Carel> I think setting a parbox or a minipage to its natural width
> Carel> would really solve the problem.

> This is utter nonsense. A parbox or a minipage comes into being by
> wrapping lines to a specified width. It has no natural width, it only
> has an artificial width. Are you sure you don't confuse this with the
> single-line lrboxes or \makebox?

Yep, possitive. I know, I should have given an example rightaway.

At the moment I'm making inlays for some cd's, like:

\newenvironment{Tracks}
{\begin{tabular}[t]{cl}}
{\end{tabular}}

\newcommand{\track}[3]{%params: nr, title, time
\fbox{#1} & #2 {\small #3} \\}

\begin{centering}
\begin{Tracks}
\track{1}{some title}{3:49}
...
\end{Tracks}\hfill\begin{Tracks}
\track{11}{some other very long\\and silly title}{6:59}
...
\end{Tracks}
\end{centering}

For long lists of titles, I split the index and put two on a row.
But then some titles are to long to fit on a line, and have to be split.
A straightforward way would be to use "\\" inside the second arg to \track.

Ofcourse, I could use a 'p' column instead of the 'l' column, but then
I've to decide on how much space to use for the first half of the index
(on the left) and how much to use for the second half (on the right).
I'd rather have TeX do the calculations involved:)

Ofcourse, I could change \track like:

\renewcommand{\track}[3]%params: nr, title, time
\fbox{#1} &%
\begin{minipage}{0pt}%
\begin{tabbing}%
#2 {\small #3}%
\end{tabbing}%
\end{minipage}%
\\}

but this would mean trouble if I changed fonts inside the title
argument. The tabbing env resets all decls at each "\\" :(
Moreover, if I put the "\\" inside the time argument, I
seem to loose the rest of the time.

Hope this example clarifies my perceived needs.
--
groetjes, carel

Carel Fellinger

unread,
Oct 29, 2001, 8:09:53 PM10/29/01
to
Ross Darnell <ro...@mcs.une.edu.au> wrote:
...
> I am not sure what you mean by "natural width" but does

To me it is the natural length of the longest line inside it.
Ofcourse all line breaks would have to be specified for such a
magical minipage.

> \begin{minipage}[t]{\linewidth}
> \end{minipage}

> or

> \parbox{\linewidth}{This should be as wide as the lines in the
> current environment.}

here I've to specify the width, I'd rather do this indirectly by
providing all linebreaks inside the minipae/parbox. For an example of
why I prefer this see an other posting of mine in this thread.

--
groetjes, carel

Donald Arseneau

unread,
Oct 29, 2001, 11:14:52 PM10/29/01
to
Carel Fellinger <cfel...@iae.nl> writes:

> Ever so often I come across a typesetting problem for which I think
> setting a parbox or a minipage to its natural width would really
> solve the problem.

Despite the nonsense of what you write, I understand :-)

Use package and environment tabularx.


Donald Arseneau as...@triumf.ca

Gert und Ulrike Fischer

unread,
Oct 30, 2001, 6:29:44 AM10/30/01
to

Carel Fellinger schrieb:


>
> Yep, possitive. I know, I should have given an example rightaway.
>
>

> For long lists of titles, I split the index and put two on a row.
> But then some titles are to long to fit on a line, and have to be split.
> A straightforward way would be to use "\\" inside the second arg to \track.

tabular is able to calculate the "natural width", so why don't you use a
tabular for the title (inside the other tabular)?

Ulrike Fischer

Carel Fellinger

unread,
Oct 31, 2001, 10:48:57 AM10/31/01
to
Donald Arseneau <as...@triumf.ca> wrote:
> Carel Fellinger <cfel...@iae.nl> writes:

>> Ever so often I come across a typesetting problem for which I think
>> setting a parbox or a minipage to its natural width would really
>> solve the problem.

> Despite the nonsense of what you write, I understand :-)

But I don't:( Where is the nonsense hiding you all seem refering to?
I know parbox and minipage don't have a natural width in the current
implementation. But a minipage does take the width of an embedded
tabbing environment, and that tabbing env does have a natural width.
The disadvantage of a tabbing env, though, is that font alterations
don't survive a newline and that you can't have a grouping with an
embedded newline.

> Use package and environment tabularx.

Nay, then I would still need to specify the width, be it relative
to the total table width. This wouldn't solve my problem of putting
two tables next to each other when the relative width of both tables
is unknown.

Maybe an other example will clarify my needs.

Say I want to put two poems side by side. The first has only short
lines, the second long lines. Using twocolumns would allot each of
them the same amount of space, resulting in a lot of white space in
between. I'd rather give the short lined poem less space.

To complicate things, they are modern poems, using a lot of fonts in
several sizes, even changing the inter line space seamingly at random.

I would hope I could encode it like this:

\begin{someMiniPageWithNaturalWidth}
\begin{verse}
haha {\tiny said\\
the clown\\}
hoho
\end{verse}
\end{someMiniPageWithNaturalWidth}
\qquad\qquad
\begin{someMiniPageWithNaturalWidth}
\begin{verse}
hahahahahahahaha {\tiny said\\
the clown\\}
hohohahahahahahahah
\end{verse}
\end{someMiniPageWithNaturalWidth}
--
groetjes, carel

Gert und Ulrike Fischer

unread,
Oct 31, 2001, 11:18:27 AM10/31/01
to

Carel Fellinger schrieb:


>
> Nay, then I would still need to specify the width, be it relative
> to the total table width. This wouldn't solve my problem of putting
> two tables next to each other when the relative width of both tables
> is unknown.
>

> Maybe an other Example will clarify my needs. ...

Take a look at the package eqparbox.

Ulrike Fischer

Carel Fellinger

unread,
Oct 31, 2001, 2:27:26 PM10/31/01
to

I would love to try it, but I can't find it with CTAN, so
any further hint of where to get it would be welcomed:)

--
groetjes, carel

Ralf Stubner

unread,
Oct 31, 2001, 2:52:59 PM10/31/01
to
Carel Fellinger <cfel...@iae.nl> writes:

on CTAN, of course: macros/latex/contrib/supported/eqparbox/

cheerio
ralf

PS: Don't search for *.sty, as many packages come as *.dtx.

--
Ralf Stubner * mailto:ralf.s...@physik.uni-erlangen.de
Lehrstuhl fuer theoretische Festkoerperphysik * Staudtstr. 7
D-91058 Erlangen * http://www.tfkp.physik.uni-erlangen.de/~ralf/

Carel Fellinger

unread,
Oct 31, 2001, 6:11:43 PM10/31/01
to
Ralf Stubner <ralf.s...@physik.uni-erlangen.de> wrote:
...

> on CTAN, of course: macros/latex/contrib/supported/eqparbox/

thanks. [must have filled in the wrong section in the search engine]

But helas, this package has the same short coming, it uses a tabular
environment to guess the natural width, but such env's don't play well
with font changes ranging several lines:(

So I guess I've to specify the maximum length after all, to bad.

--
groetjes, carel

Donald Arseneau

unread,
Oct 31, 2001, 8:48:39 PM10/31/01
to
Carel Fellinger <cfel...@iae.nl> writes:

> Donald Arseneau <as...@triumf.ca> wrote:
> > Carel Fellinger <cfel...@iae.nl> writes:
>
> >> Ever so often I come across a typesetting problem for which I think
> >> setting a parbox or a minipage to its natural width would really
> >> solve the problem.
>
> > Despite the nonsense of what you write, I understand :-)
>
> But I don't:( Where is the nonsense hiding you all seem refering to?

It was what other people were referring to (and in response to their
messages): that a "paragraph" breaks at a specified width, as opposed
to something with all forced line breaks.

I was also forgetting how tabularx handles narrow columns.

Donald Arseneau as...@triumf.ca

Carel Fellinger

unread,
Nov 1, 2001, 4:13:31 PM11/1/01
to
Donald Arseneau <as...@triumf.ca> wrote:
> Carel Fellinger <cfel...@iae.nl> writes:

>> Donald Arseneau <as...@triumf.ca> wrote:
...


>> > Despite the nonsense of what you write, I understand :-)
>>
>> But I don't:( Where is the nonsense hiding you all seem refering to?

> It was what other people were referring to (and in response to their
> messages): that a "paragraph" breaks at a specified width, as opposed
> to something with all forced line breaks.

Ah, I see. So I'd better refrase my quest:)

I'm looking for a way to put a series of lines with all line breaks
forced in a box. The width of that box then has to be the max of the
natural widths of all lines in that box.

But by now I guess there is no easy way to achieve this:(

--
groetjes, carel

David Kastrup

unread,
Nov 1, 2001, 4:54:33 PM11/1/01
to
>>>>> "Carel" == Carel Fellinger <cfel...@iae.nl> writes:

Carel> I'm looking for a way to put a series of lines with all
Carel> line breaks forced in a box. The width of that box then
Carel> has to be the max of the natural widths of all lines in
Carel> that box.

Carel> But by now I guess there is no easy way to achieve this:(

\begin{tabular}{@{}l@{}}
text with forced line breaks\\
and more text with forced line breaks\\
and so on.
\end{tabular}

Carel Fellinger

unread,
Nov 1, 2001, 7:36:29 PM11/1/01
to
David Kastrup <David....@t-online.de> wrote:
>>>>>> "Carel" == Carel Fellinger <cfel...@iae.nl> writes:

> Carel> I'm looking for a way to put a series of lines with all
> Carel> line breaks forced in a box. The width of that box then
> Carel> has to be the max of the natural widths of all lines in
> Carel> that box.

...familiar tabual example snipped

Arch, I underspec-ed my quest:(
I want to be able to change typestyle/font size somewhere and have
that change carry over into the next line. But elas, as I posted before,
that doen't work with tabular (at least not when I tried it)

e.g. the following doen't work

\begin{tabular}{@{}l@{}}
text with forced line {\small breaks\\


and more} text with forced line breaks\\
and so on.
\end{tabular}
--

groetjes, carel

Donald Arseneau

unread,
Nov 1, 2001, 9:17:24 PM11/1/01
to
Carel Fellinger <cfel...@iae.nl> writes:

Since you want seamless propagation of font settings, the normal
ways (tabular, tabbing) won't work, and there are no ready alternatives.

There is the possibility of such an environment, by post-processing
the material. It can't work in general, but only with a limited
subset of text arguments. LaTeX *could* have been written to make
such environments feasible, but is not. You would have to avoid:
\labels and other shells of \write; \color or other uses of \special;
sections or anything else that puts a \mark on the vertical list;
lists (indented lists at least); equations; \hrule (not really LaTeX
anyway).


Donald Arseneau as...@triumf.ca

Carel Fellinger

unread,
Nov 2, 2001, 1:56:50 PM11/2/01
to
Donald Arseneau <as...@triumf.ca> wrote:
> Carel Fellinger <cfel...@iae.nl> writes:
...

>> But by now I guess there is no easy way to achieve this:(

> Since you want seamless propagation of font settings, the normal
> ways (tabular, tabbing) won't work, and there are no ready alternatives.

> There is the possibility of such an environment, by post-processing
> the material. It can't work in general, but only with a limited

have been thinking of this, but my lack of TeXpertise prohibits it:(

> subset of text arguments. LaTeX *could* have been written to make
> such environments feasible, but is not. You would have to avoid:
> \labels and other shells of \write; \color or other uses of \special;
> sections or anything else that puts a \mark on the vertical list;
> lists (indented lists at least); equations; \hrule (not really LaTeX
> anyway).

Thanks for your clear anwser. I will put this quest to rest, and
live with it that I've to (guess and) specify widths in these cases.

Just wondering, does ConTeXt do any better in this respect?
(just started reading up an it, and I really can't judge yet
what ConTeXt benefits are with respect to LaTeXe or LaTeX3)

--
groetjes, carel

Stephan Lehmke

unread,
Nov 11, 2001, 10:53:38 AM11/11/01
to
In article <yfibsil...@triumf.ca>, Donald Arseneau writes:

> Carel Fellinger <cfel...@iae.nl> writes:
>
>> I'm looking for a way to put a series of lines with all line breaks
>> forced in a box. The width of that box then has to be the max of the
>> natural widths of all lines in that box.
>>
>> But by now I guess there is no easy way to achieve this:(
>
> Since you want seamless propagation of font settings, the normal
> ways (tabular, tabbing) won't work, and there are no ready alternatives.
>
> There is the possibility of such an environment, by post-processing
> the material. It can't work in general, but only with a limited
> subset of text arguments. LaTeX *could* have been written to make
> such environments feasible, but is not. You would have to avoid:
> \labels and other shells of \write; \color or other uses of \special;
> sections or anything else that puts a \mark on the vertical list;
> lists (indented lists at least); equations; \hrule (not really LaTeX
> anyway).

A lot of the above can be used in horizontal mode inside the parbox,
or encapsulated in hboxes.

TeXPower contains code of this kind, for calculating a `good' width
for vertical panels (see
http://lrb.cs.uni-dortmund.de/~lehmke/pub/paneltest.pdf). I just
ripped out the code to make a `naturalparbox' package.

If you put the following:

----------------------------------------------------------------------
% File: naturalparbox.sty
%
% Crude attempt at making parboxes of `natural' width.
%
% Author: Stephan Lehmke <Stephan...@cs.uni-dortmund.de>
%

\NeedsTeXFormat{LaTeX2e}

\ProvidesPackage{naturalparbox}
[2001/11/11 Attempt at making parboxes of `natural' width]

\RequirePackage{ifthen}
\RequirePackage{calc}

% User-configurable: Which `resolution' should be used when searching for `best' width?
\newcommand{\optwidthsteps}{100}

% User-configurable: Which badness should be tolerated as `perfect' (stopping the search for a better one).
\newcommand{\optwidthlinetolerance}{200}

% Internal parameter: Badness of the parbox currently under consideration.
\let\maxbadness@NPB=\@tempcnta

\newlength{\maxheight@NPB}
\newlength{\optwidth@NPB}
\newlength{\tempdima@NPB}
\newcounter{probe@NPB}
\newboolean{carryon@NPB}
\newbox\tempbox@NPB

% \naturalparbox[<max width>][<max height>]{<contents>} will (try to)
% automatically calculate the `best' width of a \parbox to contain
% <contents> and then set <contents> into a \parbox of this width.
%
% The optional parameters <max width> (default \linewidth) and <max
% height> (default \textheight) limit the growth of the box. If not
% both can be respected, <max width> will be respected and <max
% height> violated.
%
% Owing to limitations set by TeX, there are certain limits to the
% sophistication of the procedure for finding the `optimal' width. For
% instance, any `whatsits' (specials (like color changes), file
% accesses (like \label), or hyper anchors) or rules which are
% inserted directly in the vertical list of the parbox `block' the
% analysis, so the procedure can't `see' past them (starting at the
% bottom of the box) when analysing the contents of the parbox. The
% user should make sure such items are set in horizontal mode (by
% using \leavevmode or enclosing stuff in boxes). Furthermore, only
% overfull and underfull hboxes which occur while setting the parbox
% are considered when judging which width is `best'. This will
% reliably make the width large enough to contain `wide' objects like
% tabulars or included graphics, but might not give optimal results
% for justified text.
% vboxes occurring directly in the parbox are ignored.
% Note further that hboxes with fixed width (made by \hbox to...)
% which occur directly in the vbox may disturb the procedure, because
% the fixed width cannot be recovered. These hboxes will be
% reformatted with the width of the vbox, generating an extremely
% large badness, unsettling the calculation of maximum badness. To
% avoid this such hboxes should be either contained in a vbox or set
% in horizontal mode with appropriate glue at the end.
\newcommand{\naturalparbox}[1][\linewidth]{\def\maxwidth@NPB{#1}\@naturalparbox}

\newcommand{\@naturalparbox}[2][\textheight]
{%
% Calculate `best' width of a parbox. The current algorithm will set the textual contents into parboxes of increasing
% width, starting from 0pt and ending with the maximum width given, in \optwidthsteps steps. The `badness' of every
% parbox is measured. If it is below the threshold defined by \optwidthlinetolerance, the process is stopped and the
% found width accepted. If this doesn't happen, the width of the parbox with the least badness is returned.
\setcounter{probe@NPB}{0}% Initialize `probe counter' for box width.
\let\best@cnt@NPB=\empty% Initialize number of best `probe' so far.
\def\bestbadness@NPB{1000000}% Initialize badness of best `probe'.
\setboolean{carryon@NPB}{true}% Flag for breaking out of loop.
\setlength{\maxheight@NPB}{#1}% Store maximal box height.
\whiledo
{\value{probe@NPB}<\optwidthsteps\and\boolean{carryon@NPB}}% Probes done or break of loop?
{%
\stepcounter{probe@NPB}% Start next probe.
\setbox\@tempboxa=\vbox% The trick with vbox/lastbox is to get the vbox
{% produced by \parbox `immediately' into a box register.
\parbox[b]{(\maxwidth@NPB)/\optwidthsteps*\value{probe@NPB}}% Make the next parbox.
{\hfuzz\maxdimen\hbadness\@M\relax#2}%
\global\setbox\tempbox@NPB=\lastbox% ... and assign \tempbox@NPB to it.
}%
\setlength{\tempdima@NPB}{\ht\tempbox@NPB+\dp\tempbox@NPB}% Measure total height.
\ifthenelse{\lengthtest{\tempdima@NPB>\maxheight@NPB}}% If it exceeds the maximum height given, the box isn't
{}% acceptable anyway.
{%
\calcmaxbadness@NPB{\maxbadness@NPB}{\tempbox@NPB}% Calculate `worst badness' of any hbox appearing in parbox.
\ifthenelse{\not\maxbadness@NPB>\optwidthlinetolerance}% Below Threshold?
{% Yes. Accept this width.
\edef\best@cnt@NPB{\theprobe@NPB}% Store this probe number.
\setboolean{carryon@NPB}{false}% Break loop.
}
{% No. Carry on.
\ifthenelse{\maxbadness@NPB<\bestbadness@NPB}% Below lowest badness found so far?
{% Yes. Store probe number.
\edef\bestbadness@NPB{\number\maxbadness@NPB}% Store badness value.
\edef\best@cnt@NPB{\theprobe@NPB}% Store probe number.
}
{}% No. Try next probe.
}% matches second argument of \ifthenelse{\not\maxbadness@NPB>\optwidthlinetolerance}%
}% matches second argument of \ifthenelse{\lengthtest{\tempdima@NPB>\maxheight@NPB}}%
}% matches \whiledo{\value{probe@NPB}<\optwidthsteps\and\boolean{carryon@NPB}}{%
\ifx\best@cnt@NPB\empty% Was _any_ badness below the initialization value found?
\setlength{\optwidth@NPB}{\maxwidth@NPB}% No; return max width.
\else
\setlength{\optwidth@NPB}{(\maxwidth@NPB)/\optwidthsteps*\best@cnt@NPB}% Yes; return width of best probe.
\fi
\parbox{\optwidth@NPB}{#2}%
}

% Calculate maximal badness of any hbox occurring in a vbox.
\newcommand{\calcmaxbadness@NPB}[2]
{%
\let\@resultcnt@NPB=#1% Here we store the result.
\global\@resultcnt@NPB=\z@\relax% Just in case no hbox occurs...
\setlength{\@tempdima}{\wd#2}% This is the width to which every hbox is stretched for finding its badness.
\setbox\@tempboxa=\vbox% A dummy vbox for recursively analysing the vbox contents using \lastbox
{%
\hfuzz\maxdimen\hbadness\@M
\unvbox#2% `free' the contents of the vbox.
\measureboxes@NPB% Analyse `tail to head' using \lastbox.
}%
}


% Recursively analyse vertical list using \lastbox, to find maximum badness of any contained hbox.
\newcommand{\measureboxes@NPB}%
{%
\unskip\unpenalty\unkern% This is a kluge for TeX, because there is no certain way of finding out whether there's a
\unskip\unpenalty\unkern% penalty, glue or kern on the vertical list. \lastpenalty will give its value, but a
\unskip\unpenalty\unkern% value of 0 might mean there was none or there was one of value 0.
\unskip\unpenalty\unkern% This is different in eTeX. I might make a switch to a smarter solution.
\unskip\unpenalty\unkern
\unskip\unpenalty\unkern
\unskip\unpenalty\unkern
\unskip\unpenalty\unkern
\unskip\unpenalty\unkern
\unskip\unpenalty\unkern
\setbox\@tempboxa=\lastbox% Grab last box.
\ifhbox\@tempboxa% Was this an hbox?
\setbox0=\hb@xt@\@tempdima{\unhbox\@tempboxa}% Yes. Reformat with given width.
\ifnum\badness>\@resultcnt@NPB% Badness larger than largest recorded badness?
\global\@resultcnt@NPB=\badness% Yes. Memorize.
\fi
\expandafter\measureboxes@NPB% Recursive call.
\else
\ifvbox\@tempboxa% Was this a vbox?
\expandafter\expandafter\expandafter\measureboxes@NPB% Ignore, but execute recursive call.
\fi
\fi
}
----------------------------------------------------------------------

into a file naturalparbox.sty, you can test the effect with a file
test.tex like this:

----------------------------------------------------------------------
\documentclass{article}

\usepackage{naturalparbox}

\begin{document}

\fbox
{%
\naturalparbox
{%


\begin{verse}
haha {\tiny said\\
the clown\\}
hoho

\end{verse}%
}%
}%
\qquad\qquad
\fbox
{%
\naturalparbox
{%


\begin{verse}
hahahahahahahaha {\tiny said\\
the clown\\}
hohohahahahahahahah
\end{verse}

}%
}%

\fbox
{%
\parbox{.3\linewidth}
{%


\begin{verse}
haha {\tiny said\\
the clown\\}
hoho

\end{verse}%
}%
}%
\qquad\qquad
\fbox
{%
\parbox{.5\linewidth}
{%


\begin{verse}
hahahahahahahaha {\tiny said\\
the clown\\}
hohohahahahahahahah
\end{verse}

}%
}%
\end{document}
----------------------------------------------------------------------

I know the code is rather crude (especially the strange mixture
between TeX and LaTeX code), but I'm planning to tidy it up after the
first alpha release of TeXPower.

I'd be happy about any bug reports or suggestions of course.

regards
Stephan

--
Stephan Lehmke Stephan...@cs.uni-dortmund.de
Fachbereich Informatik, LS I Tel. +49 231 755 6434
Universitaet Dortmund FAX 6555
D-44221 Dortmund, Germany

pi...@cs.uu.nl

unread,
Nov 16, 2001, 10:41:24 AM11/16/01
to
>>>>> Carel Fellinger <cfel...@iae.nl> (CF) writes:

CF> I'm looking for a way to put a series of lines with all line breaks
CF> forced in a box. The width of that box then has to be the max of the
CF> natural widths of all lines in that box.

CF> But by now I guess there is no easy way to achieve this:(

This code was produced by Victor Eijkhout a looooong time ago. It may not
work if you put complicated things in the box (whatsits etc).
Use it in a .sty file or put it between \makeatletter and \makeatother

\def\snugbox{\hbox\bgroup\setbox\z@\vbox\bgroup
\leftskip\z@\expandafter\let\expandafter\\\csname @normalcr\endcsname
\bgroup\aftergroup\make@snug\noindent
\let\next=}
\def\make@snug{\par\sn@gify\egroup \box\z@\egroup}
\def\sn@gify
{\skip\z@=\lastskip \unskip
\advance\skip\z@\lastskip \unskip
\unpenalty
\setbox\z@\lastbox
\ifvoid\z@ \nointerlineskip \else {\sn@gify} \fi
\hbox{\unhbox\z@}\nointerlineskip
\vskip\skip\z@
}

And then
\snugbox{line1\\line2\\...}
--
Piet van Oostrum <pi...@cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: P.van....@hccnet.nl

0 new messages