答案1
有一种可能性是,使第二个参数符合第一个参数的宽度,显示第一个参数自然短于第二个参数的情况,反之亦然。
垂直显示表明它们实际上是宽度匹配的。我注释掉了其他几种显示样式。
\documentclass{article}
\usepackage{scalerel,graphicx}
\newcommand\matchfirstwidth[2]{\leavevmode%
\setbox8=\hbox{\strut#1}\dp8=0pt%
\setbox4=\hbox{\rotatebox[origin=lb]{90}{\copy8}}%
\setbox8=\hbox{\strut#2}\dp8=0pt%
\setbox2=\hbox{\rotatebox[origin=lb]{90}{\copy8}}%
\setbox6=\hbox{\rotatebox[origin=rb]{-90}{\scalerel*{\copy2}{\copy4}}}%
\setbox8=\hbox{\rotatebox[origin=rb]{-90}{\scalerel{\copy2\,}{\copy4}}}%
%{\fboxsep=0pt\fbox{\copy8}}%
% or
\copy8%
% or
%{\fboxsep=0pt\fbox{\scaleto{\copy8}{2\baselineskip}}}
}
\begin{document}
\matchfirstwidth{foo}{bar}\quad
\matchfirstwidth{bar}{foo}\quad
\matchfirstwidth{foogoo}{bar}\quad
\matchfirstwidth{bar}{foogoo}
\end{document}
并且,正如原帖所说,为了反转两个项目的垂直方向,
\documentclass{article}
\usepackage{scalerel,graphicx}
\newcommand\matchfirstwidth[2]{\leavevmode%
\setbox8=\hbox{\strut#1}\dp8=0pt%
\setbox4=\hbox{\rotatebox[origin=lb]{90}{\copy8}}%
\setbox8=\hbox{\strut#2}\dp8=0pt%
\setbox2=\hbox{\rotatebox[origin=lb]{90}{\copy8}}%
\setbox8=\hbox{\rotatebox[origin=rb]{-90}{\copy4\,\scalerel*{\copy2}{\copy4}}}%
%{\fboxsep=0pt\fbox{\copy8}}%
% or
\copy8%
% or
%{\fboxsep=0pt\fbox{\scaleto{\copy8}{2\baselineskip}}}
}
\begin{document}
\matchfirstwidth{foo}{bar}\quad
\matchfirstwidth{bar}{foo}\quad
\matchfirstwidth{foogoo}{bar}\quad
\matchfirstwidth{bar}{foogoo}
\end{document}