Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for How to use Latex for awesome letters
Dandy Vica
Dandy Vica

Posted on

     

How to use Latex for awesome letters

If you don't knowLateχ (pronounced Lay-teck, because the last letter is the Greek letter Chi χ), you definitely have to. For professional looking documents, letters, resumes, articles, it's one of the best document production system on earth. To get an idea of its power:https://en.wikipedia.org/wiki/LaTeX

It has nothing to do traditionalWYSIWYG software. It more relates to a traditional compiler, where source code language isLateχ and compilation output is generally a PDF file (but can also be a DVI or PostScript one).Lateχ is extensible using packages, for almost everything. It is very popular among scientists because of its rich and powerful science symbols library.

The number ofLateχ documents, tutorials, references etc is literally staggering. Just google them to get the full power of it. My goal is not to add another one, but rather help you to design a good-looking one page letter.

Installing Latex on Linux

$sudoapt-getinstalltexlive-full
Enter fullscreen modeExit fullscreen mode

This is a full blown installation, maybe bloated (around 5GB is installed), with all world languages and lots of packages you'll probably never use. But this is much simpler to deal with IMHO.

Choosing an editor

On Linux,TexStudio is my favorite. Intuitive and already configured, its fast and efficient. It sports syntax color highlighting, shortcuts for most common definitions, wizards, etc. Available for a host of distributions, just download the relevant package and install it:https://www.texstudio.org/

Designing a letter

EveryLateχ document is starting with a preamble:

% define a new A4 document with 12pt font size\documentclass[a4paper,12pt]{article}
Enter fullscreen modeExit fullscreen mode

For english-spoken fellows, you can changea4paper withletterpaper which is the default page size.

After that, a list of packages needed to get the desired effects are loaded:

% define a new A4 document with 12pt font size\documentclass[a4paper,12pt]{article}% for mobile phone etc symbols\usepackage{marvosym}% set margins with no header and no footer\usepackage[left=1.9cm,top=2cm,bottom=2.5cm,right=1.9cm,nohead,nofoot]{geometry}% if fancy tables are needed\usepackage{array}% if colors are needed\usepackage{color}% Latex can't use TrueType fonts out of the box% to use TrueType fonts, use this package.% Caveat: need to compile with XeLatex\usepackage{fontspec}\setmainfont{Linux Libertine O}% no page numbers\pagestyle{empty}% for images and image files list of search paths\usepackage{graphicx}\graphicspath{{.}{../../../Photos/}}% no paragraph identation (or change it to whatever is needed)\setlength{\parindent}{0pt}% space between paragraphs\setlength{\parskip}{11pt}% interline space\linespread{1.125}% PDF metadata into the final file\usepackage[            pdfauthor={Conan Doyle},            pdftitle={Adventures of Sherlock Holmes}            ]{hyperref}
Enter fullscreen modeExit fullscreen mode

Now it's to time to start typing your text, because up to now, all tags are only forLateχ internal use. Everything should stick between those 2 Latex tags:

\begin{document}\end{document}
Enter fullscreen modeExit fullscreen mode

Here is the whole text:

%% ------------------------------------------------------------%% document start%% ------------------------------------------------------------\begin{document}%% ------------------------------------------------------------%% header table%% ------------------------------------------------------------\begin{tabular}{p{10cm} p{5cm}}\begin{minipage}[t]{0.40\textwidth}\begin{flushleft}{\Large\textbf{John H. Watson}}\\[10pt]            221B Baker Street\\            London\\[8pt]\Mobilefone ~ +41 06 00 00 00 00\\\Email ~ john.watson@outlook.com\\[20pt]\end{flushleft}\end{minipage}&\begin{minipage}[t]{0.40\textwidth}\begin{flushright}{\Large\textbf{Professor Moriarty}}\\[10pt]            6649 N Blue Gum St\\            London\\\end{flushright}\end{minipage}\end{tabular}\begin{flushleft}London, 1895Object: A scandal in Bohemia\end{flushleft}\vspace{1.5cm}%% ------------------------------------------------------------%% Letter body%% ------------------------------------------------------------Dear Sir,\vspace{1.5cm}To Sherlock Holmes she is always the woman. I have seldom heardhim mention her under any other name. In his eyes she eclipses andpredominates the whole of her sex. It was not that he felt any emotionakin to love for Irene Adler. All emotions, and that one particularly,were abhorrent to his cold, precise, but admirably balanced mind. Hewas, I take it, the most perfect reasoning and observing machine thatthe world has seen; but, as a lover, he would have placed himself in afalse position. He never spoke of the softer passions, save with a gibeand a sneer. They were admirable things for the observer—excellentfor drawing the veil from men’s motives and actions. But for thetrained reasoner to admit such intrusions into his own delicate andfinely adjusted temperament was to introduce a distracting factor whichmight throw a doubt upon all his mental results. Grit in a sensitiveinstrument, or a crack in one of his own high-power lenses, would notbe more disturbing than a strong emotion in a nature such as his. Andyet there was but one woman to him, and that woman was the late IreneAdler, of dubious and questionable memory.I had seen little of Holmes lately. My marriage had drifted us awayfrom each other. My own complete happiness, and the home-centredinterests which rise up around the man who first finds himself masterof his own establishment, were sufficient to absorb all my attention;while Holmes, who loathed every form of society with his wholeBohemian soul, remained in our lodgings in Baker Street, buried amonghis old books, and alternating from week to week between cocaine andambition, the drowsiness of the drug, and the fierce energy of hisown keen nature.\vspace{1cm}\hspace{10cm} Sherlock Holmes\end{document}
Enter fullscreen modeExit fullscreen mode

Several points to explain:

  • tables are not the most easy to read inLateχ source code. This is quite verbose, and not really intuitive. But once you got the whole idea, this is much simpler
  • units for spacing are so numerous that there's a complete article on Wikipedia:https://en.wikibooks.org/wiki/LaTeX/Lengths
  • to separate 2 paragraphs, just add one blank line between 2 blocks of text
  • for text, just type your text without thinking of spacing, alignment, carriage return etc. Just type it,theLateχ compiler will manage and calculate justification with correct word hyphenation (the way of word iscut to prevent overflow)
  • hspace andvspace are, as you already guessed, to keep horizontal or vertical spaces between text

Beware that to get the full power ofTrueType fonts, you need to compile withXeTeχ. This is done by selectingXeLaTeχ in the combo list inOptions -> Configure -> Production.

The result is a very neat, professional and good looking letter !

Hope this helps.

Photo by Andrew Buchanan on Unsplash

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Senior software engineer.Always willing to learn new stuff.
  • Location
    France
  • Education
    Master's Degree in Computer Science
  • Work
    Software architect, devops engineer
  • Joined

Trending onDEV CommunityHot

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp