Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
LaTeX Cookbook

You're reading from   LaTeX Cookbook Over 100 practical, ready-to-use LaTeX recipes for instant solutions

Arrow left icon
Product type Paperback
Published in Feb 2024
Publisher Packt
ISBN-13 9781835080320
Length 424 pages
Edition 2nd Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Stefan Kottwitz Stefan Kottwitz
Author Profile Icon Stefan Kottwitz
Stefan Kottwitz
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Preface 1. Chapter 1: Exploring Various Document Classes FREE CHAPTER 2. Chapter 2: Tuning the Text 3. Chapter 3: Adjusting Fonts 4. Chapter 4: Creating Tables 5. Chapter 5: Working with Images 6. Chapter 6: Creating Graphics 7. Chapter 7: Creating Beautiful Designs 8. Chapter 8: Producing Contents, Indexes, and Bibliographies 9. Chapter 9: Optimizing PDF Files 10. Chapter 10: Writing Advanced Mathematics 11. Chapter 11: Using LaTeX in Science and Technology 12. Chapter 12: Getting Support on the Internet 13. Chapter 13: Using Artificial Intelligence with LaTeX 14. Index 15. Other Books You May Enjoy

Writing a letter

Letters have a specific structure. Commonly, they have an addressee field at a fixed position, which should be visible in the envelope window. It also should show a back address of yourself as the sender. An opening text and a closing phrase are usual elements; you may add fold marks and enclosures.

How to do it...

We will use a KOMA-Script class specifically designed for letters named scrlttr2. Follow the following steps:

  1. Use the scrlttr2 class, activate the address field and fold marks via an option, and align the sender’s address to the right:
    \documentclass[addrfield=true, foldmarks=true,
      fromalign=right]{scrlttr2}
  2. Provide your name and your address using the \setkomavar command:
    \setkomavar{fromname}{Thomas Smith}
    \setkomavar{fromaddress}{123 Blvd \\ City, CC 12345}
  3. Write a date, either \today for today or any date as text:
    \date{\today}
  4. Begin the document:
    \begin{document}
  5. Open a letter environment with the recipient’s address as an argument:
    \begin{letter}{Agency \\ 5th Avenue \\
                   Capital City, CC 12345}
  6. Start with an opening, and let your letter text follow:
    \opening{Dear Sir or Madam,}
    the actual content of the letter follows.
  7. End with closing words:
    \closing{Yours sincerely}
  8. End the letter environment and the document:
    \end{letter}
    \end{document}
  9. Compile the document. Here is the upper part of the output:
Figure 1.6 – A letter template

Figure 1.6 – A letter template

That was pretty easy! You got fully fledged formal letter addressing information, envelope window support, today’s date, phrases, signature, and even fold marks.

Now, you can enter real addresses and actual letter text.

How it works...

When loading the scrlttr2 letter class, we activated the address field, switched on fold marks, and set the options for right aligning the sender’s address.

The scrlttr2 class is quite different from others, so it has a unique interface. Using the \setkomavar command, we set the content of class variables, similar to \renewcommand. Here, we put names and addresses. The KOMA-Script manual explains all available variables. As mentioned in the Developing a thesis recipe, you can open it by executing texdoc koma-script at Command Prompt or online at https://texdoc.org/pkg/koma-script.

We used a letter environment for the actual content, including the opening and closing phrases. The address is a mandatory argument for that environment. You can have several letter environments in a single document.

There’s more...

To improve input and hyphenation and change the font, look at the first recipes in Chapter 2, Tuning the Text.

Let’s take a look at some letter-specific options.

Separating paragraphs

Instead of indenting the beginning of paragraphs, you can visualize a paragraph break with an empty line. For this, add the parskip=full option to the comma-separated list of class options at the beginning.

Use parskip=half for less space.

Changing the signature

If you would like to use a signature different from your specified name for the address, you can modify the corresponding variable content in the preamble:

\setkomavar{signature}{Thomas}

It would be indented. You can get it left aligned by specifying the following code:

\renewcommand{\raggedsignature}{\raggedright}

The code just shown also belongs to the preamble.

Adding enclosures

If you would like to add enclosures to your letter, it’s common to mention them. You can do this by inserting an \encl command right before \end{letter}:

\encl{Curriculum vitae, certificates}

You can change the default encl: option if you like by modifying the corresponding variable before calling the \encl command:

\setkomavar*{enclseparator}{Attached}

We used the \setkomavar* starred version, which modifies the description of a variable instead of its content, which actually is : – that is, a colon followed by a space.

You have been reading a chapter from
LaTeX Cookbook - Second Edition
Published in: Feb 2024
Publisher: Packt
ISBN-13: 9781835080320
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime