2

I'm attempting to create text for an envelope. The sender is in the top-left corner, and the recipient should be centred vertically and horizontally with respect to the edges of the paper. That is, the presence of the sender should not change the vertical alignment of the recipient.

\documentclass{letter}
\usepackage[papersize={110mm,220mm},landscape,margin=5mm,twoside=false]{geometry}
\setlength\parskip{0pt}
\pagestyle{empty}

\begin{document}

If undeliverable, please return to:

Joe Citizen

12345 Foo St

Bar BAZ 67890

\huge
RECIPIENT LINE 1

RECIPIENT LINE 2

RECIPIENT LINE 3

\end{document}

How can I vertically centre the RECIPIENT lines with respect to the entire page? The block itself should be centred, but text within it should be left justified.

Sparhawk
  • 494
  • 1
  • 6
  • 13
  • 1
    Perhaps this question would give you several options: https://tex.stackexchange.com/questions/169808/what-are-the-ways-to-position-things-absolutely-on-the-page – Steven B. Segletes Aug 31 '17 at 10:39

2 Answers2

4

Use center and \vspace*{\fill}; for the addressee, it's better to use tabular, so to get left alignment in the respective rows. For the return address, use a zero height box.

\documentclass{letter}
\usepackage[
  papersize={110mm,220mm},
  landscape,
  margin=5mm,
  twoside=false
]{geometry}

\setlength\parskip{0pt}
\setlength\parindent{0pt}
\setlength\topskip{0pt}

\pagestyle{empty}

\begin{document}

\parbox[t][0pt]{\textwidth}{
  \vspace{0pt}% to set the reference point
  \raggedright
  If undeliverable, please return to:\\
  Joe Citizen\\
  12345 Foo St\\
  Bar BAZ 67890
}

\vspace*{\fill}

\begin{center}
\huge
\begin{tabular}{@{}l@{}}
Joe Citizen\\
12345 Foo St\\
Bar BAZ 67890
\end{tabular}
\end{center}

\vspace*{\fill}

\end{document}

enter image description here

egreg
  • 1,121,712
  • This mostly works, but \vspace{0pt} creates an additional margin at the top, so all the text is shifted down. – Sparhawk Aug 31 '17 at 11:43
  • @Sparhawk Use \vspace{-\ht\strutbox} – egreg Aug 31 '17 at 19:32
  • This removes the top margin, but the text is still not vertically centred. I measure the gap above the recipient block to be ~9% larger than the gap below. In comparison, the tikz solution is much more precise. – Sparhawk Sep 01 '17 at 02:04
  • @Sparhawk You probably want to set \topskip to zero – egreg Sep 01 '17 at 08:42
  • That also shifts the sender up. It's most evident if I set margin=0mm, then the sender runs off the top of the page. – Sparhawk Sep 04 '17 at 03:07
  • @Sparhawk I don't know what your purpose is: does the set of postal rules you have to comply require centering of the address block? Anyway, I modified the code to show how to use \topskip. – egreg Sep 04 '17 at 08:22
  • Haha, no nothing like that. It started off as an exercise in making a template, then I got… uh… obsessive about alignment. Thanks, that works perfectly now. – Sparhawk Sep 04 '17 at 23:18
3

I would use tikz for that:

\documentclass{letter}
\usepackage[papersize={110mm,220mm},landscape,margin=5mm,twoside=false]{geometry}
\setlength\parskip{0pt}
\pagestyle{empty}

\usepackage{tikz}


\begin{document}

If undeliverable, please return to:

Joe Citizen

12345 Foo St

Bar BAZ 67890
\begin{tikzpicture}[remember picture,overlay]
    \node at (current page.center)
        {\huge\begin{tabular}{@{}l@{}}
            RECIPIENT LINE 1\\
            RECIPIENT LINE 21\\
            RECIPIENT LINE 3
        \end{tabular}};
\end{tikzpicture}

\end{document}

enter image description here

Skillmon
  • 60,462
  • This works, but I find I have to pdflatex twice. Is that just something to do with tikz? – Sparhawk Aug 31 '17 at 11:44
  • 1
    @Sparhawk yes, this is because tikz's positioning option current page.center might need two runs to determine the needed shift to actually hit the center. – Skillmon Aug 31 '17 at 11:52
  • Pretty close, but the top gap is 4% shorter than the bottom gap, when I set margin=0mm. Probably good enough, but I wonder why the slight discrepancy. – Sparhawk Sep 03 '17 at 21:41
  • @Sparhawk honestly I have no clue. Perhaps because those are all uppercase letters. Try with an \fbox around the tabular with \fboxsep=-\fboxrule before the \fbox. This way you could check for the discrepancy correctly. – Skillmon Sep 03 '17 at 21:53