%%%%%%%% DISCLAIMER & GETTING STARTED

% This document has examples of how to use LaTeX to do pretty much anything you
% might need for a lab report for Statistics 215A. The solutions given here are
% those I've come up with in the course of my own work; I'm not a LaTeX authority,
% however, and they may not be the best, and certainly aren't the only,
% answers. This document should still be a good template for beginners.
%
% To "compile" this file, use
%
%   latex lab_template.tex
%
% from your UNIX command line. (Documents, like this one, which contain
% cross-references may need to be compiled twice.) This generates a .dvi file
% which can be viewed with xdvi. (Type "xdvi &" from your command line to open
% it.) Generally, you'll then want to convert the .dvi into a .ps or .pdf. Use
%
%   dvips -t letter -o lab_template.ps lab_template.dvi
%
% to make a postscript file. To convert this to a .pdf, use
%
%   ps2pdf lab_template.ps lab_template.pdf
%
% There more efficient ways to work with LaTeX and to generate the desired
% output formats; see me for details, or google "latex beginner". Good luck!



%%%%%%%% PREAMBLE

\documentclass{article}

% Extra packages for graphics, header control, good math typesetting, and margin
% control:

\usepackage{graphicx, fancyhdr, amssymb, amsmath, geometry}

% Lengths and margins: you're not supposed to monkey around with these in LaTeX,
% but default margins waste a lot of paper. For readability, leave lots of space
% on the left and right, but feel free to cut down blank space at the top and
% bottom of the page.

\geometry{ left = 1.75in, right = 1.75in, top = 1in, bottom = 1in }

% Headers and footers with FANCYHDR, a package which provides some useful extra
% commands. Note that "l," "r" and "c" denote "left," "right" and "center." The
% \headsep line contrals space between your header and the first bit of actual
% text on the page. The \headrulewidth line controls the thickness of the line
% under your header. Set this to 0 (by un-commenting the line below) if you
% don't want a line there.

\pagestyle{fancy}
\setlength{\headsep}{.5in}
\renewcommand{\headrulewidth}{.25pt}

\lhead{\footnotesize Statistics 215A, LaTeX template}
\chead{}
\rhead{\footnotesize \today}

\lfoot{}
\cfoot{\footnotesize Page \thepage}
\rfoot{}

% To avoid typing long expressions many times, define your own commands. (In some
% cases, LaTeX may already have definitions for the names you've chosen, in which
% case you need to re-define them -- this is the difference between \newcommand
% and \renewcommand.)

% Here are double-strike and caligraphic letters:

\newcommand{\E}{\mathbb{E}}
\renewcommand{\P}{\mathbb{P}}
\newcommand{\R}{\mathbb{R}}
\renewcommand{\L}{{\mathcal L}}

% The right way to define math operators, so that they display with the correct
% font and spacing:

\DeclareMathOperator{\Var}{Var}
\DeclareMathOperator{\Cov}{Cov}





%%%%%%%% DOCUMENT BEGINS HERE

\begin{document}

% Sections are automatically numbered. If you don't like numbers, use \section*
% instead of \section.

\section{First Section}

This is the first section of the document. It contains...

\begin{enumerate}
  \item A numbered list
  \item Two subsections
\end{enumerate}

% LaTeX has so very particular ideas about how one should indent the first line
% of a new paragraph. To get rid of an indentation you don't like, use
% \noindent. Getting it to indent things it has decided shouldn't be indented
% (e.g., the first line of a section) is a lot harder. Sections, figures,
% equations, and tables can be given a \label{}, and then referred to by label
% elsewhere for consistent numbering.

\noindent
You can find an equation in Section \ref{sec:equation}.




\subsection{A subsection}

As promised, here's the first subsection. For a paragraph break in LaTeX, you
need to leave a blank line before starting the next paragraph.

This is the next paragraph of the subsection. Although there's a blank line in
the source file, no blank line will appear in the formatted document.



% In the following subsection, both the subsection and the equation have been
% given labels. These labels will produce "1.1" and "1," respectively.

\subsection{Another subsection}
\label{sec:equation}

\begin{equation}
  \label{eq:normal}
  \int_{-\infty}^{\infty} \frac{ e^{ -x^2/2 } }{ \sqrt{2 \pi} } \ dx = 1
\end{equation}

\noindent
Learning all the abbreviations for mathematical symbols takes a while. Some
references to help get your started will be listed on the course web site. In
addition to display equations like (\ref{eq:normal}), you can also include
symbols in your paragraphs by using the dollar sign. For example, $-e^{\pi i}$
also equals 1, and $\Var(X+Y) = \Var X + \Var Y$ for uncorrelated $X$ and $Y$
(i.e., when $\E XY = \E X \E Y$).




\section{Second Section}

% When placing figures, the letters "h," "t," "b" and "p," denote "here," "top,"
% "bottom" and "page" (for a separate figure page). You can specify more than one
% if you like, and LaTeX will pick what it likes. Sometimes it ignores your
% request, and adding a "!" after the letters to show that you really mean it
% might help. Or it might not...

\begin{figure}[b!]
\begin{center}
  \includegraphics[width = 2.5in]{lab_template_figure.eps}
   %Using a minipage environment lets you pull in the margins for figure
   %captions, yielding a block which is only 80\% as wide as the surrounding
   %text.
  \begin{minipage}{.8\textwidth}
   \caption{A figure saved from R to encapsulated postscript. For graphics of
    this type, EPS makes for small files which look good in PDFs and on paper.
    Both R and MATLAB can save into this format.}
    \label{fig:EPSexample}
  \end{minipage}
\end{center}
\end{figure}

\noindent
This section demonstrates how to include figures. LaTeX will take care of where
the figure is placed in your document. (Its choices can be a bit perverse at
times, and it is stubborn.) Since your figures tend to move around, you should
refer to them like this: ``Figure \ref{fig:EPSexample} is pretty, but too small
to easily read.''




\section{Third Section}

Below is an example of how to make a table. You'll be begging for Excel---or
paper, pencil, and a ruler---after trying to set up a few of these.

\begin{center}
  \begin{tabular}[c]{|l|c|}
    \hline
    {\it Month} & {\it Days} \\
    \hline
    January & 31 \\
    February & 28 or 29 \\
    March & 31 \\
    \hspace{.2in} $\vdots$ & $\vdots$ \\
    December & 31 \\
    \hline
  \end{tabular}
\end{center}




\end{document}
