How can I give a box a minimal width, in math mode? That is, I would like a command something like \minwidth{exp}{width}
, which will always typeset exp
, but additionally, if the natural length of exp
is less than width
, will pad it by centering it in a box of width width
.
For instance, $A \minwidth{i}{2em} B$
should come out like $A \makebox[2em][c]{i} B$
; but $A \minwidth{WXYZ}{2em} B$
should come out like $A WXYZ B$
.
The varwidth
package provides this variable-width functionality, but only for a minipage, not for a plain box or similar.
(The use case is for a variant of the inline TikZ arrow commands defined in this answer, padding the arrow label to a minimal width, so that the arrow extends for large labels, but does not get too short when the label are short or absent.)
Edit: This turned out to be a bit of an XY problem: Harish Kumar has excellently answered my real problem, without answering this specific question. What I am now using, adapted from his answer, is:
\newcommand{\myto}[1][]{ \mathrel{
\tikz[baseline={([yshift=-0.55ex]a.south)}]{%
\node[minimum width=1.5em,align=center,inner xsep=0.3ex,inner ysep=0.15ex] (a) {$\scriptstyle #1$};
\draw[->] (a.south west) -- ([xshift=0.6ex]a.south east);}
}\mkern-1mu}
with usage as in $A \myto[f] B$
.
I would still be interested in answers to the specific question asked, though.
Best Answer
Here is a
tikz
only approach. Adjustex
s suitably.The magic word here is
minimum width=2em
option for thenode
. I have also used somexshift
for the arrow head to make it more symmetric. Adjust these values as you need.