2

I am trying to write something like \underset{\mathbb{P}}{foo} where the beginning of foo would be horizontally aligned with the P of \mathbb{P}, even if 'foo' can be wide (let's say, something like A \leftarrow \{0,1\} \cup \{5,6\}). In other words : I am trying to have a leftalign option for underset.

Moreover, I would be happy if this tip can be compatible with the \oset and \uset macro defined in Change vertical space in overset, that allows to control the vertical space.

The only solution I actually found is to manually add horizontal spaces, but the amount of space I need to add is dependent on the content in the underset command, so it takes a lot of time when I need to use a lot of them.

2 Answers2

1

I can propose this \lunderset that takes as optional argument the separation between the main object and the subscript (default 1pt).

\documentclass{article}
\usepackage{amsmath,amssymb}

\makeatletter \DeclareRobustCommand{\lunderset}[3][1pt]{% \binrel@{#3}% \binrel@@{% \vbox{% \offinterlineskip\m@th \ialign{##\hfil\cr$\displaystyle#3$\cr\noalign{\vskip#1}$\scriptstyle#2$\cr}% }% }% } \makeatother

\begin{document}

[ \lunderset{\mathbb{P}}{A\gets{0,1}\cup{5,6}} ]

[ \lunderset[0pt]{\mathbb{P}}{A\gets{0,1}\cup{5,6}} ]

[ \lunderset{\mathbb{P}}{f\gets{0,1}\cup{5,6}} ]

\end{document}

enter image description here

If you plan to use this also inline, using \displaystyle is not the best, but this requires some more work.

\documentclass{article}
\usepackage{amsmath,amssymb}

\makeatletter \DeclareRobustCommand{\lunderset}[3][1pt]{% \binrel@{#3}% \binrel@@{\mathpalette\lunderset@{{#1}{#2}{#3}}}% } \newcommand{\lunderset@}[2]{\lunderset@@#1#2} \newcommand{\lunderset@@}[4]{% \vbox{% \offinterlineskip\m@th \ialign{##\hfil\cr$#1#4$\cr\noalign{\vskip#2}$\lunderset@size{#1}#3$\cr}% }% } \newcommand{\lunderset@size}[1]{% \ifx#1\displaystyle\scriptstyle\else \ifx#1\textstyle\scriptstyle\else \scriptscriptstyle\fi\fi } \makeatother

\begin{document}

[ \lunderset{\mathbb{P}}{A\gets{0,1}\cup{5,6}} ]

[ \lunderset[0pt]{\mathbb{P}}{A\gets{0,1}\cup{5,6}} ]

[ \lunderset{\mathbb{P}}{f\gets{0,1}\cup{5,6}} ]

\end{document}

egreg
  • 1,121,712
0

Here is a macro \lunderset (left underset) that uses \mathrlap from the mathtools package together with a phantom of the main content.

enter image description here

\documentclass{article}

\usepackage{amssymb, mathtools}

\newcommand{\lunderset}[2]{\underset{\mathrlap{#1}}{\mathrlap{#2}}\phantom{#2}}

\begin{document}

Some text $\lunderset{\mathbb{P}}{A \leftarrow {0,1} \cup {5,6}}$ more text

\end{document}

This is compatible with Mico's linked solution for \uset, except in your usage the main content shouldn't be contained in \mathrel. So use the following:

\makeatletter
\newcommand{\uset}[3][0ex]{%
  {\mathop{#3}\limits_{
    \vbox to#1{\kern-7\ex@
    \hbox{$\scriptstyle#2$}\vss}}}}
\makeatother

enter image description here

Sandy G
  • 42,558
  • Thanks! I like the simplicity of it! I read this article, quoted by the mathtools documentation, pdf about alignement macros, and I think it helped me to understand the general idea! If you have nice references like this one to understand more the alignements in latex, I would be very happy. – mahaaaham Jan 15 '23 at 17:54