[Tex/LaTex] How to make text aligned left/center/right in the same line

horizontal alignment

I am trying to align some text to left/center/right in the same line. For example, I want to put my phone number on the left, my name in the center, and my email on the right, how do I do that?

Best Answer

Using \hfill won't necessarily result in the middle text being centered, as the example below demonstrates. If you want to place the text in such a way that the middle text is really centered, I would suggest using \parboxes, as the example shows (I used the \lipsum[2] command to generate text to be used only as a reference):

\documentclass{article}
\usepackage{lipsum}

\newcommand\textbox[1]{%
  \parbox{.333\textwidth}{#1}%
}

\begin{document}

\noindent Left longer sample simple text\hfill Center?\hfill Right

\noindent\textbox{Left longer sample text\hfill}\textbox{\hfil Center\hfil}\textbox{\hfill Right}

\noindent\lipsum[2]

\end{document}

enter image description here

If this construct will be used many times, it would be better to have a command; something along the lines of the \textline command whose definition and use are illustrated in the following example (in which I also incorporated egreg's suggestion about \raggedleft, \centering and \raggedright):

\documentclass{article}
\usepackage{lipsum}

\newcommand\textline[4][t]{%
  \par\smallskip\noindent\parbox[#1]{.333\textwidth}{\raggedright\texttt{+}#2}%
  \parbox[#1]{.333\textwidth}{\centering#3}%
  \parbox[#1]{.333\textwidth}{\raggedleft\texttt{#4}}\par\smallskip%
}

\begin{document}

\lipsum[2]
\textline[t]{555\,555\,555}{Some Name}{user@some.site.com}
\lipsum[2]

\end{document}

enter image description here