Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

LATEX Cheat Sheet: Main Notions, Cheat Sheet of Programming Languages

This cheat sheet contains the main notions about Latex, a software system for document preparation: Layout, Structure the Document, Math Equations, Text,Floating Environments.

Typology: Cheat Sheet

2019/2020

Uploaded on 10/09/2020

anandamayi
anandamayi 🇺🇸

4.2

(9)

250 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
4
ei*
* kann Spuren von Katzen enthalten
nicht für Humorallergiker geeignet
alle Angaben ohne Gewehr
L
A
T
E
XCheat Sheet
“Write clear & beautiful english with LAT
E
X!”
1. LaTeX Basics
You have to include the package mentioned in the headings e.g. to
use \definecolor you have to include the xcolor package with
\usepackage{xcolor} in the preamble
Available units for lengths and dimensions:
points pt millimeter mm inch in m width em
pixel px centimeter cm pica pc x height ex
1.1. Special Characters
\introduces a command (in text \textbackslash)
{ } embraces arguments, creates logical parts ($\{ \}$)
[ ] embraces optional command parameters ($\[ \]$)
%comments: code after % will be ignored. (\%)
&separates columns in tables (\&)
#parameter for own command declarations (\#)
_ ^ indizes and exponents in mathmode. e.g. a2
1(\_ \^)
2. Preamble before \begin{document}
2.1. Documentclass (necessary)
Usage: \documentclass[opt,opt]{class}
Common classes:
scrartcl (article), scrreprt (report), scrbook (book)
Common Options:
10pt/11pt/12pt Font size.
letterpaper/a4paper Paper size.
twocolumn Use two columns.
twoside Set margins for two-sided.
landscape Landscape orientation.
2.2. Load Packages (they do all the magic)
Usage: \usepackage[opt, opt]{package}
\PassOptionsToPackage{opt, opt}{package}
2.3. Penalties
Penalties are the main values that T
E
Xtries to minimise when line or page
breakes are calculated.
\linepenalty=10 breaking a page within a paragraph
\hyphenpenalty=50 line breaking at an automatic hyphen
\binoppenalty=700 breaking a line at a binary operator
\relpenalty=500 breaking a line at a relation
\clubpenalty=150 *breaking after first line of a paragraph
\widowpenalty=150 *breaking before last line of a paragraph
\brokenpenalty=100 page breaking after a hyphenated line
2.4. Language Settings with babel
\usepackage[ngerman, english]{babel} (last language default)
\selectlanguage{language} \foreignlanguage{language}{text }
2.5. Glossar and Nomenclature with glossaries
Load \usepackage[acronym]{glossaries}
Define: \newacronym{label}{ABB }{written-out}
\newglossaryentry{label}{name=..., description=...}
Use: \gls{label},\glspl{label }
3. Layout
3.1. Pagelayout with geometry package
Usage: \geometry{ opt, opt, ... }
Margin
Notes
Body
Header
Footer
1
2
3
45
6
7
8
9
10
11 bottom
top
left right
1
1in + \hoffset 2
1in + \voffset
3
\oddsidemargin 4
\topmargin
5
\headheight 6
\headsep
7
\textheight 8
\textwidth
9
\marginparwidth 10
\marginparwidth
11
\footskip
Additional paramter: left,right,top,bottom,paper=a4paper,
landscape|portrait,includehead,includefoot,twocolumn
3.2. Header and Footer with fancyhdr
\us ep a ck a ge { f an c yh d r }
\pagestyle{ fa n cy } % u se f an cyh dr pa ge sty le
\fancyhf{} % c lea r h ead er a nd f oo ter
\f a n cy h e a d [ RE ] { } % ev en pa ge r ig ht h ea de r
3.3. Colors with xcolor
\us ep a ck a ge { xcolor}
\d e fi n ec o lo r { tu m _ bl ue } { RG B }{ 0 , 115, 207 }
\c o lo r l et { c o l _ se c t io n } { tu m _ b lu e }
Predefined colors:
white, gray, black, red,green,blue,cyan,magenta,yellow
Fade a color with !value between 0 and 100, e.g. \color{gray!70}
Usage in Text: \textcolor{red}{text} or {\color{red}text}
4. Structure the Document
4.1. Title with titlepage
default: \author{text},\title{text},\date{\today},\maketitle
titlepage: \begin{titlepage} text \end{titlepage}
4.2. Table of Content, List of .. .
\tableofcontents \listoftables \listoffigures
\printglossaries (needs glossaries package)
4.3. Headings
\part{title} \subsubsection{title}
\chapter{title} \paragraph{title}
\section{title} \subparagraph{title}
\subsection{title}
*: no numbering, no entry in ToC
\part and \chapter only in dcumentcalss book or report
4.4. Lists
\begin{itemize} with bullet \item or \item[symbol]
\begin{enumerate} with numbered \item
\begin{description} with bold \item[word]
\be gi n { e nu me r at e } \ itemsep0 p t
\item Fi rst A rg um en t
\item Se con d Ar gu me nt
\end { e n um e ra t e }
5. Text
5.1. Fonts
Command Declaration Effect
\textrm{text} {\rmfamily text}Roman family
\textsf{text} {\sffamily text}Sans serif family
\texttt{text} {\ttfamily text} Typewriter family
\textmd{text} {\mdseries text}Medium series
\textbf{text} {\bfseries text}Bold series
\textup{text} {\upshape text}Upright shape
\textit{text} {\itshape text}Italic shap e
\textsl{text} {\slshape text}Slanted shap e
\textsc{text} {\scshape text}Small Caps shape
\emph{text} {\em text}Emphasized
\textnormal{text} {\normalfont text}Do cument font
\underline{text}Underline
5.2. Font size
\tiny tiny
\scriptsize scriptsize
\footnotesize footnotesize
\small small
\normalsize normalsize
\large large
\Large Large
\LARGE LARGE
\huge huge
\Huge Huge
5.3. Justification
Environment Declaration Other
\begin{center} \centering text \vfill text
\begin{flushleft} \raggedright text \hfill text
\begin{flushright} \raggedleft
6. Math Equations
Textstyle: $x^2 + 4$,x2+4 as part of the text.
Disyplaystyle: \begin{equation} x^2 + 4 \end{equation}
λ:= lim
x1→∞
x1
ˆ
x0
ft
2
n
pt2+ sin2(t)dt
!
1(1)
for numbered equations. use the * variant for unnumbered equations.
6.1. Fonts and Sizes in Math Mode
\scriptscriptstyle, \scriptstyle, \textstyle, \displaystyle
\mathrm, \mathit, \mathbb, \mathcal, \mathfrak
6.2. Often used math expressions
xn+1 x^{n+1} Ekin E_{\mathrm{kin}}
a+b
2\frac{a+b}{2} n
pa2+b2\sqrt[n]{a^2+b^2}
x1,...,xnx_1 , \ldots, x_n
x1+···+xnx_1 + \cdots + x_n
a+1
22
\left(a+\frac12 \right)^2
N
X
i=1
,
N
Y
i=1
\sum\limits_{i=1}^{N},
\prod\limits_{i=1}^{N}
F,Fk\vec F_{\perp},\vec F_{\parallel}
lim
a→∞ \lim\limits_{a \rightarrow \infty}
b
ˆ
a
x2dx\int\limits_a^b x^2\; \mathrm{d}x
df
dxx0
\left.\frac{\mathrm df}{\mathrm dx}
\right|_{x_0}
a>, A, A\vec a^\top, A^\dagger, A^*
!
<, def
=\stackrel{!}{<}, \stackrel{\rm def}{=}
6.3. Math function names (upright, correct spacing)
\sin \sinh \arcsin \csc \ln \min
\cos \cosh \arccos \sec \lg \max
\tan \tanh \arctan \cot \log \lim
\exp \det \tr \dim \ker \Pr
6.4. Important Math functions
P\sum Q\prod ´\int
´\int ˜\iint ˝\iiint ¸\oint
a\vec a.
a\dot a..
a\ddot aˆa\hat a
6.5. Important Symbols in Mathmode
++-±\pm \mp
<<\le \ll ·\cdot
>>\ge \gg ×\times
==6=\ne \equiv \approx
||\perp |\mid k\parallel
f0f’ \nabla \Delta \partial
\in \forall \exists @\nexists
\cap \cup /\notin \\setminus
`\ell \angle \circ \emptyset
\lor \land ¬\lnot \varnothing
>\top \bot \infty \propto
Homepage: www.latex4ei.de please report misstakes immediately. by Emanuel Regnath, contact emanuel.regnath@tum.de Created 17. November 2013 at 16:54 1
pf2

Partial preview of the text

Download LATEX Cheat Sheet: Main Notions and more Cheat Sheet Programming Languages in PDF only on Docsity!

ei

  • kann Spuren von Katzen enthaltennicht für Humorallergiker geeignetalle Angaben ohne Gewehr

LATEX Cheat Sheet

“Write clear & beautiful english with LATEX!”

1. LaTeX Basics

You have to include the package mentioned in the headings e.g. to use \definecolor you have to include the xcolor package with \usepackage{xcolor} in the preamble

Available units for lengths and dimensions: points pt millimeter mm inch in m width em pixel px centimeter cm pica pc x height ex

1.1. Special Characters

\ introduces a command (in text \textbackslash) { } embraces arguments, creates logical parts (${ }$) [ ] embraces optional command parameters ($[ ]$) % comments: code after % will be ignored. (%) & separates columns in tables (&)

parameter for own command declarations (#)

_ ^ indizes and exponents in mathmode. e.g. a^21 (_ ^)

2. Preamble before \begin{document}

2.1. Documentclass (necessary)

Usage: \documentclass[opt,opt]{class}

Common classes: scrartcl (article), scrreprt (report), scrbook (book)

Common Options: 10pt/11pt/12pt Font size.

letterpaper/a4paper Paper size. twocolumn Use two columns.

twoside Set margins for two-sided.

landscape Landscape orientation.

2.2. Load Packages (they do all the magic)

Usage: \usepackage[opt, opt]{package}

\PassOptionsToPackage{opt, opt}{package}

2.3. Penalties

Penalties are the main values that TEXtries to minimise when line or page breakes are calculated. \linepenalty=10 breaking a page within a paragraph

\hyphenpenalty=50 line breaking at an automatic hyphen \binoppenalty=700 breaking a line at a binary operator

\relpenalty=500 breaking a line at a relation \clubpenalty=150 *breaking after first line of a paragraph

\widowpenalty=150 *breaking before last line of a paragraph

\brokenpenalty=100 page breaking after a hyphenated line

2.4. Language Settings with babel

\usepackage[ngerman, english]{babel} (last language default) \selectlanguage{language} \foreignlanguage{language}{text}

2.5. Glossar and Nomenclature with glossaries

Load \usepackage[acronym]{glossaries} Define: \newacronym{label}{ABB}{written-out} \newglossaryentry{label}{name=..., description=...} Use: \gls{label}, \glspl{label}

3. Layout

3.1. Pagelayout with geometry package

Usage: \geometry{ opt, opt, ... }

Margin Notes

Body

Header

Footer

1

2

3

(^4 )

6

7

8

9

10

11

bottom

top

left right

© 1 1in + \hoffset © 2 1in + \voffset © 3 \oddsidemargin © 4 \topmargin © 5 \headheight © 6 \headsep ©^7 \textheight ©^8 \textwidth © 9 \marginparwidth 10 © \marginparwidth 11 © \footskip Additional paramter: left,right,top,bottom, paper=a4paper, landscape|portrait, includehead,includefoot, twocolumn

3.2. Header and Footer with fancyhdr

\ usepackage { fancyhdr } \ pagestyle { fancy } % use fancyhdr pagestyle \ fancyhf {} % clear header and footer \ fancyhead [ RE ]{} % even page right header

3.3. Colors with xcolor

\ usepackage { xcolor } \ definecolor { tum _ blue }{ RGB }{0 , 115 , 207} \ colorlet { col _ section }{ tum _ blue }

Predefined colors: white, gray, black, red, green, blue, cyan, magenta, yellow Fade a color with !value between 0 and 100, e.g. \color{gray!70} Usage in Text: \textcolor{red}{text} or {\color{red}text}

4. Structure the Document

4.1. Title with titlepage

default: \author{text}, \title{text}, \date{\today}, \maketitle titlepage: \begin{titlepage} text \end{titlepage}

4.2. Table of Content, List of...

\tableofcontents \listoftables \listoffigures \printglossaries (needs glossaries package)

4.3. Headings

\part{title} \subsubsection{title} \chapter{title} \paragraph{title} \section{title} \subparagraph{title} \subsection{title} *: no numbering, no entry in ToC \part and \chapter only in dcumentcalss book or report

4.4. Lists

\begin{itemize} with bullet \item or \item[symbol] \begin{enumerate} with numbered \item \begin{description} with bold \item[word]

\ begin { enumerate }\ itemsep 0 pt \ item First Argument \ item Second Argument \ end { enumerate }

5. Text

5.1. Fonts

Command Declaration Effect

\textrm{text} {\rmfamily text} Roman family \textsf{text} {\sffamily text} Sans serif family \texttt{text} {\ttfamily text} Typewriter family \textmd{text} {\mdseries text} Medium series \textbf{text} {\bfseries text} Bold series \textup{text} {\upshape text} Upright shape \textit{text} {\itshape text} Italic shape \textsl{text} {\slshape text} Slanted shape \textsc{text} {\scshape text} Small Caps shape \emph{text} {\em text} Emphasized \textnormal{text} {\normalfont text} Document font \underline{text} Underline

5.2. Font size

\tiny tiny \scriptsize scriptsize \footnotesize footnotesize \small small \normalsize normalsize

\large large

\Large Large

\LARGE LARGE

\huge huge

\Huge Huge

5.3. Justification

Environment Declaration Other \begin{center} \centering text \vfill text \begin{flushleft} \raggedright text \hfill text \begin{flushright} \raggedleft

6. Math Equations

Textstyle: $x^2 + 4$, x^2 + 4 as part of the text. Disyplaystyle: \begin{equation} x^2 + 4 \end{equation}

λ := lim x 1 →∞

xˆ 1

x 0

f

t 2

n^ √t (^2) + sin (^2) (t) dt^

! ≤ 1 (1)

for numbered equations. use the * variant for unnumbered equations.

6.1. Fonts and Sizes in Math Mode

\scriptscriptstyle, \scriptstyle, \textstyle, \displaystyle \mathrm, \mathit, \mathbb, \mathcal, \mathfrak

6.2. Often used math expressions

xn+1^ x^{n+1} Ekin E_{\mathrm{kin}} a + b 2

\frac{a+b}{2} n

a^2 + b^2 \sqrt[n]{a^2+b^2}

x 1 ,... , xn x_1 , \ldots, x_n

x 1 + · · · + xn x_1 + \cdots + x_n ( a +

\left( a + \frac12 \right)^

∑^ N

i=

∏^ N

i=

\sum\limits_{i=1}^{N}, \prod\limits_{i=1}^{N}

F (^) ⊥, F (^) ‖ \vec F_{\perp}, \vec F_{\parallel}

lim a→∞ \lim\limits_{a \rightarrow \infty} ˆ^ b

a

x^2 dx \int\limits_a^b x^2; \mathrm{d}x

df dx

x 0

\left.\frac{\mathrm df}{\mathrm dx} \right|_{x_0}

a>, A†, A∗^ \vec a^\top, A^\dagger, A^* ! <,

def = \stackrel{!}{<}, \stackrel{\rm def}{=}

6.3. Math function names (upright, correct spacing)

\sin \sinh \arcsin \csc \ln \min \cos \cosh \arccos \sec \lg \max \tan \tanh \arctan \cot \log \lim \exp \det \tr \dim \ker \Pr

6.4. Important Math functions

\sum

\prod

´ \int \int

\iint

\iiint

\oint

a \vec a .a \dot a ..a \ddot a ˆa \hat a

6.5. Important Symbols in Mathmode

    • − - ± \pm ∓ \mp < < ≤ \le  \ll · \cdot

≥ \ge  \gg × \times = = 6 = \ne ≡ \equiv ≈ \approx | | ⊥ \perp | \mid ‖ \parallel f ′^ f’ ∇ \nabla ∆ \Delta ∂ \partial ∈ \in ∀ \forall ∃ \exists @ \nexists ∩ \cap ∪ \cup ∈/ \notin \ \setminus ` \ell ∠ \angle ◦ \circ ∅ \emptyset ∨ \lor ∧ \land ¬ \lnot ∅ \varnothing \top ⊥ \bot ∞ \infty ∝ \propto

