Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've recently turned away from the letter document class for writing my covering letters as I'd like a little more creative freedom with the formatting, and as my own little exercise in formatting LaTeX. I'm almost done with my template, but I just have two teeny questions.

  1. Is there a way to suppress page numbers for a single paged document, but allow them if my letter spills over to a second page (without compiling and checking manually)? And also,
  2. Is there a way to align the rightmost point of the return address at the top with the rightmost part of the main body? I'd normally do it manually after compiling, but since I like to put the date in there, the length keeps changing. If that's a little vague, here's an MWE (using tabular, which is as close as I've gotten):

    \documentclass{article}
    
    \begin{document}
    \begin{minipage}{\textwidth}
    \hfill\begin{tabular}{l}
    a) Return address\\
    b) Here's a short line\\
    c) Here's a slightly longer line
    \end{tabular}\\
    \end{minipage}\\
    
    \noindent Here's a really long bit of text, to show where the line breaks are normally, and to show that at the moment, they don't line up. The end of the line labelled c) should align with the line breaks in this body of texts, and the start of line a) and b) should align with the start of line c).
    
    \end{document}
    
share|improve this question

migrated from stackoverflow.com Dec 11 '12 at 11:02

This question came from our site for professional and enthusiast programmers.

    
There are a multitude of document classes for letter; e.g. koma-script. No need to roll your own. –  Martin Schröder Dec 10 '12 at 7:22
    
Welcome to TeX.sx! Your post was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. –  Werner Dec 11 '12 at 15:30
add comment

1 Answer

  1. Since your document seems fairly simple (doesn't contain floating environments like figures or tables), you can use the lastpage package to pick up the value of the last page within your document. refcount is another package which provides the means to translate references (including a page reference) into a counter, so one can examine the value or condition on it.

    Specifically, I would use the following in your document preamble:

    \usepackage{lastpage,refcount}% http://ctan.org/pkg/{lastpage,refcount}
    \newcounter{lastpage}
    \AtBeginDocument{%
      \setcounterpageref{lastpage}{LastPage}%
      \ifnum\value{lastpage}=1\thispagestyle{empty}\fi%
    }
    

    The lastpage package defines the page reference LastPage. This is extracted using refcount's \setcounterpageref and stored in a newly-created counter lastpage. Then, \AtBeginDocument we check whether the value of lastpage is 1 and set the page style accordingly. The default page style is otherwise used (plain in this case).

    We need to set and check lastpage \AtBeginDocument, since the .aux file with the LastPage reference is only read at the end of the preamble, leaving LastPage undefined until then.

    Using this approach requires you to compile your document at least twice. The first time to write the correct page reference to the .aux file, and the second time to read the update value from it.

  2. A tabular necessarily inserts some spacing around its columns. This is given by the length \tabcolsep (6pt in article, and may be different in other document classes). You can override the right-hand column separation by using the column specification l@{}.

    Specifically your tabular definition might look like this:

    \begin{tabular}{l@{}}
    %...
    \end{tabular}
    

The following minimal example highlights the above two points.

enter image description here

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{lastpage,refcount}% http://ctan.org/pkg/{lastpage,refcount}
\newcounter{lastpage}
\AtBeginDocument{%
  \setcounterpageref{lastpage}{LastPage}%
  \ifnum\value{lastpage}=1\thispagestyle{empty}\fi%
}
\begin{document}
\null\hfill\begin{tabular}{l@{}}
a) Return address\\
b) Here's a short line\\
c) Here's a slightly longer line
\end{tabular}

\bigskip
\lipsum[1-4]

\end{document}

In the above example, use \lipsum[1-9] to see the effect of the page style change. Remember to compile twice.

The lipsum package merely provides dummy text, Lorem Ipsum style.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.