Align numbers to words of a sentence in the next line

alignment

I am typesetting a mnemonic for remembering values of pi. For this I want the number of characters in the word to appear on the next line aligned with where word starts. I have tried both tabular and align but both of them do not preserve the spacing in the sentence structure as shown in MWE. The tabular gives sightly better results. Is there a way to typeset this so that sentence appears as in regular text and the numbers get alinged with them in the next line?

enter image description here

What is required:

enter image description here

MWE

\documentclass{article}

\usepackage{amsmath}


\begin{document}

\begin{align*}
\text{May} & \text{I} & \text{have} & \text{a} & \text{large} & \text{container} & \text{of} & \text{coffee?} \\
3   & 1 & 4    & 1 & 5     & 9         & 2  & 6
\end{align*}

\begin{tabular}{llllllll}
May & I & have & a & large & container & of & coffee? \\
3   & 1 & 4    & 1 & 5     & 9         & 2  & 6\\
\end{tabular}


\end{document}

Best Answer

You only need the package dvgloss and use \gl{May I have}{3 1 4}. A not so minimal example:

Mwe

\documentclass{article}
\usepackage[margin=7cm]{geometry}
\usepackage{dvgloss,xcolor}
\setlength\parindent{0pt}
\def\everygla{\sffamily\Large\color{cyan!40!blue}}
\def\everyglb{\sffamily\hfil\footnotesize}
\begin{document}
\gl{May  I  have a  large  * container * of coffee? 
Maybe  one  round  recepter * traslucid * fuschia available now}
{3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3}
\end{document}
Related Question