Homepage: www.latex4ei.de – please report misstakes immediately. by Emanuel Regnath, contact emanuel.regnath@tum.de Created 17. November 2013 at 16:54 1

6.6. Delimeters

(.) (.) [.] [.] b.c \lfloor.\rfloor |.| |.| {.} {.} d.e \lceil.\rceil ‖.‖ |.| |.| \vert.\vert 〈.〉 \langle.\rangle Use \left( expr \right) to stretch any delimeter to the height of expr Or \big, \Big, \bigg for manual sizing e.g. \Big| \Big|

6.7. Arrows

Every combination of left,right,up,down with arrow(s) 7 → \mapsto \leadsto

→ \rightarrow ⇒ \Rightarrow −→ \longrightarrow =⇒ \Longrightarrow

← \leftarrow ⇐ \Leftarrow ←− \longleftarrow ⇐= \Longleftarrow

↑ \uparrow ⇑ \Uparrow

↓ \downarrow ⇓ \Downarrow ↔ \leftrightarrow ⇔ \Leftrightarrow

⇔ \leftleftarrows ⇒ \rightrightarrows

 \leftrightarrows  \rightleftarrows \leftrightharpoons \rightleftharpoons

6.8. Physical Units with siunitx

Use the package siunitx for correct display of numbers and units. It provide the commands \num{}, \si{}, and \SI{}{}. Some examples:

