LaTeX useful Tips/Tricks

Sat 11 October 2008

In my previous post I discussed a "small" but, I would say "complet" template to start your document. If you want to include also movies in your pdf documents, then this post can help you. If you need a good program for bibliographic management check this post.

Below I will post a lot of tips, tricks and useful stuff which helps me when I am using LaTeX, for details check the documentation of coresponding package name, or Google .

Customize your header and footer

\pagestyle{fancy}
\lhead{}
% \chead{}
\rhead{\leftmark}
% \lfoot{}
% \cfoot{}
% \rfoot{}

More packages

\usepackage{latexsym} % use \Box, \Join
\usepackage{setspace}
\usepackage{subfigure} % include subfigures
\usepackage{amsmath} % equation
% table of contents, list of figures
\usepackage[titles,subfigure]{tocloft} 
\usepackage{lastpage} % total page count
\usepackage{makeidx} % create index

Old Makefile which I used, you can modify it for your needs

dvi: poster.tex
    latex poster.tex
bib: 
    bibtex poster
view:
    kdvi poster.dvi
ps:
    dvips poster.dvi -o poster.ps
pdf:
    ps2pdf poster.ps poster.pdf
mp:
    psnup -9 -l -d2 poster.ps multpage.ps
a4:
    psresize -H118.9cm -W91.4cm -pa4 poster.ps a4.ps
    ps2pdf a4.ps poster_a4.pdf
.PHONY: clean
clean:
    @echo Cleaning...
    $(RM) *.log *.aux *.dvi *.bbl *.blg *~
    @echo Cleaning... done

Indexes and Glossaries

% first include the makeidx command in the preamble
\usepackage{makeidx}
\makeindex

To index something, use the command:

\index{Index Entry}

When the document has been processed through LaTeX, it will create a .idx file. You will then need to run the .idx file through the makeindex program:

makeindex filename

No file extension for the name. The program will look for the .idx file and will output a .ind file. This file is used by the command:

\printindex

Glossaries simply use the commands:

\makeglossary (used in the preamble, like the \makeindex command)
\glossary (used for the particular entries, like the \index command)

Include/Rotate/Reflect images

\includegraphics{image.png}
\includegraphics[angle=45]{image.png}
\includegraphics*[viewport=30 30 120 120]{image.png}
\includegraphics[scale=0.25]{image.png}
\includegraphics[width=5in,height=1in]{image.png}
% no explicit size for image
\includegraphics[width=0.88\hsize]{image.png}
% horizontally reflect a image
\reflectbox{\includegraphics{myimage.png}}
% strange text behaviour
\scalebox{2}{\rotatebox{60}{\reflectbox{Check this text!}}}

Complet environment with two images left-right

\begin{figure}[htbp]
\centering
\includegraphics[width=0.8\hsize]{image}\  
\includegraphics[width=0.8\hsize]{image}
\caption{image caption}
\label{fig:mylabel}
\end{figure}


:::latex
\begin{figure*}[t]
\centerline{\includegraphics[width=0.8\textwidth]{figures/image}}
\caption{Caption title. {\it Caption text.}}
\label{fig:image}
\end{figure*}

Labeling sections in the document

\section{Introduction}
\label{sec:intro}
.....
% reference to section 
\ref{sec:intro}

Adding external files to the document

\section{Introduction}
\label{sec:intro}
\input{sections/intro}

Math

\[...\] % produces an unnumbered formula
\(...\)
$...$
\begin{math} ... \end{math}

Type properties

\bf % bold
\sf % sans serif
\sc % small caps
\tt % typewriter
\tiny
\normalsize
\large
\Large
\LARGE

Lists

\begin{enumerate}
   \item First item
   \item Second item
\end{enumerate}
%
\begin{itemize}
   \item First item
   \item Second item
\end{itemize}
%
\begin{description}
   \item[first] A definition for the first item.
   \item[second] A definition for the second item.
\end{description}

Columns

\begin{tabbing}
text \= some text \  
  \> text  \= text,
   \>       \> text; \  
  \> text  \> text. \  
endif 
\end{tabbing}
%
\begin{tabular}{|l|c|c|}
   \hline
   {Row 1,Col1} & {Row1,Col2} & {Row1,Col3} \  
  \hline
   {Row 2,Col1} & {Row2,Col2} & {Row2,Col3} \  
  \cline{2-3}
   {Row 3,Col1} & {Row3,Col2} & {Row3,Col3} \  
  \hline
\end{tabular}
%
\begin{tabular}{|l|c|c|}
   \hline
   {Row 1,Col1} & {Row1,Col2} & {Row1,Col3} \  
  \hline
   {Row 2,Col1} & \multicolumn{2}{c}{Row2,Col2-3} \  
  \cline{2-3}
   {Row 3,Col1} & {Row3,Col2} & {Row3,Col3} \  
  \hline
\end{tabular}

Tables

{\protect
   \begin{table}[t]
      % Table body
      \caption{Caption title. {\it The caption text.}}
      \label{tab:schema}
   \end{table}
}
%
{\protect
   \begin{table}[t]
      \centering
      \footnotesize
      \begin{tabular}{|l|c|c|}
         \hline
         {Row 1,Col1} & {Row1,Col2} & {Row1,Col3} \  
        \hline
         {Row 2,Col1} & {Row2,Col2} & {Row2,Col3} \  
        \cline{2-3}
         {Row 3,Col1} & {Row3,Col2} & {Row3,Col3} \  
        \hline
      \end{tabular}
      \caption{Caption title. {\it The caption text.}}
      \label{tab:schema}
   \end{table}
}

References: