[Tex/LaTex] A command like `\hspace` calculating the distance from the beginning of the line

horizontal alignmentspacing

I would like to place several blocks of text in one line, but fixing their positions by distances from the beginning of the line. For example

(1.2pt from beginning) cat (2.1pt from beginning) dog (2.9pt from beginning) bird

\hspace does not work, since it fixes the distances from the end of the last word. Is there a command which fixes this distance from the beginning of the line? If the words are too long or too close to each other, they should overlap.

Best Answer

The tabto package does what you want. If a \tabto requires a leftward tab, it will issue a linefeed, unless you use the \tabto* invocation. Below, I show successive \tabto's with and without the * variant.

Note that a blank line appears between the two versions in the output because the \tabto{1.2pt}cat is a leftward tab relative to the \parindent value (so a linefeed was inserted). If I had added a \noindent prior to the invocation, no blank line would have appeared.

\documentclass{article}
\usepackage{tabto}
\begin{document}
\tabto*{1.2pt}cat
\tabto*{2.1pt}dog
\tabto*{2.9pt}bird

\tabto{1.2pt}cat
\tabto{2.1pt}dog
\tabto{2.9pt}bird
\end{document}

enter image description here

Related Question