# How to make text aligned left/center/right in the same line?

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?

-

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}


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}


-
This is very clear. Thank you so much. –  LWZ May 12 '12 at 4:07
I'd use \raggedright in the left box, \centering in the middle box and \raggedleft in the right box. –  egreg May 12 '12 at 9:51

The task is accomplished easily with boxes:

\noindent
\makebox[0pt][l]{+999\,555\,999\,555}%
\makebox[\textwidth][c]{Ben Lee User}%
\makebox[0pt][r]{\texttt{ben.l.user@some.site}}


This doesn't check for overlaps, but the chance to getting overlaps is very small.

One macro for it might be

\newcommand{\headerline}[3]{%
\par\medskip\noindent
\makebox[0pt][l]{#1}%
\makebox[\textwidth][c]{#2}%
\makebox[0pt][r]{\texttt{#3}}\par\medskip}


to be used as

\headerline{+999\,555\,999\,555}{Ben Lee User}{ben.l.user@some.site}


## A more efficient (and more obscure) solution

\newcommand{\headerline}[3]{%
\par\medskip\noindent
\makebox[\textwidth][s]{\rlap{#1}\hfill#2\hfill\llap{\texttt{#3}}}%
\par\medskip}

-
+1, but wouldn't \rlap and \llap be easier than the outer \makebox's? –  Martin Scharrer May 12 '12 at 10:02
@MartinScharrer LaTeX syntax versus Plain. :) –  egreg May 12 '12 at 10:06
Are \rlap and \llap considered plain syntax? I didn't know that. –  Martin Scharrer May 12 '12 at 10:07
@MartinScharrer They are slightly dangerous because they don't start horizontal mode. –  egreg May 12 '12 at 10:11
Ah, good point. Thanks. –  Martin Scharrer May 12 '12 at 10:34
Left \hfill Center \hfill Right

@texasAUtiger \noindent will probably be necessary and you have to be careful with spurious blank spaces. –  Gonzalo Medina May 12 '12 at 3:48