여러 상자의 최소 너비나 높이를 측정하는 방법은 무엇입니까?

여러 상자의 최소 너비나 높이를 측정하는 방법은 무엇입니까?

다음을 통해 여러 상자의 최대 너비 또는 높이를 얻을 수 있다는 것을 알고 있습니다.

\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

다음은 매크로로 추상화하지 않고 최소한 하나의 간단한 방법입니다.

\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

관련 정보