
複数のボックスの最大幅または最大高さを次の方法で取得できることはわかっています。
\setbox0=\vbox{\hbox{a}\hbox{b}\hbox{c}}
The maximum width is \the\wd0
\setbox0=\hbox{\hbox{a}\hbox{b}\hbox{c}}
The maximum height is \the\ht0
しかし、最小の幅や高さをどのように取得するのでしょうか?
答え1
アイデアはシンプルです。箱を設置して測定するだけです。
\documentclass{article}
\makeatletter
\newcommand{\settominwidth}[1]{\saltyegg@settomin{\wd}{#1}}
\newcommand{\settominheight}[1]{\saltyegg@settomin{\ht}{#1}}
\newcommand{\settomindepth}[1]{\saltyegg@settomin{\dp}{#1}}
\newcommand{\saltyegg@settomin}[3]{%
#2\maxdimen
\@for\next:=#3\do{%
\sbox\z@{\next}%
\ifdim#1\z@<#2%
#2=#1\z@
\fi}%
}
\makeatother
\newlength{\saltyeggtest}
\begin{document}
\settominwidth{\saltyeggtest}{a,b,c,f}
\the\saltyeggtest
\settominheight{\saltyeggtest}{a,b,c,f}
\the\saltyeggtest
\settomindepth{\saltyeggtest}{a,b,c,f}
\the\saltyeggtest
\end{document}
答え2
マクロに抽象化せずに、少なくとも 1 つの簡単な方法を次に示します。
\newdimen\minwd
% 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
\setbox0\hbox{first}%
\minwd=\wd0
\box0
\setbox0\hbox{second}%
\ifdim\wd0<\minwd \minwd=\wd0 \fi
\box0
\setbox0\hbox{third}%
\ifdim\wd0<\minwd \minwd=\wd0 \fi
\box0
minwd = \the\minwd
\bye
で別の答え同様のことを行うマクロを作成しました。
答え3
拡張可能なソリューションが必要で、ボックスがすでに存在し (そのため、ボックスに何らかの素材を入れるという拡張不可能なステップを回避できる)、e-TeX
拡張機能が有効になっている TEX エンジンを使用する場合は、次の操作を行います。
% 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})
%% EXAMPLES
\newbox\bA
\newbox\bB
\newbox\bC
\setbox\bA\hbox{Aah}
\setbox\bB\hbox{BB}
\setbox\bC\hbox{CCC}
\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.
\bye