Center line based on only part of text

I'm working off of a resume template I found. This is what it looks like

I want to center the bottom line of text differently. Right now, it is centered based on the whole line of text, but I would like the email address to line up centered under the name and address.

Here's an example that generates the document.

\documentclass[11pt,letterpaper]{article}
\usepackage{fullpage}
\usepackage{amsmath}
\usepackage{amssymb}
\pagestyle{empty}
\raggedright

\newcommand{\lineunder}{\vspace*{-8pt} \\ \hspace*{-18pt} \hrulefill \\}
\newcommand{\contact}[3]{
\vspace*{-8pt}
\begin{center}
{\LARGE \scshape {#1}}\\
#2 \lineunder
#3
\end{center}
\vspace*{-8pt}
}

\begin{document}

\contact{First M. Last}
}
\end{document}

-
Is it one purpose that the \lineunder rule hangs into the left margin but not into the right one? –  Qrrbrbirlbel Oct 3 '12 at 0:51
@Qrrbrbirlbel probably not. I'm working starting from someone else's template. I didn't even notice. Actually, looking now I don't see a difference in the resulting pdf between the left and right margin. –  Joe Oct 3 '12 at 1:09
Put \usepackage[showframe,pass]{geometry} in your preamble and you can see it for yourself. \hspace*{-18pt} puts the line 18pt into the left margin. Repeat it after \hrulefill to get the same effect on the right side. –  Qrrbrbirlbel Oct 3 '12 at 1:17
@Qrrbrbirlbel I see it now. In the full template, it is actually intended because \lineunder is also used as part of section headers that hang into the margin. I just didn't realize it because I thought it was working the other way, i.e. the rest of the text was indented. –  Joe Oct 3 '12 at 1:33

You can use boxes. A variant using \parboxes in which each one having a width equal to one third of \textwidth:

\documentclass[11pt,letterpaper]{article}
\usepackage{fullpage}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{url}
\pagestyle{empty}
\raggedright

\newcommand{\lineunder}{\vspace*{-8pt}\par\hspace*{-18pt}\hrulefill\par}
\newcommand{\contact}[3]{%
\vspace*{-8pt}
\begin{center}
{\LARGE\scshape #1}\\
#2 \lineunder
#3
\end{center}
\vspace*{-8pt}
}

\begin{document}

\contact{First M. Last}{Address, City, State Zip}
{\parbox[t]{.3333\textwidth}{(123) 456-7890\hfill}%
\parbox[t]{.3333\textwidth}{\hfil\texttt{email@mail.edu}\hfil}%
}
\end{document}


It is not clear to me if the hanging indent of the rule is meant to be the way it is now.

Now a variant using a \makebox and \llap, \rlap centering the email and keeping the \qquad separation:

\documentclass[11pt,letterpaper]{article}
\usepackage{fullpage}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{url}

\pagestyle{empty}
\raggedright

\newcommand{\lineunder}{\vspace*{-8pt}\par\hspace*{-18pt}\hrulefill\par}
\newcommand{\contact}[5]{%
\vspace*{-8pt}
\begin{center}
{\LARGE\scshape #1}\\
#2 \lineunder
\makebox[\textwidth][c]{%
\end{center}
\vspace*{-8pt}
}

\begin{document}

\end{document}


-
This works great on the example text I gave. Unfortunately, my actual web address is a little longer, and doesn't quite fit in .333\textwidth –  Joe Oct 3 '12 at 0:54
I swapped the web address into the center parbox, and adjusted the widths of the center and right to .444 and .222 respectively, and that seems to work. –  Joe Oct 3 '12 at 0:57
@Joe of course, you can adjust the widths according to your needs; too hard to guess from you example that the widths needed to be different. –  Gonzalo Medina Oct 3 '12 at 1:00
what do you mean by hanging indent? –  Joe Oct 3 '12 at 1:10
I didn't realize at first that the adjustment of the widths was going to be trivial, which is why there are two comments. –  Joe Oct 3 '12 at 1:11

A variant that centers the email address under the postal address and keeps \qquad as separation to the phone number and the home page.

\documentclass[11pt,letterpaper]{article}
\usepackage{fullpage}
\usepackage{amsmath}
\usepackage{amssymb}
\pagestyle{empty}
\raggedright

\newcommand{\lineunder}{\vspace*{-8pt} \\ \hspace*{-18pt} \hrulefill \\}
\newcommand{\contact}[5]{
\vspace*{-8pt}
\begin{center}
{\LARGE \scshape {#1}}\\
#2 \lineunder
\sbox0{#4}%
\centerline{%
\usebox0 %
}%
\end{center}
\vspace*{-8pt}
}

\begin{document}

\contact{First M. Last}
{(123) 456-7890}
{email@mail.edu}
\end{document}


Rewritten as "pure LaTeX":

\documentclass[11pt,letterpaper]{article}
\usepackage{fullpage}
\usepackage{amsmath}
\usepackage{amssymb}
\pagestyle{empty}
\raggedright

\newlength{\emailwidth}
\newlength{\partialwidth}

\newcommand{\lineunder}{\vspace*{-8pt} \\ \hspace*{-18pt} \hrulefill \\}
\newcommand{\contact}[5]{
\vspace*{-8pt}
\begin{center}
{\LARGE \scshape {#1}}\\
#2 \lineunder
\settowidth{\emailwidth}{#4}%
\setlength{\partialwidth}{\linewidth}%
\setlength{\partialwidth}{.5\partialwidth}%
\parbox{\linewidth}{%
\mbox{%
#4%
}%
}%
\end{center}
\vspace*{-8pt}
}

\begin{document}

\contact{First M. Last}
{(123) 456-7890}
{email@mail.edu}
\end{document}


The next variant is probably much easier to understand:

\documentclass[11pt,letterpaper]{article}
\usepackage{fullpage}
\usepackage{amsmath}
\usepackage{amssymb}
\pagestyle{empty}
\raggedright

\newcommand{\lineunder}{\vspace*{-8pt} \\ \hspace*{-18pt} \hrulefill \\}
\newcommand{\contact}[5]{
\vspace*{-8pt}
\begin{center}
{\LARGE \scshape {#1}}\\
#2 \lineunder
\end{center}
\vspace*{-8pt}
}

\begin{document}

\contact{First M. Last}
{(123) 456-7890}
{email@mail.edu}
\end{document}


However, the disadvantage of this solution is, that TeX does not warn, if the phone number or the home page is too long to properly fit in the line. Therefore the first solutions are a little more complicate, because they additionally define the space that is allowed for the phone number and the home page.

-
I don't fully follow why the modified code works. In particular \sbox and pretty much everything in \centerline{...} –  Joe Oct 3 '12 at 1:03

Here is an alternative, where the command \contact takes 5 arguments

\documentclass[11pt,letterpaper]{article}
\usepackage{fullpage}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{url}
\usepackage{calc}
\pagestyle{empty}
\raggedright

\newcommand{\lineunder}{\vspace*{-8pt}\par\hspace*{-18pt}\hrulefill\par}
\newcommand{\contact}[5]{%
\vspace*{-8pt}
\begin{center}
{\LARGE\scshape #1}\\
#2 \lineunder
\end{center}
\vspace*{-8pt}
}

\begin{document}

\contact{First M. Last}