7 .123 456 × 1012 \num{7.123456e12}

[g] = m s−^2 [g] = \si{\meter \per \second \squared}

E = 1. (^3) mmkV E = \SI{1.3}{\kilo\volt\per\milli\meter}

You can use all SI units (pascal, henry, ...) and not only the base units. It is also possible to change the style of display with \sisetup{per-mode=reciprocal} or \sisetup{per-mode=fraction}: Prefixes like \kilo,\deca,\mega,\micro

7. LaTeX4EI classes & packages

latex4ei_thesis: layout with TUM colors scientific: useful scientific macros dx \diff x N, R, C \N, \R, \C

x \vec x

x 1 x 2

\vect{ x_1 \ x_2 }

A

\ma A

[
]

\mat{ 1 & 2 \ 3 & 4}

b^ F r \FT

DT Fb r \DTFT b^ L r \LT bZ r \ZT Additional function names (upright, correct spacing): \const, \sinc, \grad, \rot, \div, \tri, \rect, \erf

8. Floating Environments

8.1. Figures with graphicx

\ begin { figure } \ centering \ includegraphics [ width =9 cm ]{./ img / diagram. pdf } \ caption [ title for LOF ]{ this is the long title } \ label { fig : example 1} \ end { figure }

Load image: \includegraphics[width=x]{file} Alter numbering: \renewcommand\thefigure{\arabic{figure}} 8.1.1 Subfigures with subfigure Usage \subfigure[caption]{graphic, label}

