summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/generic/FAQ-en/html/FAQ-varwidth.html
blob: c77dbcf70c17771f4112472436a5733af1dbb7c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<head>
<title>UK TeX FAQ -- question label varwidth</title>
</head><body>
<h3>Automatic sizing of <code>minipage</code></h3>
<p/>The <code>minipage</code> environment requires you to specify the
width of the &#8220;page&#8221; you&#8217;re going to create.  This is sometimes
inconvenient: you would like to occupy less space, if possible, but
<code>minipage</code> sets a box that is exactly the width you
specified.
<p/>The <i>pbox</i> package defines a <code>\</code><code>pbox</code> whose width is exactly
that of the longest enclosed line, subject to a maximum width that you
give it.  So while <code>\</code><code>parbox{2cm}{Hello\\world!}</code> produces a
box of width exactly <code>2cm</code>,
<code>\</code><code>pbox{2cm}{Hello\\world!}</code> produces one whose width is
<code>1.79cm</code> (if one&#8217;s using the default <i>cmr</i> font for the
text, at least).  The package also provides a
<code>\</code><code>settominwidth[</code><em>min</em><code>]{</code><em>length</em><code>}{</code><em>text</em><code>}</code> (which looks (almost)
like the standard <code>\</code><code>settowidth</code> command), and a <code>\</code><code>widthofpbox</code>
function analogous to the <code>\</code><code>widthof</code> command for use with the
<i>calc</i> package.
<p/>The <i>eqparbox</i> package extends <i>pbox</i>&#8217;s idea, by
allowing you to set a series of boxes, all with the same (minimised)
width.  (Note that it doesn&#8217;t accept a limiting maximum width
parameter.)  The package documentation shows the following example
drawn from a joke <em>curriculum vitae</em>:
<blockquote>

<pre>
\noindent%
\eqparbox{place}{\textbf{Widgets, Inc.}} \hfill
\eqparbox{title}{\textbf{Senior Widget Designer}} \hfill
\eqparbox{dates}{\textbf{1/95--present}}

...

\noindent%
\eqparbox{place}{\textbf{Thingamabobs, Ltd.}} \hfill
\eqparbox{title}{\textbf{Lead Engineer}} \hfill
\eqparbox{dates}{\textbf{9/92--12/94}}
</pre>
</blockquote><p>
The code makes the three items on each of the heading lines have
exactly the same width, so that the lines as a whole produce a regular
pattern down the page.  A command <code>\</code><code>eqboxwidth</code> allows you to use
the measured width of a group: the documentation shows how the command
may be used to produce sensible-looking columns that mix <code>c</code>-,
<code>r</code>- or <code>l</code>-rows, with the equivalent of a <code>p{...}</code>
entry, by making the fixed-width rows an <i>eqparbox</i> group, and
making the last from a <code>\</code><code>parbox</code> using the width that&#8217;s been
measured for the group.
<p/>The <i>varwidth</i> package defines a <code>varwidth</code>
environment which sets the content of the box to match a &#8220;narrower
natural width&#8221; if it finds one.  (You give it the same parameters as
you would give <code>minipage</code>: in effect, it is a &#8216;drop-in&#8217;
replacement.)  <i>Varwidth</i> provides its own ragged text command:
<code>\</code><code>narrowragged</code>, which aims to make narrower lines and to put more
text in the last line of the paragraph (thus producing lines with more
nearly equal lengths than typically happens with <code>\</code><code>raggedright</code>
itself).
<p/>The documentation (in the package file) lists various restrictions and
things still to be done, but the package is already proving useful for
a variety of jobs.
<dl>
<dt><tt><i>eqparbox.sty</i></tt><dd><a href="http://www.tex.ac.uk/tex-archive/macros/latex/contrib/eqparbox.zip">macros/latex/contrib/eqparbox</a> (or <a href="http://www.tex.ac.uk/tex-archive/macros/latex/contrib/eqparbox/">browse the directory</a>)
<dt><tt><i>pbox.sty</i></tt><dd><a href="http://www.tex.ac.uk/tex-archive/macros/latex/contrib/pbox.zip">macros/latex/contrib/pbox</a> (or <a href="http://www.tex.ac.uk/tex-archive/macros/latex/contrib/pbox/">browse the directory</a>)
<dt><tt><i>varwidth.sty</i></tt><dd><a href="http://www.tex.ac.uk/tex-archive/macros/latex/contrib/misc/varwidth.sty">macros/latex/contrib/misc/varwidth.sty</a>
</dl>
<p/>
<p/><p/><p/><p>This question on the Web: <a href="http://www.tex.ac.uk/cgi-bin/texfaq2html?label=varwidth">http://www.tex.ac.uk/cgi-bin/texfaq2html?label=varwidth</a>
</body>