%% ``What you can do with LaTeX'' %% Kazuyuki Tamura %% AstroTool Seminar, Arizona State University %% April 9, 2010 %% %% Last updated: March 29, 2010 %% \documentclass[12pt]{article} %%% Load some packages to use extra functions in the LaTeX \usepackage{color} %% This enables the use of color. For available %% colors and how to use it, see: %% http://en.wikibooks.org/wiki/LaTeX/Colors \usepackage{graphicx} %% This enables to insert figures %\usepackage{times} %% This changes the base font to 'times' \usepackage{sidecap} \usepackage{wrapfig} %%% Macros, that you frequently use in the tex file, this simplifies a %%% lot of writing in the main body. \newcommand{\figref}[1]{Figure~\ref{#1}}% \newcommand{\secref}[1]{Section~\ref{#1}}% \newcommand{\tabref}[1]{Table~\ref{#1}}% \newcommand{\eqref}[1]{Equation~\ref{#1}}% \newcommand{\bs}{$\backslash$}% \newcommand{\blt}{$\bullet$}% \newcommand{\thistex}{\texttt{basic\_latex.tex}}% \newcommand{\vsk}{\vspace{3mm}}% \newcommand{\blue}{\color{blue}}% \newcommand{\red}{\color{red}}% \newcommand{\green}{\color{green}}% \newcommand{\magenta}{\color{magenta}}% \newcommand{\HII}{\mbox{H\,\textsc{ii}}}% \begin{document} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% This section (till line with ``\maketitle'') %%% makes a title of the document \title{\textsc{What you can do with \LaTeX}} \author{KAZuyuki Tamura} \date{Astro Comp-Tool Seminar: April 9, 2010} \maketitle %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \vspace{1cm} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% This section makes an ABSTRACT for the document \begin{abstract} This is a short document to illustrate the basic use of \LaTeX. In this example, I explain how to use some \LaTeX\ commands, and how to put a text (the main body that appear in ps/pdf files) into a ``\texttt{***.tex}'' file. Make sure you have both this PDF as well as the \texttt{basic\_latex.tex} to read along with. Most of the materials in this packet, \secref{intro}--\secref{bibliography}, will be a summary of ``learning \LaTeX'' by David F.\ Griffiths and Desmond J.\ Higham (\figref{fig1}). Final section, \secref{advanced}, contains some advanced use of \LaTeX. You can also find many useful tips and examples of \LaTeX\ on Internet. Particularly, a useful web page is the Wikibook for \LaTeX:\\ \texttt{http://en.wikibooks.org/wiki/LaTeX}. \end{abstract} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \vspace{4cm} \begin{center} \footnotesize{ \copyright\ 2010 Kazuyuki Tamura\\ School of Earth and Space Exploration\\ Arizona State University\\ Tempe, AZ 85287-1404\\ ktamura@asu.edu } \end{center} \newpage %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% This is the beginning of the main body \section{Introduction}\label{intro} %% This is the section heading for %% section 1 \LaTeX\ is a macro package based on TeX (a low-level markup and programming language). It is a typesetting system that specializes in producing mathematically oriented documents. But \LaTeX\ can create a range of documents, including journal papers, class handouts, reports, letters, slides, dissertation/thesis, books, resume/CV, etc., etc. \vsk\noindent Why you should learn about \LaTeX? \vspace{-3mm} \begin{itemize} \item Mathematical formulae can be produced easily (see \secref{math}). With \LaTeX, your documents will look polished. \item Chapters, sections, equations, citations, figures, tables, etc.\ can be labeled, so that cross-referencing is automated. \item \LaTeX\ is (usually) installed at many universities and research institutions, and can be run on many different platforms (PCs, Mac OS, workstations, and mainframe computers). \item The \texttt{tex} files have the standard ASCII format. Therefore, they can be produced using your favorite text editor. \end{itemize} \LaTeX\ is not a WYSIWYG (\textsc{w}hat \textsc{y}ou \textsc{s}ee \textsc{i}s \textsc{w}hat \textsc{y}ou \textsc{g}et) system. Hence, you can't see what the final version will like while typing. Instead, you see the \emph{logical structure} of the document. Therefore, you can concentrate on the content of your writing rather than the final appearance of the document. \LaTeX\ takes care of the formatting for you. Changing the format of your document is easy, and you also have some freedom of adjusting the appearance by changing/adding a small number of formatting commands. \newpage \section{Basics}\label{basics} In the \LaTeX, the `$\backslash$ (backslash)' and special characters such as \texttt{\$}, \texttt{\^{}}, and \texttt{\_} are used to format a document. \subsection{Minimum Requirements}\label{min_req} %% This makes the %% sub-heading for %% Section 2.1 In the ``\texttt{***.tex}'' file, you need minimum of: \begin{itemize} \vspace{-3mm} %% \vspace{*mm} shifts the following line up/down by %% specified distance, {*mm} can be replaced with %% {*cm}, {*in}, or other length-units. %% See section 1.5 for details. \item $\backslash$documentclass\{article\} \vspace{-3mm} \item $\backslash$begin\{document\} \vspace{-3mm} \item $\backslash$end\{document\} \end{itemize} And the main text are written in between``$\backslash$begin\{document\}'' and ``$\backslash$end\{document\}'' lines. \vsk \noindent For the package selection of ``documentclass'', some options are:\\ \begin{tabular}{llll} $\bullet$ {\color{blue} \textbf{article.cls}} & $\bullet$ {\blue report.cls} & & \\ \blt\ {\green letter.cls} & \blt\ {\green slides.cls} & & \\ \blt\ minimal.cls & \blt\ book.cls & \\ \blt\ {\magenta memoir.cls} & \blt\ {\magenta beamer.cls} & & \\ \blt\ {\red ltnews.cls} & \blt\ {\red ltxguide.cls} & \blt\ {\red proc.cls} & \blt\ {\red ltxdoc.cls} \\ \end{tabular} \vsk \noindent The options to the ``documentclass'' are:\\ \vspace{-7mm} \begin{itemize} \item \textbf{10pt, 11pt, 12pt} --- Sets the size of main font in the document. If no option is specified, 10pt is assumed. \vspace{-3mm} \item \textbf{a4paper, letterpaper, etc.} --- Defines a paper size. Default is ``a4paper'' (somehow, this does not work with my \LaTeX). \vspace{-3mm} \item \textbf{fleqn} --- Typesets displayed formulas left-aligned. \vspace{-3mm} \item \textbf{leqno} --- Places the numbering of formulae on the left hand side instead of the right. \vspace{-3mm} \item \textbf{titlepage, notitlepage} --- Specifies whether a new page should be started after the document title or not. the \texttt{article} class does not start a new page by default, while \texttt{report} and \texttt{book} do. \vspace{-3mm} \item \textbf{onecolumn, twocolumn} --- Instructs LaTeX to typeset the document in one column or two columns. \vspace{-3mm} \item \textbf{landscape} --- Changes the layout of the document to print in landscape mode. \end{itemize} \newpage \subsection{Basics: How to create a PDF file} \figref{fig1} illustrates how a ``***.tex'' file is converted into DVI, PDF, and/or a PostScript (ps) files. \begin{figure}[h] \centerline{ \includegraphics[width=\textwidth]{LaTeX_diagram} } \caption{\footnotesize How a \LaTeX\ file is compiled (image taken from \LaTeX\ Wikibook). The command to convert a file from DVI to PostScript is ``dvips'' rather than ``dvi2ps'', and the command from PostScript to PDF is ``ps2pdf13'' instead of ``ps2pdf''.}\label{fig1} \end{figure} The commands to create a PDF file (with LINUX and Mac X11 environments) for this particular file are (with PostScript figures):\\ \texttt{ latex basic\_latex.tex\\ latex basic\_latex.tex\\ dvips -P amz -P cmz -t letter basic\_latex.dvi -o basic\_latex.ps\\ ps2pdf13 basic\_latex.ps basic\_latex.pdf} \vsk If you are using JPG, PNG, and other format of figure other than PostScript, then you can simply do:\\ \texttt{ pdflatex basic\_latex.tex} \vsk If you are using Windows or Mac OS X GUI based TeX software, then it might be as easy as simply clicking a button in a menu bar. \newpage \subsection{Basics: Paragraphs and line-breaks}\label{paragraph} In the main body of text, even you make a line-break in the middle of sentence, or even with every single word within the ``***.tex'' file, \LaTeX\ will keep on writing on the same line as long as the text is continuing on the next line. On the other hand, you can also keep writing (as long as your text editor allows) on the same line, and \LaTeX\ will automatically adjust the word wrap to its default (or specified) text width of a page. If you want to make a new paragraph, simply insert an empty line (or any number of multiple empty lines) in between two paragraphs. Or, if you want to simply break the line, \\ you can also use ``$\backslash\backslash$" to make \\ a new line. See lines 243--246 in the \\ ``\texttt{basic\_latex.tex}'' for this example. \vspace{3mm} \noindent When making a new paragraph, and you don't want any indentation, you can add a \LaTeX\ command ``$\backslash$noindent'', so the new paragraph starts from the left-most position. This paragraph is written with this option, so the first word is not indented. \vspace{5mm} % The ``\%'' character in the ``\texttt{basic\_latex.tex}'' indicates that the text following the ``\%'' simbol \emph{ in the same line} is commented out. If you want to comment out some lines, simply put ``\%'' at the beggining of the line, and if you want to simply comment out a few words, you can use in the middle of the line as well. %% (This won't appear in the PDF.) See the ``\texttt{basic\_latex.tex}'' to see what is hidden around this sentence. %% (This line is completely ignored by the LaTeX, when compiled.) Commenting out with ``\%'' is useful when you are making a short note that you don't want to be seen but keep it there to remind you later. Or, when you are re-writing a paragraph, you can keep the old one as comment. See the tex file for example. %%%%% %% The following few lines are written as comment, and so it won't %% show up in the ps/PDF file when compiled, but the author (you) %% can still read in this file directly. It is useful in many %% different situations. And as you already have seen, the number %% of '%' can be any, one, two, five, or all across the line. %% (Anything after the first '%' in a line is treated as a comment.) %%%%% There were total of 8 lines of comments in the ``\texttt{basic\_latex.tex}'' just before this sentence, but you cannot see it in the ps/PDF file. \vspace{5mm} You can also use the \texttt{footnote}\footnote[1]{ see the \thistex\ to see exactly how it works. } to add some notes at the bottom of the page. One thing is that the numbering has to be done manually as:\\ \texttt{\bs footnote[2]\{...\}} \newpage %% This command inserts a page-break \subsection{Basics: Fonts}\label{fonts} The basic font size can be specified at the beginning of the tex file, as ``$\backslash$\{documentclass\}[XXpt]\{article\}''. This document is written with a 12-point font size, so the [XXpt] becomes [12pt] (See the very first line in the ``\texttt{basic\_latex.tex}''). If no size is defined, the \LaTeX\ uses 10-pint font as its default size. If you want to change a font size within the main body, you can use ``$\backslash$(fontsize)'' keyword. Those are: \begin{itemize} \vspace{-2mm} \item \bs Huge = {\Huge Huge Font} \vspace{-2mm} \item \bs huge = {\huge huge Font} \vspace{-2mm} \item \bs LARGE = {\LARGE LARGE Font} \vspace{-2mm} \item \bs Large = {\Large Large Font} \vspace{-2mm} \item \bs large = {\large large Font} \vspace{-2mm} \item \bs normalsize = {\normalsize Normal Size} \vspace{-2mm} \item \bs small = {\small Small Size} \vspace{-2mm} \item \bs footnotesize = {\footnotesize Footnote Size} \vspace{-2mm} \item \bs scriptsize = {\scriptsize Script Size} \vspace{-2mm} \item \bs tiny = {\tiny Tiny} \end{itemize} \noindent Some other available fonts include: \begin{itemize} \vspace{-2mm} \item \bs textup = \textup{Upright Type} \vspace{-2mm} \item \bs textit = \textit{Italic type} \vspace{-2mm} \item \bs textsl = \textsl{Slanted type} \vspace{-2mm} \item \bs textsc = \textsc{Small Caps type} \vspace{-2mm} \item \bs texttt = \texttt{Typewriter} \vspace{-2mm} \item \bs textsf = \textsf{Sans serif} \vspace{-2mm} \item \bs textrm = \textrm{Roman} % \vspace{-2mm} % \item \bs textmd = \textmd{Medium} \vspace{-2mm} \item \bs textbf = \textbf{Boldface} \end{itemize} \noindent If you want to emphasize a single (or multiple) words within a sentence, you can simply use ``\bs emph\{ \}'' to \emph{emphasize} a phrase. \subsection{Basics: Making a list}\label{list} If you are reading the ``\thistex'' file, you have noticed that several lists are made using \bs begin\{itemize\} and \bs end\{itemize\}, where each line/item is made with ``\bs item'' keyword at the beginning of line. Without any specific option, each item with start with a ``$\bullet$''. But you can also change it to anything (including special characters) by simply adding [ ] right after the ``\bs item'' as ``\bs item[***]''. For example: \begin{itemize} \vspace{-3mm} \item[X] is made with ``\bs item[X]'' \vspace{-3mm} \item[$\diamond$] is made with ``\bs item[\$\bs diamond\$]'' \vspace{-3mm} \item[3)] is made with ``\bs item[3)]'', and \vspace{-3mm} \item[Item 1.] is made with ``\bs item[item 1.]'' \end{itemize} \noindent Above are made with ``\texttt{itemize}'', but you can also make it with ``\texttt{enumerate}'' with a simple ``\bs item'' if you simply want numbers at the beginning of each item as: \begin{enumerate} \vspace{-3mm} \item This is item No.\ 1 \vspace{-3mm} \item This is item No.\ 2, and \vspace{-3mm} \item This is item No.\ 3 \end{enumerate} \noindent And if you want sub-items, you can combine two loops of \texttt{enumerate} or \texttt{itemize} as: \begin{enumerate} \vspace{-2mm} \item This is item No.\ 1 \vspace{-2mm} \begin{enumerate} \vspace{-2mm} \item This is item No.\ 1(a) \vspace{-2mm} \item This is item No.\ 1(b), and \end{enumerate} \vspace{-5mm} \item This is item No.\ 2 \end{enumerate} \newpage \vspace*{-3cm} \subsection{Basics: Spacing}\label{spacing} When you are writing a text, sometimes you want to shift around some words or lines or even figures and tables up/down/left/right. If you are reading the ``\thistex'', you should have noticed that ``\bs vspace\{*mm\}'' have been used a lot. \bs vspace\{*mm\} shifts what follows up/down for \texttt{*mm} (millimeter). Other units of lengths such as \texttt{cm}, \texttt{in}, \texttt{em} (the width of the letter ``M''---the widest character), \texttt{ex} (the height of the letter ``x''), and \texttt{pt} (points) are also available. Other than ``\bs vspace'', there is also ``\bs hspace'' to shift anything horizontally. For example, ``\bs hspace\{1in\}'' shift the following word \hspace{1in} to left for 1 inch. \hspace{-2cm} Or, you can start a line (or shift figures) to left for 2-cm by using ``\bs hspace\{-2cm\}'' (as in this one sentence paragraph). \vspace{0.5cm} %% This is same as ``\vspace{5mm}'' % If you use ``\bs hspace\{-2cm\}'' after a line-break by ``\bs\bs'', it usually does not shift the following line (omitted by \LaTeX).\\ \hspace{-2cm} Like this line here (See the tex file). %% This ``\hspace{-2cm}'' does not work here. Compare with the %% ``\hspace*{-2cm} used in the following paragraph, (see also the %% PDF file how it appears on paper.) But instead, if you add ``*'' as ``\bs hspace*\{-2cm\}'', \\ \hspace*{-2cm} then it works. Adding the ``*'' character before \{ \} override the default setting of the \LaTeX. So, when you use ``\bs vspace'' or ``\bs hspace'' but don't get the effect you wanted, try adding a ``*''. \vspace{0.25in} If you want to align the text to the center of the page, you can use ``\bs begin\{center\}'' and ``\bs end\{center\}''.\\ \vspace{-2ex} \begin{center} These sentences are aligned to the center of the page.\\ All other \LaTeX\ commands\\ works as described before.\\ \hspace*{4cm}\bs hspace*\{4cm\} works as well (on this line). \end{center} \vspace{5pt} % You can also separate the words to left/right by using ``\bs hspace\{\bs fill\}'', or simply ``\bs hfill''.\\ This line is separated to left and \hfill right by using one ``\bs hfill''.\\ This line is separated into \hfill three sections \hfill using two ``\bs hfill''s.\\ You can use as many \hfill ``\bs hfill'' \hfill as \hfill you \hfill want in a single line.\\ There is also ``\bs vfill'' for vertical separation, but I have never used it. \vfill \noindent This last line is written at the bottom of page by using ``\bs vfill'' in front of it. \newpage \subsection{Basics: Cross-referencing}\label{crossref} One reason why you want to use the \LaTeX\ is its automated ``cross-reference'' feature, as mentioned in \secref{intro}. In \LaTeX, you can label sections, figures, tables, citations, etc.\ by using ``\texttt{\bs label\{ \}}'' command. Within the \{ \}, write a unique name of each section, figure, or equation that you want to cross-reference later, i.e, this section is labeled as ``crossref'' and the \figref{fig1} is labeled as ``fig1''. For example, this section heading in \thistex\ is written as:\\ \texttt{\bs subsection\{Basics:\ Cross-referencing\}\bs label\{crossref\}} \vsk Once a label is created, you can reference it using a ``\texttt{\bs ref}'' command. Since labeling are automatically separated and numbered by \LaTeX\ into different categories (figures, sections, tables, etc.), if I type ``\bs ref\{fig1\}'', it will appear as ``\ref{fig1}'', and if I type ``\bs ref\{crossref\}'', it will appear as ``\ref{crossref}'' in the text. Therefore by adding ``Figure'' or ``Section'' before using ``\bs ref'' command, will create the appropriate cross-reference as: ``Section \ref{crossref}'' \vsk An advantage of \LaTeX\ is that since all the references are automatically managed, you do not have to fix the reference number when adding or removing any ``\bs label'' in the tex file. For example, even though you suddenly have to add a new figure in Chapter~1 of your dissertation (say already have XX figures), you do not have to go and fix the other figure numbers. \LaTeX\ will automatically adjust \emph{all} the numbering instantly. \vsk To simplify the cross-referencing, you can always make a macro for figures, tables, and sections. See \secref{macros} and the beginning of \thistex\ file for more details. \newpage \subsection{Basics: Tables} This section describes how a basic tables can be created. The first and the simplest is with \texttt{tabular}. The \texttt{tabular} environment has the form: \vspace{3mm} \noindent\bs begin\{tabular\}\{\emph{format}\}\\ . . . \\ \bs end\{tabular\} where, you specify how many columns and whether they are left justified (\texttt{l}), centered (\texttt{c}), or right justified (\texttt{r}) in the \emph{format}. \begin{center} Example 1 \end{center} %\vspace{3mm} \noindent \bs begin\{tabular\}\{lcr\}\\ Friday Meetings \& Time \& Room \bs \bs\\ \bs hline\\ Astro Journal Club \& 12:15 pm \& PSF 226 \bs \bs\\ AstroComp Tool Seminar \& 1:30 pm \& PSF 226 \bs \bs\\ Another meeting \& 3:00 pm \& PSF 566 \bs \bs\\ Yet another meeting? \& 4:00 pm \& PSF 226 \bs \bs\\ Happy Hour!! \& 5:00 pm \& Four Peaks \bs \bs\\ \bs hline\\ \bs end\{tabular\} \vspace{3mm} %\noindent \begin{tabular}{lcr} Friday Meetings & Time & Room \\ \hline Astro Journal Club & 12:15 pm & PSF 226 \\ AstroComp Tool Seminar & 1:30 pm & PSF 226 \\ Another meeting & 3:00 pm & PSF 566 \\ Yet another meeting? & 4:00 pm & PSF 226 \\ Happy Hour!! & 5:00 pm & Four Peaks \\ \hline \end{tabular} \vspace{6mm} \noindent Within the table entries,\\ $\bullet$ The entries across each row are separated by \texttt{\&}.\\ $\bullet$ A horizontal line is created with ``\texttt{\bs hline}''.\\ $\bullet$ If you want a vertical line, simply add ``\texttt{|}'' in the \emph{format}, (i.e., \texttt{\{l|cr\}} draws vertical line between ``Friday Meetings'' and ``Time'' columns. ) \newpage If you want a heading for a multicolumn, you can use ``\texttt{\bs multicolumn\{X\}}'' for a heading across 'X' columns. \begin{center} Example 2 \end{center} \noindent \bs begin\{tabular\}\{\texttt{|}l\texttt{|}\texttt{|}c\texttt{|}c\texttt{|}\}\\ \bs hline\\ \& \bs multicolumn\{2\}\{c\texttt{|}\}\{Time\} \bs\bs\\ \bs cline\{2-3\}\\ Friday Meetings \& Feb 26 \& Mar 5 \bs \bs\\ \bs hline \bs hline\\ Astro Journal Club \& 12:15 pm \& 12:15 pm \bs \bs\\ AstroComp Tool Seminar \& 1:30 pm \& 1:30 pm \bs \bs\\ Another meeting \& 3:00 pm \& 3:30 pm \bs \bs\\ Yet another meeting? \& 4:00 pm \& Canceled \bs \bs\\ Happy Hour!! \& 5:00 pm \& 5:00 pm \bs \bs\\ \bs hline\\ \bs end\{tabular\} \vspace{3mm} %\noindent \begin{tabular}{|l||c|c|} \hline & \multicolumn{2}{c|}{Time}\\ \cline{2-3} Friday Meetings & Feb 26 & Mar 5 \\ \hline\hline Astro Journal Club & 12:15 pm & 12:15 pm \\ AstroComp Tool Seminar & 1:30 pm & 1:30 pm \\ Another meeting & 3:00 pm & Canceled \\ Yet another meeting? & 4:00 pm & 3:30 pm \\ Happy Hour!! & 5:00 pm & 5:00 pm \\ \hline \end{tabular} \vspace{3mm} \noindent $\diamond$ \texttt{\bs multicolumn} takes three arguments, (1) the number of columns, (2) format of the column, and (3) the content (text).\\ $\diamond$ \texttt{\bs cline\{2-3\}} draws the horizontal line for columns 2 and 3 (underneath ``Time'').\\ \newpage Another environment to make a table, and probably with more useful than \texttt{tabular}, is \texttt{table}, which is added outside the \texttt{tabular} environment. \noindent Adding the following before and after the previous page's \texttt{tabular} environment changes the look of the table as below. \vspace{3mm}\noindent \emph{before \texttt{tabular}}: \vspace{1mm} \noindent \bs begin\{table\}[h]\\ \bs begin\{center\}\\ \bs footnotesize\\ \bs caption\{Meeting Times For Friday Meetings\}\bs label\{table1\} \vspace{3mm} \noindent \emph{after \texttt{tabular}}: \vspace{1mm} \noindent \bs end\{center\}\\ \bs end\{table\} \begin{table}[h] \begin{center} \footnotesize \caption{Scheduled Times For Friday Meetings}\label{table1} \begin{tabular}{|l||c|c|} \hline & \multicolumn{2}{c|}{Time}\\ \cline{2-3} Friday Meetings & Feb 26 & Mar 5 \\ \hline\hline Astro Journal Club & 12:15 pm & 12:15 pm \\ AstroComp Tool Seminar & 1:30 pm & 1:30 pm \\ Another meeting & 3:00 pm & Canceled \\ Yet another meeting? & 4:00 pm & 3:30 pm \\ Happy Hour!! & 5:00 pm & 5:00 pm \\ \hline \end{tabular} \end{center} \end{table} \noindent $\bullet$ The \texttt{[h]} at the very beginning a option for the placement of the table within the page, that puts the table \emph{here}, or where it is typed in the \thistex\ file. \texttt{[t]} puts the table at the top, and \texttt{[b]} puts it at the bottom of the page. \\ However, the factors influencing \LaTeX\ table locations are so many, that sometimes tables appear other than specified location. In that case, adding ``\textbf{!}'' can/may overwrite the \LaTeX\ preference (i.e., use as \texttt{[!b]}).\\ % $\bullet$ The \texttt{\bs footnotesize} changes the font size of the table itself to a smaller fonts.\\ % $\bullet$ The \texttt{\bs caption} can be moved to after the \texttt{tabular} environment if you want the caption of the table to appear \emph{below} the table itself.\\ % $\bullet$ The \texttt{\bs label\{table1\}} will be used in the main text when cross-referencing the table as ``\tabref{table1}''. (See following sections for details about cross-referencing.) \vsk Depending on the classfile you are using (e.g., for some pre-defined class file for journals), you can also use the ``\texttt{longtable}'' and/or ``\texttt{deluxtable}'' packages/environment to create tables. These have some additional features that you can use, but still follow the same rules to create a table. \subsection{Verbatim} Verbatim is an extremely useful environment for displaying the ``raw'' \LaTeX, and computer codes. All the \LaTeX\ significance (i.e., the use of special characters ``\textbf{\bs\&\$\%\~\_\{\}\#\^}'') is ignored within this environment, and whatever you type will displayed directly. %\textbf{Even I didn't know about this. And using this would have % simplified the earlier section a lot!!!} Anyway... \vsk \noindent If I write as following: %\vsk \noindent \bs begin\{verbatim\} \vspace{-3mm} \begin{verbatim} %% This '%' sign is usually used to comment out words following %% in a same line. $ % & ^ y = a*x + b + cos(theta) \end{verbatim} \vspace{-3mm} \bs end\{verbatim\} \vsk \noindent It will appear as: \begin{verbatim} %% This '%' sign is usually used to comment out words following %% in a same line. $ % & ^ y = a*x + b + cos(theta) \end{verbatim} \vsk \noindent This is useful when one have to show a (portion of) programming code, which is usually filled with symbols and characters that \LaTeX\ treat as ``special'' characters. \newpage \section{Typesetting Mathematics}\label{math} \subsection{Basics} One of the strong-point of \LaTeX\ is mathematical typesetting. There are several ways to write this in \LaTeX. Simplest way is to put in between '\texttt{\$}' symbols, which is usually used in a sentence. For example, \texttt{\$x\$} and \texttt{\$y=2.5x\$} will appear in \textit{italic-like} fonts as, '$x$' and '$y=2.5x$'. \vsk To display equations (unnumbered) in a separate line, use the delimiters \texttt{\bs [} and \texttt{]\bs}. \[ y=\sin(x) \] where, ``sin'' is typed as \texttt{\$\bs sin\$} and NOT as \texttt{\$sin\$}. Mathematical functions such as ``sin'', ``log'', and ``cosh'' are, by convention, typeset in standard roman type. Or, if you need a certain situation that math fonts to be in roman type, then you can use \texttt{\bs mathrm}. For example, %\vspace{-5mm} \begin{verbatim} $\mathrm{y = 2.5x}$ \end{verbatim} appears as: $\mathrm{y = 2.5x}$. \vsk Other equation environments that you can use to write numbered equations are:\\ \textbf{1.} \texttt{\bs begin\{equation\}}...\texttt{\bs end\{equation\}} This only gives a single line equation and a simple number. \begin{equation}\label{eq1} A_N = \sum_{i=1}^N a_i\\ \end{equation} \noindent \textbf{2.} \texttt{\bs begin\{eqnarray\}}...\texttt{\bs end\{eqnarray\}} This let you format sets of equations. \begin{eqnarray}\label{eq2} \int_{x=0}^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2}\\ \int_{x=0}^\infty xe^{-x^2} dx = \frac{1}{2} %% \lim_{n\rightarrow\infty}(1+x/n)^n=e^x \end{eqnarray} The \texttt{eqnarray} can also be used to align equations, or in other words, it can be used as a table (in math mode) with precisely three columns within a row. (Separated with \texttt{\$}.) \begin{eqnarray}\label{eq4} y & = & x^4+4 \nonumber\\ & = & (x^2+2)^2-4x^2 \nonumber\\ & \le & (x^2+2)^2 \end{eqnarray} where, if you don't want any number at the end of each line, you have to add ``\texttt{\bs nonumber}'' before the ``\bs\bs''. Or if you don't want your equations to be numbered at all, you can simply use \texttt{\bs begin\{eqnarray*\}}...\texttt{\bs end\{eqnarray*\}}, with ``\texttt{*}'' marks at added. \subsection{If you need more than basics} \subsubsection{Fonts, Hats, and Underlining} In math mode, you can type equations, but you can also use other fonts, and markings (hats, underlining, etc.). One of the most important, or frequently used commands are for spacing. For example, if you want to add a space between $a$ and $b$ in a single line within math environment, simply adding a space (' ') does not change the spacing between $a$ and $b$.\\ $ab$ -- typed as '\texttt{\$ab\$}'\\ $a b$ -- typed as '\texttt{\$a b\$}'\\ $a\!b$ -- typed as '\texttt{\$a\bs!b\$}' = Negative thin space\\ $a\,b$ -- typed as '\texttt{\$a\bs,b\$}' = Thin space\\ $a\:b$ -- typed as '\texttt{\$a\bs:b\$}' = Medium space\\ $a\;b$ -- typed as '\texttt{\$a\bs;b\$}' = Thick space\\ These become important in situations when you have, e.g., double integrals: \vspace{-3mm} \begin{itemize} \vspace{-3mm} \item[1)] without space:\\ $\int \int f(x,y) dx dy$ = \$\bs int \bs int f(x,y) dx dy\$ \vspace{-3mm} \item[2)] with spaces:\\ $\int \!\! \int f(x,y)\, dx \, dy$ = \$\bs int \bs !\bs ! \bs int f(x,y)\bs, dx \bs, dy\$ \end{itemize} \noindent You can also use markings such as:\\ $\hat a$ = \$\bs hat a\$\\ $\dot x$ = \$\bs dot x\$\\ %$\ddot y$ = \$\bs ddot y\$\\ $\widehat{\alpha + \beta}$ = \$\bs widehat\{\bs alpha + \bs beta\}\$\\ $\underline{\Gamma - \Omega}$ = \$\bs underline\{\bs Gamma - \bs Omega\}\$\\ and, \\ $\overline{\dot x + v_0}$ = \$\bs overline\{\bs dot x + v\_0\}\$\\ \subsubsection{Braces} You saw curly braces \{ and \} have a special meaning in \LaTeX. It is same in equations. So, if you physically want \{ and \} to be typed, then you have to use ``\bs\{`` and ``\bs\}''. However, \{ \},as well as '( )' and '[ ]', have a fixed height of a single line in math mode if typed directly, and it \emph{won't} adjust its height even if \bs frac command is used to write some equations. \[ p(x) = 4 \times [2x + (\frac{3x}{5} + \frac{1}{\{x-1\}})] \] To match the height of braces, you have to use \texttt{'\bs left\{' ... '\bs right\}', '\bs left(' ... '\bs right)', and '\bs left[' ... '\bs right]'}. \[ p(x) = 4 \times \left[2x + \left(\frac{3x}{5} + \frac{1}{\left\{x-1\right\}}\right)\right] \] \subsubsection{Arrays and Matrices} Arrays and Matrices can be written as well \emph{within mathematical environment}. The format used in \texttt{array} environment is similar to that of tables. See the \thistex\ for examples how the followings are written. 1.\ Simple array: \[ \begin{array}{llcr} a & 0 & \sin (2x) & c\\ a + b & 16 & \cos x & b + c \end{array} \] 2.\ Matrix: \begin{equation} A = \left[ \begin{array}{ccc} 1 & 1 & 2\\ x & y & z\\ (2\tan y) & xy & x^3\\ \end{array} \right] \ne B \end{equation} 3.\ Some useful way of using \texttt{array}: \begin{eqnarray} \delta_{ij} = \left\{ \begin{array}{ll} 1 & \mbox{when $i=j$,} \\ 0 & \mbox{when $i\ne j$.} \end{array} \right. \end{eqnarray} In \thistex, for the last example, the ``\texttt{\bs right.}'', which is called ``dummy'' right brace, is required to match the ``\texttt{\bs left\{}'' we used at the beginning of the array. Otherwise, \LaTeX\ would complain that \texttt{\bs left} did not have a matching partner. Also, the ``\texttt{\bs mbox\{...\}}'' are used to temporarily leave mathematical typesetting mode. %%%%%%%%%%%%%%%%%%%%%%%% FIGURES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \newpage \section{Including Figures} In \LaTeX, \emph{if you are using 'latex' and 'dvips' to create a PostScript document}, you can only input PostScript (***.ps) files, or Encapsulated PostScript (***.eps) files only. On the other hand, \emph{if you are using 'pdflatex', TeXShop, or other PDF-oriented compiler to create the final document}, you can only use PDF, PNG, and JPEG (and GIF?) images. \\ {\red \textbf{Here, I explain the case for creating a PostScript document with PostScript (ps) files.}} \vsk To display a pictures, you have to use a command such as ``\texttt{\bs includegrahpics}'' or ``\texttt{\bs psfig}''. To use these commands, the \texttt{graphicx} or \texttt{psfig} package has to be loaded at the beginning of \thistex\ document, between the lines \texttt{\bs documentclass[...]\{...\}} and \texttt{\bs begin\{document\}}. \begin{verbatim} \documentclass[12pt]{article} \usepackage{...} \usepackage{graphicx} \usepackage{psfig} \newcommand{\figref}[1]{Figure~\ref{#1}} \begin{document} \end{verbatim} The following example will load the figure as in the following page: \begin{verbatim} \begin{figure}[h] \centerline{ \includegraphics[height=0.8\textheight]{tmp.ps} } \caption[Figure Title Comes Here]{\footnotesize One of the best introductory level \LaTeX\ textbook, ``learning \LaTeX'' by David F.\ Griffiths and Desmond J.\ Higham. Published by saim (ISBN: 0-89871-383-3). Sold at Amazon.com for \$26.39 (new). }\label{fig2} \end{figure} \end{verbatim} As in tables, options ``[!/h/t/b/p]'' can be used to specify the location of the figure to put in, and adding ``\texttt{*}'' (as \texttt{\{figure*\}}) overwrite the basic \LaTeX\ settings. \begin{figure}[h] \centerline{ \includegraphics[height=0.45\textheight]{learningLaTeX_2.ps} } \caption[Figure Title Comes Here]{\footnotesize One of the best introductory level \LaTeX\ textbook, ``learning \LaTeX'' by David F.\ Griffiths and Desmond J.\ Higham. Published by saim (ISBN: 0-89871-383-3). Sold at Amazon.com for \$26.39 (new). }\label{fig2} \end{figure} To convert the format of images into a PostScript (***.ps), I usually use ``gimp (\texttt{http://www.gimp.org/})'', but other image processing tools/software, should be able to convert the image format as well. \vsk If the \LaTeX\ is having trouble when creating file with a converted PostScript file, try to modify the PostScript file as following. The {\red red} are originally in the converted file, and the {\blue blue} are how you have to change. \begin{itemize} \item at the very first line of the ``***.ps'' file:\\ {\red \%!PS-Adobe-3.0}\\ {\blue \%!PS-Adobe-3.0 EPSF-3.0} \item For lines with ``Page/Pages'':\\ {\red \%\%Page(s): 1}\\ {\blue \%*\%Page(s): 1}\\ \end{itemize} \newpage \section{Making Bibliography}\label{bibliography} A bibliography can be created with the \texttt{thebibliography} environment. As in the list-making environment, you start a new input ``\texttt{\bs bibitem}'', but then you can refer/cite the item anywhere in the document with ``\texttt{\bs cite}'', ``\texttt{\bs citet}'' or ``\texttt{\bs citep}'' commands (the latter two require more specific 'class-file' and/or 'style-file'). For example, to create a reference list, you can simply type: \begin{verbatim} \begin{thebibliography}{99} \bibitem{short_name} Authours, Title, etc. \bibitem{griffith97} Griffiths, D.F., \& Higham, D.J., \emph{learning \LaTeX}, siam, Philadelphia, 1997. \end{thebibliography} \end{verbatim} and this will create the following: \vspace{-5mm} \begin{thebibliography}{99} \bibitem{short_name} Authours, Title, etc. \bibitem{griffith97} Griffiths, D.F., \& Higham, D.J., \emph{learning \LaTeX}, siam, Philadelphia, 1997. \end{thebibliography} This will appear as \cite{griffith97}, when ``\texttt{\bs cite\{griffith97\}}'' is typed in a sentence. Or, if you rather want name/short notation to be shown, you can add an option as: \begin{verbatim} \bibitem[GH97]{griffith97} Griffiths, D.F., \& Higham, D.J., \emph{learning \LaTeX}, siam, Philadelphia, 1997. \end{verbatim} which is cited as \cite{griffith97}, and appears in the ``References'' as: \begin{thebibliography}{99} \bibitem[GH97]{griffith97} Griffiths, D.F., \& Higham, D.J., \emph{learning \LaTeX}, siam, Philadelphia, 1997. \end{thebibliography} \newpage \section{Advanced Use of \LaTeX}\label{advanced} \subsection{Macros}\label{macros} In \LaTeX, you can define frequently used phrases and commands with shorter notation using ``\texttt{\bs newcommand}'' Best if you all write together at the beginning (\emph{before} \texttt{\bs begin\{document\}}), but you can use it anywhere in the tex file. \begin{verbatim} \newcommand{cmd}[args]{def}% \end{verbatim} \noindent \texttt{cmd} --- A command name beginning with a \bs. For \texttt{\bs newcommand}, it must not be already defined, and must not begin with \texttt{\bs end}. \noindent \texttt{args} --- An integer from 1 to 9 denoting the number of arguments of the command being defined. The default is for the command to have no arguments. \noindent \texttt{def} --- The text to be substituded for every occurrence of \texttt{cmd}. A parameter of the form '\texttt{\#n}' in \texttt{cmd} is replaced by the text of the n$^{th}$ argument when this substitution takes place. \noindent \texttt{\%} --- Add this to the end to make sure the defined macro ends here. If you forget the closing '\}', it can cause some errors. \vsk \noindent Examples: \begin{verbatim} \newcommand{\thistex}{\texttt{basic\_latex.tex}}% \newcommand{\figref}[1]{Figure~\ref{#1}}% \newcommand{\figreftwo}[2]{Figures~\ref{#1} and \ref{#2}}% \newcommand{\HII}{\mbox{H\,\textsc{ii}}}% \end{verbatim} When you use, simply type ``\bs thistex'', ``\bs figref\{fig1\}'', and ``\bs figreftwo\{fig1\}\{fig3\}, etc. When a word/phrase is defined with a \texttt{\bs newcommand}, you have to manually add an extra space \emph{after} the macro by ending it with ``\bs''. For example, if you don't add ``\bs'', simply typing ``\texttt{\bs HII region}'' will appear as ``\HII region''. But if you type ``\texttt{\bs HII\bs\ region}'', then it will appear as ``\HII\ region''. \newpage \subsection{Adjusting the Numbering of Figures and Tables} When you have one figure that spans a multiple pages, or use different format of figures/tables in a single document, the numbering can be shifted. In such a situation, you can use ``\texttt{\bs addtocounter}'' command to adjust the numbering. \begin{figure}[!hp] \centerline{ \includegraphics[height=4cm]{mauna-kea.ps} \includegraphics[height=4cm]{mauna-kea-summit.ps} } \caption[Pictures of Mauna Kea]{\footnotesize Second image in the document \emph{without} using \texttt{addtocounter}. Tow images are scaled with '\emph{height}' (rather than 'width') for better size-matching.}\label{fig3} \end{figure} \addtocounter{figure}{+2} \begin{figure}[!hp] \centerline{ \includegraphics[width=5.5cm]{geology-in-space.ps} } \caption[Geology in Space]{\footnotesize Third image in the document appearing as ``Figure 6'' (instead of Figure~4) by adding \texttt{\bs addtocounter\{figure\}\{+2\}} \emph{before} the \texttt{\bs begin\{figure\}} command. }\label{fig6} \end{figure} \newpage \subsection{Adjusting the Location of Figure Caption} \subsubsection{SCfigure} Sometimes, you might want to save space by moving a caption to a side of a figure, instead of writing it under the figure. In that case, you can use a command ``\texttt{SCfigure}''. You also need to load the ``sidecap'' package by adding a line ``\bs usepackage\{sidecap\} at the beginning of tex file. \begin{SCfigure}[][h!] \includegraphics[width=4cm]{mars} \caption{This figure caption is written on the right side of the figure by using ``SCfigure'' command. }\label{fig7} \end{SCfigure} %One thing is that the width of figure caption is set to the same %width as the figure. (Currently, I don't know if there is a way to %adjust this caption width.) %If you look at the \thistex\ file, %to fix the figure location (with ``h!''), it has to be written in the %\emph{second} ``[ ]''---with regular ``figure'', it is the first ``[ ]''. \subsubsection{wrapfigure} Another way of manually writing caption or main text around the figure is with ``\texttt{wrapfigure}''. As for the 'SCfigure', to use the ``wrapfigure'', \begin{wrapfigure}{r}{0.3\textwidth} \includegraphics[width=4cm]{earth.ps} \caption{\footnotesize Or, you can write caption here. \vspace{-15mm}} \end{wrapfigure} you have to load ``wrapfig'' package at the beginning of the tex file. This also allows you to save some space. The text written \emph{below} the ``\bs end{wrapfigure}'' will appear next to the figure, as in this case. \vspace{7mm} Figure 8: {\footnotesize You can write a figure caption here (on a side of a figure) \emph{manually}.} \vsk \vsk You can use this to manually add some figure caption (typed in blue above) as a part of main text. This will allow figure caption to take wider space than the image width (compare to ``SCfigure'' above). As well as you have a choice of putting your figure on the \emph{right} or \emph{left} of the wrapped text. The space above the figure and below the figure caption can be adjusted by '\bs vspace' command. \subsubsection{minipage} Another way to create a wrapped text or side caption is with ``\texttt{minipage}''. \vspace{5mm} \noindent \makebox[\textwidth]{ \makebox[0.3\textwidth]{ \begin{minipage}[b]{0.30\textwidth} \includegraphics[width=\textwidth]{hst_galaxy} \end{minipage} } \hfill \makebox[0.65\textwidth]{ \begin{minipage}[t]{0.65\textwidth} \vspace{-10mm} Figure 9: {\footnotesize Depending on the size of the image, you can adjust the size of left/right column widths.} \end{minipage} } } \vsk \textbf{IMPORTANT!!}: With this method (without using '\bs begin\{figure\}', the numbering of figures might change after this. Make sure to adjust the figure numbers with ``addtocounter\{figure\} on the following figure. \vsk This is also useful when writing the ``References'' section in two (or more) columns. Following is an example. \vsk \noindent \makebox[\textwidth]{ \makebox[0.50\textwidth]{ \begin{minipage}[t]{0.45\textwidth} \footnotesize {\bf\large{References:}} \\[-2pt] Abraham, R.G., et al.\ 1999, MNRAS\\ $\null\quad$308, 569\\ Anders, P., \& U. Fritze-von Alvensleben\\ $\null\quad$2003, A\&A, 401, 1063\\ \end{minipage} } \hfill \makebox[0.50\textwidth]{ \begin{minipage}[t]{0.45\textwidth} \footnotesize $\null\quad$\\ Heller, C.H., et al.\ 2007, ApJ, 657, L65\\ Jogee, S., et al.\ 2004, ApJ 615, L105\\ Sheth, K., et al.\ 2008, ApJ 675, 1141\\ Trumpler, R.\ J.\ 1930, PASP, 42, 214\\ \end{minipage} } } \newpage \subsection{Use of ``\bs input'' and ``\bs include'' Commands} Sometimes---especially if you are writing long documents such as your dissertation or a book---it is easier to write each chapter as a separate \LaTeX\ file, and then put all together at once using a master tex file. (i.e., I crated my dissertation (total 243 pages, but ``kaz\_thesis.tex'' is less than 100 lines) in this way.) \vsk\noindent \texttt{\bs input ***.tex} --- Simply insert another tex file into the position specified. \vsk\noindent \texttt{\bs include\{***\}} --- \emph{WITHOUT the ``.tex'' file extension}. This put the another tex file \emph{starting from a new page}. \vsk\noindent These are useful when you are including tables, references, chapters, etc. \subsection{Predefined (Journal) Style files and Class files} Some journals and organizations, require their original format in documents prepared with \LaTeX. If you are writing papers for astronomy journals (AJ/ApJ) you can use ``AASTeX''. If you are writing papers for Elsevier, they have their own class-files and style-files. And if you are writing one to Nature, the DO NOT accept LaTeX files, but \emph{they accept the PDF files created with} \LaTeX. \vsk For example, if you download ``AASTeX'' from:\\ \texttt{http://ucpjournals.uchicago.edu/AAS/AASTeX/}\\ The tar file (zip file) include:\\ $\bullet$ aastex.cls = class file, which format the paper,\\ $\bullet$ natbib.sty = bibliography style file,\\ and other associated files (README, support document, template tex file, etc.). \vsk For Elsevier, who publishes various journals with many different formats, you can download the specific class-file and style-file form:\\ \texttt{http://www.elsevier.com/wps/find/authorsview.authors/elsarticle} \vsk And for Nature, you can google it to find the class-files that are modified by different individuals. Since they are NOT OFFICIAL class-files, make sure the created PDF satisfies the Nature requirements. \subsection{ASU Dissertation with \LaTeX: 2007-2010 Format} \textbf{IMPORTANT!!}\\ Different printers have somehow slightly different margin set-ups. Make sure to adjust the margins to your printer before printing the final version of your thesis/dissertation. To obtain the necessary style files and class files, contact Kaz Tamura or recently graduated people. \textbf{These style files are modified to match the format of Astronomical Journal (and Astrophysical Journal) \emph{after} 2009 (IOP version of Journals).} \vsk\noindent For 2009/2010 format of dissertation, the necessary files are: \vspace{-3mm} \begin{itemize} \item \textbf{report4.cls} --- Enabled the use of ``\bs subsubsubsection'' (modified by Melissa Morris in 2009). \item \textbf{body\_only.sty} --- For printing main body of thesis. \item \textbf{toc\_only.sty} --- For pages \emph{before} the actual table of contents (i.e., title page, approval page, abstract, and acknowledgment). \item \textbf{toc\_p1.sty} --- \emph{ONLY} for page 1 of the ``Table of Contents''. \item \textbf{toc\_p2on.sty} --- For pages 2--X (second page on) of ``Table of Contents'', and for pages 2--X of ``List of Tables/Figures''. \item \textbf{toc\_tab\_fig\_p1.sty} --- \emph{ONLY} for page 1's of ``List of Tables/Figures'' \end{itemize} \noindent You also need: \vspace{-3mm} \begin{itemize} \item \textbf{longtable\_asu.sty} --- Table style file to match the table layout with Astronomical/Astrophysical Journal. Modified by Kaz Tamura. \end{itemize} \noindent The original style file is: \vspace{-3mm} \begin{itemize} \item \textbf{asthesis4.sty} --- Original Dissertation/Thesis format style-file originally created by John Jones in 1998, modified by various people (e.g., Kevin Healy, Melissa Morris, Nimish Hathi, and Kaz Tamura). \end{itemize} \newpage \noindent For example, the beginning of your thesis tex file should looks like:\\ \noindent \texttt{\bs documentclass[12pt]\{report4\}\\ \bs usepackage\{{\blue body\_only},natbib,amsmath,rotating,amssymb\}\\ \bs usepackage\{graphicx,epsfig,lscape,psfig\}\\ \bs usepackage\{longtable\_asu\}}\\ \noindent where, the ``\texttt{{\blue body\_only}}'' should be changed to another classfile based on which page(s) of thesis/dissertation you are preparing for. \vsk You can find the ASU thesis template (formatted for 2009--2010 Astronomical Journal style) at:\\ \texttt{http://www.public.asu.edu/~ktamura/}\\ under ``Presentations/Talks''. \end{document}