[Tex/LaTex] Simple way to align text within tabbing environment

horizontal alignmenttabbingtables

I want to align text within a tabbing environment without using a new environment. That means flushleft and flushright are not options. Ideally smething like this would be nice:

\begin{tabbing}
\textalign[left]{Hello} \= \textalign[center]{There} \= \textalign[right]{World}
\end{tabbing}

How do I do this though?

Best Answer

You can do something like this:

\documentclass{article} 

\newcommand\textalign[2][]{%
\ifx#1l\relax
  \makebox[0pt][l]{#2}%
\else
  \ifx#1r\relax
    \makebox[0pt][r]{#2}%
  \else  
    \ifx#1c\relax
      \makebox[0pt][c]{#2}%
    \fi\fi\fi
}

\begin{document}

\noindent
\hrulefill

\begin{tabbing}
\=\hspace*{.5\linewidth}\=\hspace{.5\linewidth}\=\kill \\
\> \textalign[l]{Hello} \> \textalign[c]{There} \> \textalign[r]{World} \\
\> \textalign[l]{Longer text} \> \textalign[c]{Another longer text} \> \textalign[r]{Some other text}
\end{tabbing}

\end{document}

enter image description here

but I don't see much use in this. Some other approaches (e.g., boxes or tabular or longtable) without the tabbing would do the same.