8.2. Tables

\ begin { table } \ centering \ begin { tabular }{ ll } \ textsc { Name } & \ textsc { Desc .}\ \ hline test 1 & is no good idea &\ bla 2 & even worse &\ \ end { tabular } \ caption { My first Table } \ label { tab : example 1} \ end { table }

Usage: \begin{tabular}[htbp]{@{}lrc|p{3cm}} Column distance: \setlength{\tabcolsep}{5pt} Adjust row distance: \renewcommand{\arraystretch}{1.5} Partial lines: \cline{2-3} instead of \hline Additional packages: longtable, booktabs, colortbl

8.3. Source Code Listings with listings

Options: \lstset{basicstyle=\tt, language=C} Languages: C,C++,Java,Matlab,Python,HTML,XML,bash,...

Environment: \begin{lstlisting} code \end{lstlisting} Inline: \lstinline?code?

\ begin { lstlisting } int i =0; for ( i = 0; i < 10; i ++){ printf ( " Line % i " , i ); } \ end { ltlisting } % missing s!

9. Correct Typography

9.1. Hyphen and Dashes

Rule: The hyphen is never placed between two spaces!

Name Source Example Usage

hyphen - X-ray, in- and output connect words en-dash -- 1 – 5, Paris – Rom seperate numbers. em-dash --- Yes—or no? Punctuation. minus $-$ 5 − 3 = 2 Equations.

