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}%
    {first.middle.l@gmail.com}%
    {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}} \\ first.middle.l@gmail.com}%
    {\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}} \\ first.middle.l@gmail.com}%
    {\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.

  • 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 01 '18 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 01 '18 at 18:18
  • Thanks, that's what I originally had. Updated with similar result. I'll start adding the extra context right now. – Jorge Israel Peña May 01 '18 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! – Jorge Israel Peña May 01 '18 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 01 '18 at 19:13
  • Fair enough, no worries! I'm still pretty new to latex so I wasn't sure if it was necessary for this or not. I'll remove fontspec and the font and other things I think may be unnecessary. – Jorge Israel Peña May 01 '18 at 19:15
  • @Skillmon I've updated each example to remove what I believe to be unnecessary, as well as updated the resulting images. Please let me know if there's anything else, thanks! – Jorge Israel Peña May 01 '18 at 19:19
  • Do I understand correctly, that this is should be at the top of every page (you mentioned fancyhdr)? If so, fancyhdr or something similar might ease the process a lot. If not, don't use fancyhdr. – Skillmon May 01 '18 at 19:29
  • I managed to remove more! Hope that helps. I do only want this on the first page. – Jorge Israel Peña May 01 '18 at 19:30

1 Answers1

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\\first.middle.l@gmail.com}%
    {(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.

  • I should finally take a look at your stackengine. – Skillmon May 01 '18 at 19:37
  • @Skillmon I second that emotion! – Steven B. Segletes May 01 '18 at 19:41
  • Just started reading the documentation. – Skillmon May 01 '18 at 19:41
  • Thanks for responding! I'm sorry but I'm having trouble understanding the difference, or seeing it, besides the phone number having no spacing in the second example. Would you be kind enough to explain? – Jorge Israel Peña May 01 '18 at 19:44
  • 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! – Jorge Israel Peña May 01 '18 at 19:48
  • I was noticing that for me it wasn't aligning, so I was trying to figure out why, and I just realized it's because one of the letters in the middle is an Ñ (my name, as it is on this site), so it ends up aligning with the tilde instead of the top of the N. Sorry I didn't include that in the MWE, I hadn't anticipated it! Do you think there's any way to have it align with the top of the N rather than the top of the ~ itself? If not, I understand and will mark this as the answer either way, but I'd kindly appreciate any pointers! – Jorge Israel Peña May 01 '18 at 20:01
  • 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 01 '18 at 20:07
  • 1
    @Skillmon that works beautifully! I really appreciate it, thank you! – Jorge Israel Peña May 01 '18 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 01 '18 at 20:13
  • @Skillmon Thanks for picking up my slack, in my absence. – Steven B. Segletes May 02 '18 at 00:01
  • Thank you again @StevenB.Segletes . Curious if you have any ideas on how to top-align this row. Question posted here: https://tex.stackexchange.com/questions/672704/top-align-stackengine-stacks – Jorge Israel Peña Jan 23 '23 at 20:22