Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I know we can get the maximum width or height of several boxes via:

The maximum width is \the\wd0

The maximum height is \the\ht0

But how to get the minimum width or height?

share|improve this question
add comment

3 Answers 3

up vote 5 down vote accepted

The idea is simple: set the boxes and measure them.










enter image description here

share|improve this answer
add comment

Here is at least one straight-forward way without abstraction into a macro:


% what needs to happen in order to find the minimum width inner hbox in:
% \hbox{\hbox{first}\hbox{second}\hbox{third}}

\leavevmode % otherwise hboxes stack
\ifdim\wd0<\minwd \minwd=\wd0 \fi
\ifdim\wd0<\minwd \minwd=\wd0 \fi

minwd = \the\minwd


In another answer I have a made a macro for a similar thing.

share|improve this answer
add comment

If you need an expandable solution, and the boxes are already there (thus avoiding the non-expandable step of putting some material into boxes), and use a tex engine with e-TeX extensions enabled:

minimum width of boxes

% compile with etex (or pdftex, etc...) as this requires e-TeX extensions
\input xint.sty

\def\minimalwidthofboxes #1{%
    \dimexpr\xintiMinof {\xintApply{\number\wd\firstofone}{#1}}sp\relax }

\long\def\firstofone #1{#1}% \long in case \firstofone already exists and was
                           % declared long

% why \firstofone? because \xintApply\macro{{item1}..{item2}} does
% \macro{item1}, hence here this would give \number\wd{\bA} which is illicit, we
% want \number\wd\bA without braces (besides, on the other hand, it doesn't
% matter if the list contains the single token \bA or the braced token {\bA})






\the\minimalwidthofboxes {\bA\bB\bC}\ % or equivalently {{\bA}{\bB}{\bC}}
is the minimal width among \the\wd\bA, \the\wd\bB, \the\wd\bC.

\newbox\bD \setbox\bD\hbox{bb}

\the\minimalwidthofboxes {{\bA}{\bB}{\bC}{\bD}}
is the minimal width among \the\wd\bA, \the\wd\bB, \the\wd\bC\ and \the\wd\bD.

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.