9.2. Quotation Marks

Language Symbols LaTeX

German ” ’

... ‘ “ \glqq \glq ... \grq \grqq English “ ‘... ’ ” ‘‘ \lq ... \rq ’’ France <... > \flqq \flq ... \frq \frqq

“I think”, said Anna, “he shouted ‘This is Lars’s car!’, when I saw him.”

9.3. Numbers and Dates

Numbers Look Usage

old-style  as part of text, dates lining 1234567890 as math value

British American German

27/06/93 06/27/93 27.06. 27 June, 1993 June 27, 1993 27. Juni 1993 International notation (ISO 8601): yyyy-mm-dd: 1993-06-

9.4. Spacing

a!b ab a,b a b a;b a b a\quad b a b ab ab a>b a b a\ b a b a\qquad b a b \hspace{length}, \vspace{length} *: even at line start \phantom{text}, \vphantom{text} Protected space ~

9.5. Boxes and Rules

Normal: \parbox[pos][height][contentpos]{width}{text} or \begin{minipage}[pos][height][contentpos]{width} text

Prevent line breaking: \mbox{text} Lift Text: \raisebox{lift}[height][depth]{text} Framed Box: \framebox[width][pos]{text} or \fbox{text} Resize: \scalebox{10}{Giant} Lengths: \setlength{\fboxsep}{10pt}, \setlength{\fboxrule}{2pt}

10. Bibliography with BibTEX

10.1. BibTEX entry types

@article Journal or magazine article. fields: author, title, journal, year, volume

@book Book with publisher. fields: author/editor, title, publisher, year

@techreport Tech report, usually numbered in series. fields: author, title, institution, year

@phdthesis PhD. or other thesis. fields: author, title, school, year

\ bibliographystyle { alphadin } \ bibliography { < bibliographyfile. bib >}

10.2. References with hyperref

\cite{key } Cite a reference \label{marker } Set a marker for cross-reference, of- ten of the form \label{sec:item} like \label{fig:diag1}. \ref{marker } Give section/body number of marker. \pageref{marker } Give page number of marker. \footnote{text} Print footnote at bottom of page. \url{url} Creates click-able web-adress. \href[options]{url}{text} click-able link \hyperref[marker ]{text} click-able ref

10.3. Reference management software supporting BibTEX

Mendeley: free, Win/Linux/Mac, import from several websites Citavi: free, Win

11. Include beautiful Matlab Plots

Same font, line width, vector graphic

12. Own Commands and Writing Packages

\usepackage[options]{package} load package \newcommand[paranum]{\newcmd}{tex #1} define command \renewcommand{\cmd}{ latex #1,#2 } alter command \let\cmdcopy\cmd copy a command Read this document CTAN

Some important variables: Counters: \thepage, \thesection, \thefigure Lengths: \textwidth, \parindent, \parskip

12.1. Plain TEX

These plain TEX commands should be used carfully Fonts \rm, \sf, \sc, \sl, \it, \tt Definitions \def\newcmd{texcode}, \let\newcmd\cmd If \ifnum\counter<10 true text \else false text \fi

13. Useful Weblinks

LaTeX4EI www.latex4ei.de Font & Symbols https://de.wikipedia.org/wiki/Hilfe:TeX Color Schemes http://colorschemedesigner.com Tipps for Package Writers:

Homepage: www.latex4ei.de – please report misstakes immediately. by Emanuel Regnath, contact emanuel.regnath@tum.de Created 17. November 2013 at 16:54 2