Mikkel Madsen latex@mikkl.dk
Today Recap from lecture 1 Sections, figures, tables, equations, multiple files TechnicCenter demonstration Navigating a large report Compiling New material Bold, italic, fontsize etc. Lists Footnotes References Header, footer and margins 2
Installation Windows: MiKTeX - http://miktex.org/2.9/setup TeXnicCenter - http://www.texniccenter.org/ OS X: MacTeX Editor of choice Linux: TeXlive Editor of choice See http://latex.mikkl.dk > Installation 3
Hello, World! Preamble and contents \documentclass[a4paper,12pt]{book} \usepackage[latin1]{inputenc} %This line is commented out, so it does nothing \begin{document} Hello, World! \end{document} 4
Adam Tulinius latex@antistof.dk 2010 5
Table of Contents \tableofcontents NB: You may need to build your project twice to update the ToC 6
Multiple Files Easier for groups You don t have to scroll around in a 9000 line file c:\report\report.tex c:\report\chapter1\intro.tex c:\report\chapter1\section1\first_part.tex (You will give folders and files meaningful names, related to their contents. Instead of chapter1 and section1 ) Use relative paths to files (and leave out.tex): \input{chapter1/intro} \input{chapter1/section1/first_part} the path is relative to the ROOT file, i.e. the file containing your preamble. 7
Figures - Extended Preamble: \usepackage{graphicx} \begin{figure}[htb] \centering \includegraphics[width=0.5\textwidth]{graph.jpg} \caption{caption text} \end{figure} % desired width is defined and a caption is added Width=0.5\textwidth sets the width to half of the space between the right and left margins, i.e. the text width 8
Formula Preamble: \usepackage{amsmath,amssymb} Inline formula: Lorem ipsum $ f(x) = x^2 $ dolor sit amet. Normal formula: Lorem ipsum \begin{displaymath} f(x) = \int_{a}^{b} x^2 \, dx \end{displaymath} Dolor sit amet 9
Tables \begin{table}[htb] \centering \begin{tabular}{ l c r } \hline 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \\ \hline \end{tabular} \caption{blabla caption} \end{table} 10
Today Recap from lecture 1 Sections, figures, tables, equations, multiple files TechnicCenter demonstration Navigating a large report Compiling New material Bold, italic, fontsize etc. Lists Footnotes References Header, footer and margins 11
Today Recap from lecture 1 Sections, figures, tables, equations, multiple files TechnicCenter demonstration Navigating a large report Compiling New material Bold, italic, fontsize etc. Lists Footnotes References Header, footer and margins 12
Font sizes \tiny \scriptsize \footnotesize \small \normalsize (standard) \large \Large \LARGE \huge \Huge Commands change the size of all text after it Surround the text with {} if you don t want this. E.g. {\Large some text} 13
Bold, italic & typewriter \textbf{bold} \emph{italic} \texttt{typewriter} Bold Italic Typewriter 14
Extra line change \\ (double backslash) forces a new line \noindent prevents LaTeX from indenting the line (as it will do for the first line of a paragraph) 15
Force new page \clearpage Skip to next page \cleardoublepage Skip to next odd page 16
Lists 1/2 \begin{enumerate} \item Step 1 \item Step 2 \end{enumerate} \begin{description} \item [Lorem ipsum] dolor sit amet \item [consectetur] dipiscing elit \end{description} \begin{itemize} \item Lorem \item Ipsum \end{itemize} Enumerate Itemize Description 17
Lists 2/2 \begin{enumerate} \item Step 1 \item Step 2 \begin{enumerate} \item Step 2.1 \item Step 2.2 \end{enumerate} \end{enumerate} 18
Footnotes A computer contains, among other things, a CPU\footnote{ CPU: Central Processing Unit}. 19
References 1/3 \label{labelnavn} \ref{label} is replaced by figure number \pageref{label} is replaced by the page # the figure is on You can add labels to many things, floats (figures, tables), equations, sections/chapters etc. See figure \ref{fig:graph} on page \pageref{fig:graph}. \begin{figure}[htb] \centering \includegraphics[width=0.8\textwidth]{graph.jpg} \caption{blabla} \label{fig:graph} \end{figure} 20
References 2/3 - table See table \ref{tab:stuff} on page \pageref{tab:stuff}. \begin{table}[htb] \centering \begin{tabular}{ l c r } \hline 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \\ \hline \caption{blabla caption} \label{tab:stuff} \end{table} 21
References 3/3 - section \section{first section}\label{sec:first_sec} Lorem ipsum dolor sit amet. \section{second section} See section \ref{sec:first_sec} on page \pageref{sec:first_sec}. 22
Headers & footers 1/2 % Header and footer style defined in preamble \usepackage{fancyhdr} \setlength{\headheight}{15.2pt} \pagestyle{fancy} % thickness of line in header: \renewcommand{\headrulewidth}{0.5pt} % thickness of line in footer: \renewcommand{\footrulewidth}{0pt} 23
Headers & footers 2/2 % In preamble \lhead[left-of-header-even]{left-of-header-odd} \chead[center-of-header-even]{center-of-header-odd} \rhead[right-of-header-even]{right-of-header-odd} \lfoot[left-of-footer-even]{left-of-footer-odd} \cfoot[center-of-footer-even]{center-of-footer-odd} \rfoot[right-of-footer-even]{right-of-footer-odd} Replace X-of-header/footer-X with the content you want to be in that position. Insert page number with: \thepage If you use the template, you won t need to do any of this, but you may want something specific 24
Margins \usepackage[top=2cm, bottom=2cm, left=3cm, right=4cm]{geometry} NB: Margins indicate the whitespace around the actual content (not including the header/footer), so there must be room for the header and footer in the margins NB: This indicates the margin sizes for odd pages, they will be mirrored for even pages. (we want larger margins at the edge, than where the pages are bound) 25
Exercise Download the report template from latex.mikkl.dk Are you able to compile? Try the things we have covered so far: Sections Figures Tables Equations/formulas Font size, bold font, etc. References Footnotes 26
Until next week USE THE WEBSITE LATEX.MIKKL.DK The page for this course is linked at the top Elective course on LaTeX 2011 Slides are available there Install SVN, we will be using it next time http://latex.mikkl.dk/index.php?title=svn 27