Archive

Archive for April 19, 2010

Reducing paragraph gap between items in latex

In order to remove the paragraph gap between two bullets or items in latex put the following in your document class.  First one removes gap between the numbered item and second one removes gap between the unnumbered items.

%%%%%       unnumbered item       %%%%%

\newenvironment{enumerate*}

{\begin{enumerate}%

\setlength{\itemsep}{0pt}%

\setlength{\parskip}{0pt}}%

{\end{enumerate}}

%%%%%          for unnumbered item       %%%%%

\newenvironment{itemize*}%

{\begin{itemize}%

\setlength{\itemsep}{0pt}%

\setlength{\parskip}{0pt}}%

{\end{itemize}}

You can define your items using the following way:

\begin{itemize*}

\item

\item

\end{itemize*}

Some useful tips for Latex

To remove the hyphenation from the line break use the following in your document class:

\hyphenpenalty=5000

\tolerance=1000

To add urls in your document use the url package and include this in your document to use it:

\usepackage{url}

And use  the following command to add URLs:

\url { your url}

Referring to a section, figure, subsection or table you can use  the following commands:

~\ref{your referring label}

And to refer a listing label use only \ref instead of ~\ref.

To generate a quotation in latex use this “ for left quote and use this for right quote.

For special character å use \r{a}, for ä use \”{a} and for ö use \”{o}.

Listing in Latex

In order to include code, algorithm, pseudo-code listing is very useful package. To include listing package, include this in your document class.

\usepackage{listings}

The following tag shows how you can place your code or algorithm in latex .

\begin{lstlisting}[float = h, caption= Title, label=label, belowcaptionskip=0.4cm]

Place your code or algorithm here.

\end{lstlisting}

You can even include your source code directly to your documents. For example:

\lstinputlisting{main.java}

To add the “List of Listings” in your documents use the following in your main.tex file.

\lstlistoflistings

I have got a style for listing somewhere from the internet as shown in  figure below:

To use the style add this in your document class:

\usepackage{listings}

\usepackage{courier}

\lstset{

basicstyle=\footnotesize\ttfamily, % Standardschrift

%numbers=left,               % Ort der Zeilennummern

numberstyle=\tiny,          % Stil der Zeilennummern

%stepnumber=2,               % Abstand zwischen den Zeilennummern

numbersep=5pt,              % Abstand der Nummern zum Text

tabsize=2,                  % Groesse von Tabs

extendedchars=true,         %

breaklines=true,            % Zeilen werden Umgebrochen

keywordstyle=\color{red},

frame=b,

%        keywordstyle=[1]\textbf,    % Stil der Keywords

%        keywordstyle=[2]\textbf,    %

%        keywordstyle=[3]\textbf,    %

%        keywordstyle=[4]\textbf,   \sqrt{\sqrt{}} %

stringstyle=\color{white}\ttfamily, % Farbe der String

showspaces=false,           % Leerzeichen anzeigen ?

showtabs=false,             % Tabs anzeigen ?

xleftmargin=17pt,

framexleftmargin=17pt,

framexrightmargin=5pt,

framexbottommargin=4pt,

%backgroundcolor=\color{lightgray},

showstringspaces=false      % Leerzeichen in Strings anzeigen ?

}

Subfigures in Latex

It took me so long to identify how to include subfigures. I have used the subfig package for this. Include the following in your document class to use subfigures.

\usepackage{subfig}

To define subfigures use the following steps to configure it.

%%% %%             Starts of a table                      %%% %%

\begin{figure}[h]

%%% %%           Center alignment                       %%% %%

\centering

%%% %%           starting first subfigure and a line break after the first figure. Starts with \subfloat tag  and command shown below                         %%% %%

\subfloat[Title] {{\label{subfig:lable_name}}\includegraphics[width=0.6\textwidth]{pic location}

} \linebreak

%%% %%           starting second subfigure and a line break           %%% %%

\subfloat[Title] {{\label{subfig:lable_name}}\includegraphics[width=0.6\textwidth]{pic location}

} \linebreak

}\linebreak

\subfloat[Title] {{\label{subfig:lable_name}}\includegraphics[width=0.6\textwidth]{pic location}

} \linebreak

%%% %%          Caption of all the images     %%%%%

\caption{(a)Title 1; (b) Title 2; and (c) Title 3}

%%% %%         End of Figure tag    %%%%%

\end{figure}

Image below shows an example of subfigures in latex:

Categories: Latex Tags: , ,

Decimal point alignment in Latex

Decimal point alignment in Latex can be done in two different ways. But I prefer using dcolumn package because you will have the advantage of creating your own column type.

Include the package dcolumn and create a new column using the following command (you can add this in your document class).

\usepackage{dcolumn}

\newcolumntype{.}{D{.}{.}{-1}}

For defining table and heading you can use multicolumn as shown below:

\begin{tabular}{| c | . | . |}

\textbf{header 1} & \multicolumn{1} {|c|}{heading 2 } &  \multicolumn{1}{|c|} {Heading 3} \\

1 & 2563.05 & 2095.22 \\

…. (more data)

\end tabular

The image below illustrates the decimal point alignment in latex.

Follow

Get every new post delivered to your Inbox.