1

I found this answer which shows how to have a line with left, center, and right-aligned text. The thing is that I want essentially two lines, or a line break within each component.

This is fine, except that the first line's middle component is in large text which causes weird vertical alignment, so I'd like to know if and how it'd be possible to vertically-align everything to the top so everything is flush at the top, which in this case would mean that the center component descends farther down than the left and right components. I'm mainly curious to learn more about latex but also to see how it would look, maybe the current typesetting looks best (I'm open to opinions).

To be clear, I want something like this, where everything is aligned at the top:

expected

I realized that \makebox doesn't allow line breaks so I did this by creating two \toplines.

\documentclass{article}

\newcommand{\topline}[3]{%
    \noindent%
    \makebox[0pt][l]{#1}%
    \makebox[\textwidth][c]{#2}%
    \makebox[0pt][r]{#3}}

\begin{document}

\topline{123 Main Street}%
    {\LARGE {FIRST MIDDLE LAST}}%
    {\textnormal{(555) 123 -- 4567}}
\topline{Los Angeles, CA}%
    {[email protected]}%
    {somesite.com}

\end{document}

makebox

I found that \parbox has vertical-alignment parameters, and saw the top answer which uses \parbox so I attempted using that, but I am misunderstanding something as I can't get things to vertically align to the top. The result seems similar:

\documentclass{article}

\newcommand{\topline}[3]{%
    \parbox[t]{.333\textwidth}{\raggedright#1}%
    \parbox[t]{.333\textwidth}{\centering#2}%
    \parbox[t]{.333\textwidth}{\raggedleft#3}}

\begin{document}

\topline{123 Main Street \\ Los Angeles, CA}%
    {{\LARGE {FIRST MIDDLE LAST}} \\ [email protected]}%
    {\textnormal{(555) 123 -- 4567} \\ somesite.com}

\end{document}

parbox

I learned about \raisebox which I think allowed me to achieve what I want, but the manner in which I'm using it feels very ad-hoc. For example, I just guessed the unit by which to raise it to be 1ex, and I'm not positive if everything is completely flush. It seems to me like it is. I'd love to know if 1ex really is the perfect/exact unit and if so why, or if it's more the case that anything above some unit would flush at the top and go no further.

If this is the best way to do this, then that's fine with me, but it feels pretty hacky and arbitrary.

\documentclass{article}

\newcommand{\topline}[3]{%
    \noindent%
    \raisebox{1ex}{\parbox[t]{.333\textwidth}{\raggedright#1}}%
    \parbox[t]{.333\textwidth}{\centering#2}%
    \raisebox{1ex}{\parbox[t]{.333\textwidth}{\raggedleft#3}}}

\begin{document}

\topline{123 Main Street \\ Los Angeles, CA}%
    {{\LARGE {FIRST MIDDLE LAST}} \\ [email protected]}%
    {\textnormal{(555) 123 -- 4567} \\ somesite.com}

\end{document}

raisebox

I realize I'm probably doing this completely wrong, so I'd appreciate any help! Maybe I should be using entirely different commands or environments, or maybe this kind of thing just isn't possible.

I'm aware of fancyhdr and I was going to attempt using it, but what I have seemed simple enough to avoid having to bring in an entirely separate package and figuring out how it works and making sure it works well with my existing document, but if it really is the best way, then I'll be happy to look into it.

9
  • Use \parbox[t]{.333\textwidth}{Foobar} instead of \parbox[t][][t] for top alignment. The second [t] only makes sense if you specify a total height with the second optional argument.
    – Skillmon
    May 1, 2018 at 18:18
  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem.
    – Skillmon
    May 1, 2018 at 18:18
  • Thanks, that's what I originally had. Updated with similar result. I'll start adding the extra context right now. May 1, 2018 at 18:27
  • @Skillmon I've edited each one to be compilable, although I use lualatex. Please let me know if anything else is required! May 1, 2018 at 18:39
  • While now they are compilable, you put to much into those. For example: Is fontspec really necessary to show your problem, which is just about alignment of \parboxes and the like, which are part of the LaTeX kernel? You should always provide minimal working examples, which only contain the bare necessities for your code to demonstrate your issue. Sorry if that wasn't clear from my second comment.
    – Skillmon
    May 1, 2018 at 19:13

1 Answer 1

3

If you want the middle centered between the outside items

\documentclass{article}
\usepackage[usestackEOL]{stackengine}
\newcommand{\topline}[3]{%
    \noindent%
    \belowbaseline[0pt]{\Longunderstack[l]{#1}}\hfill%
    \belowbaseline[0pt]{\Longunderstack[c]{#2}}\hfill%
    \belowbaseline[0pt]{\Longunderstack[r]{#3}}}

\begin{document}

\topline{123 Main Street\\Los Angeles, CA}%
    {\LARGE FIRST MIDDLE LAST\\[email protected]}%
    {(555) 123 -- 4567\\somesite.com}

\end{document}

enter image description here

If you want the middle centered left/right between the margins:

\documentclass{article}
\usepackage[usestackEOL]{stackengine}
\newcommand{\topline}[3]{%
    \noindent%
    \belowbaseline[0pt]{\makebox[0pt][l]{\Longunderstack[l]{#1}}}\hfill%
    \belowbaseline[0pt]{\Longunderstack[c]{#2}}\hfill%
    \belowbaseline[0pt]{\makebox[0pt][r]{\Longunderstack[r]{#3}}}}

\begin{document}

\topline{123 Main Street\\Los Angeles, CA}%
    {\LARGE FIRST MIDDLE LAST\\first.middle.l@gmail.com}%
    {(555)123--4567\\somesite.com}

\end{document}

enter image description here

If you anticipate things other than \normalsize in the 2nd lines, then you might need to change the affected \Longunderstack to a \Shortunderstack.

11
  • I should finally take a look at your stackengine.
    – Skillmon
    May 1, 2018 at 19:37
  • 1
    Oh I think I understand now. I believe the difference is that the first centers such that there is an equal spacing on either side in between the left/right parts, while the second one ignores that and does so with respect to the margins. Thank you very much! May 1, 2018 at 19:48
  • 1
    @JorgeIsraelPeña since the N should be as high as the other upper case letters (I assume you're not using a weird font that has a bigger N than e.g. the P), you could do \smash{Ñ} in your name. \smash is saying to the typesetting algorithm that its contents don't have a height.
    – Skillmon
    May 1, 2018 at 20:07
  • 1
    @Skillmon that works beautifully! I really appreciate it, thank you! May 1, 2018 at 20:09
  • 2
    @JorgeIsraelPeña If you use a weird font, you could use \smash{Ñ}\vphantom{N}. \vphantom has the height of its argument, but no width.
    – Skillmon
    May 1, 2018 at 20:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .