Writing your research paper in Latex using texmaker 3.0.4 (Part 2)

This is the second part of my previous post on the same topic Writing your research paper in Latex using texmaker 3.0.4 : Some useful commands and tips. So here are the new tid-bits:

1. Sort Citations by Reference Number

If you are happen to be using a bib style other than ieeetr and need to sort citations then use the following in your premble –

\usepackage[numbers,sort]{natbib}

or

\usepackage[numbers,sort&compress]{natbib}

The latter would format the list as [1–3] while the former gives [1, 2, 3]

2. BibTeX Style Examples

If you are confused about which bibtex style your publisher uses then you can search this style example archive.

3. Aligning on specific character for multiline equations with one equation number

Use the split environment with only one ampersand at the alignment point, which would be the equals sign for your case. So, for instance, your code would be:

\usepackage{amsmath}
\begin{equation}
   \begin{split}
   A + B &= C + D \\
   &= E + F  \\
   &= 3
   \end{split}
\end{equation}

So here the equation will align around the ‘=’ sign. And ‘\\’ splits the equations in separate lines.

4. Remove colon from table and figure name, making bold
The caption package provides a lot of functionality and I would recommend to use it. You get Figure x.x bold with

\usepackage[labelfont=bf]{caption}

when you load the package.
Use the caption package with the labelsep=space option to remove colon.

\usepackage[labelsep=space]{caption}

5. How to break a long equation/Group equations under a single equation number

Use split environment provided by amsmath package.

\begin{equation}
\begin{split}
F = \{F_{x} \in  F_{c} &: (|S| > |C|) \\
 &\quad \cap (\text{minPixels}  < |S| < \text{maxPixels}) \\
 &\quad \cap (|S_{\text{conected}}| > |S| - \epsilon) \}
\end{split}
\end{equation}

6. Making a wide figure or table in a two-column document

Use the starred version * of the figure or table environment. This will usually flush the figure (or table) to the top of the following page, so there is not much control on placement. For table* and figure*, the only available options are t (top of next page) or p (end of document). b and h have been disabled on purpose, there is probably a strong typographical reason behind it.

Note that the table may appear one the next page instead of the current one. If you really need to control on what page the table is, you may have to move the table definition up in the source code.

Figure* Example:

\documentclass[twocolumn]{article}
\usepackage[showframe]{geometry}% http://ctan.org/pkg/geometry
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\begin{document}
\lipsum[1-2]
\begin{figure*}
  \includegraphics[width=\textwidth,height=4cm]{tiger}
  \caption{This is a tiger.}
\end{figure*}
\lipsum[3-10]
\end{document}

Table* example:

\documentclass[twocolumn]{article}
\usepackage{lipsum}
\begin{document}
\lipsum[1-10] % To create a random first page
\lipsum[1-3]
[Location of the table in source code]
\begin{table*}[t]
  \centering
  \begin{tabular}{lcr}
    1 & 2 & 3 \\
    4 & 5 & 6 \\
    7 & 8 & 9
  \end{tabular}
  \caption{Blabla}
  \label{tab:1}
\end{table*}
\lipsum[1-6]
\end{document}

7. Labels and Cross-referencing

This is very useful. In LaTeX you can easily reference almost anything that is numbered (sections, figures, formulas), and LaTeX will take care of numbering, updating it whenever necessary. Go to the following link to know how its done.

Labels_and_Cross-referencing

Writing your research paper in Latex using texmaker 3.0.4 : Some useful commands and tips

1. How to convert from tex to PDF
To PDF from tex select PDFLatex from Quick Build, (the default option will take a long time or hang during building process)

2. Bibtex problem – Question mark instead of number for reference

To update you bibtex citations, select BibTex from Quick Build and compile, then select PDFLatex and compile twice to update the citation numbers in the PDF. Rebuilding it a few times replace the .aux and .bbl files that were made when you used before.

Common citation mistake , putting spaces between comma seprated bibtex keys:

\cite{zhao2003face,samal1992automatic,yang2002detecting}

Don’t put spaces before the keys!

3. How to center cell contents of a LaTeX table whose columns have fixed widths?

Use

 \usepackage{array} 

in the preamble
them this:

\begin{tabular}{| >{\centering\arraybackslash}p{.5cm} | >{\centering\arraybackslash}p{8cm} |}

note that “m” for fixed with column is provided by the array package, and will give you vertical centering (if you don’t want this just use “p”)

4. Latex command reference

To find the latex command for different symbols click here and here.

5. Big Parenthesis in an Equation

replace ( with \left( and ) with \right), which automatically expand to fit the material between them. Note that every \left… requires a \right… (but the type of bracket may be different, i.e. \left(…\right] also works).

6. In-line equations

There are three essentially equivalent ways to code in LaTeX the same anti-derivative formula from calculus as an in-line equation. In the first case, mathematics mode is delimited by dollar signs.

This is an in-line $\int \frac{d\theta}{1+\theta^2} =
\tan^{-1}\theta+C$ equation.

In the next case, mathematics mode is delimited by the \( and \) pair.

This is an in-line \(\int\frac{d\theta} {1+\theta^2}= 
\tan^{-1} \theta+C\) equation. 

In the third case, mathematics environment is delimited by the \begin{math} and \end{math} pair.

This is an in-line \begin{math}\int\frac 
{d\theta}{1+\theta^2} = \tan^{-1} 
\theta+ C\end{math} equation. 

The advantage of using a dollar sign to delimit mathematics mode is that it is easy to type. On the other hand, using different opening and closing delimiters facilitates error detection and correction.

7. Scale image to page width

Use \textwidth for the width of the text block, and \paperwidth if you want to fit it into the paper width. You could also use \linewidth if you want to fit the image within the line width, which may vary depending on the environment you’re in (for example, within a list like enumerate).

\begin{figure}[!htbp]
\label{fig:1}
\centering
\includegraphics[width=\textwidth]{sample-faces.png}
\caption{Sample images from (a) FERET, (b) Indian and (c) in-house database}
\end{figure}

8. Quotation marks

use two ‘ signs instead of one ” sign, like this “quoted”.

9. Tables: How to span over variable number of cells

Use multicolumn. Example –

\begin{table}[!htbp]
% table caption is above the table
\caption{The recognition accuracy of different orientation featured Gabor phase representations for 200 subjects.}
\label{tab:1}       % Give a unique label
% For LaTeX tables use
\begin{tabular}{|>{\centering\arraybackslash}p{.25cm}|>{\centering\arraybackslash}p{8.25cm}|>{\centering\arraybackslash}p{1.5cm}|>{\centering\arraybackslash}p{.5cm}|>{\centering\arraybackslash}p{.5cm}|>{\centering\arraybackslash}p{.5cm}|}
\hline
No. & Description & Complexity & \multicolumn{3}{|c|}{Recognition Accuracy (\%)}  \\
\hline
...

10. Squeezing space with LaTeX
Make your text block as big as pos­si­ble. The sim­plest way to do that is using the geom­e­try package:

\usepackage[text={16cm,24cm}]{geometry}

More on this here.

Following code will set the space between floats (including caption) and the surrounding text to 0pt, which is stretchable by 2pt.

\setlength{\intextsep}{0pt plus 2pt}   % default value 12pt plus 2pt minus 2pt, 

11. Float problem – How to use the placement options [t], [h] with figures?

In short, the placement options means allowing placement at certain locations:

h means here: Place the figure in the text where the figure environment is written, if there is enough room left on the page
t means top: Place it at the top of a page.
b means bottom: Place it at the bottom of a page.
p means page: Place it on a page containing only floats, such as figures and tables.

! allows to ignore certain parameters of LaTeX for float placement, for example:
\topfraction: maximal portion of a page (or column resp., here and below), which is allowed to be used by floats at its top, default 0.7
\bottomfraction: maximal portion of a page, which is allowed to be used by floats at its bottom, default value 0.3
\textfraction: minimal portion of a page, which would be used by body text, default value 0.2
\floatpagefraction: minimal portion of a float page, which has to be filled by floats, default value 0.2. This avoids too much white space on float pages.
topnumber: maximal number of floats allowed at the top of a page, default 2
bottomnumber: maximal number of floats allowed at the bottom of a page, default 1
totalnumber: maximal number of floats allowed at whole page, default 3

This means, if you add !, the float will be placed if it fits onto the current page and if there aren’t further waiting float objects of the same type, ignoring predefined propotions of text and floats as above. Such floats are also called bang floats.

Fractions can be changed by \renewcommand, numbers are counters which can be changed by \setcounter, further there are lenghts for spacing before, after, and between floats. This gives an impression how LaTeX automatically takes care of sensible figure placement, which you could adjust yourself – or override by ! if meaningful.

These options can be combined, such as [!htbp]. Their order doesn’t matter, LaTeX itself attempts using allowed places in order h, t, b, p, even if [pbth] was used.

You should even consider combining as many options as sensible. If a figure cannot be placed, it blocks subsequent figures. This can be a reason why figures end up very late, as you noticed. Specifically, ensure that the figures are not too big to fit into the margins.

12. How do I order citations by appearance using BibTeX?

Use

\bibliographystyle{ieeetr}

13. Multiline equations
Use

\usepackage{amsmath}

and put aligned command around the equations

\begin{equation}
\begin{aligned}
H_{\mu,v,r}=(h_{\mu,v,r} (0),h_{\mu,v,r} (1),\dots,h_{\mu,v,r} (B-1) ) \\
\mbox{where, } h_{\mu,v,r}(i)=\sum_{(x,y)\in R_r}\delta(LGBP_{\mu,v}(x,y)-i),i=0,1,\dots,B-1
\end{aligned}
\end{equation}

14. Text Embedded in Displayed Equations

Text can be embedded in displayed equations (in LaTeX) by using \mbox{embedded text}. For example,

\begin{equation}
\begin{aligned}
H_{\mu,v,r}=(h_{\mu,v,r} (0),h_{\mu,v,r} (1),\dots,h_{\mu,v,r} (B-1) ) \\
\mbox{where, } h_{\mu,v,r}(i)=\sum_{(x,y)\in R_r}\delta(LGBP_{\mu,v}(x,y)-i),i=0,1,\dots,B-1
\end{aligned}
\end{equation}

15. Combining multiple image files into a single figure

a) approach using tabular

\documentclass[a4paper,12pt]{article}
\usepackage{graphicx}
\usepackage{subcaption}

\begin{document}
\begin{figure}[htb]
\centering
  \begin{tabular}{@{}cccc@{}}
    \includegraphics[width=.23\textwidth]{example-image-a} &
    \includegraphics[width=.23\textwidth]{example-image-b} &
    \includegraphics[width=.23\textwidth]{example-image-c} &
    \includegraphics[width=.23\textwidth]{example-image}   \\
    \includegraphics[width=.23\textwidth]{example-image-a} &
    \includegraphics[width=.23\textwidth]{example-image-b} &
    \includegraphics[width=.23\textwidth]{example-image-c} &
    \includegraphics[width=.23\textwidth]{example-image}   \\
    \includegraphics[width=.23\textwidth]{example-image-a} &
    \includegraphics[width=.23\textwidth]{example-image-b} &
    \includegraphics[width=.23\textwidth]{example-image-c} &
    \includegraphics[width=.23\textwidth]{example-image}   \\
    \multicolumn{4}{c}{\includegraphics[width=.23\textwidth]{example-image-a}}
  \end{tabular}
  \caption{This is   some figure side by side}
\end{figure}
\end{document}

output:
latex_fig1

b) using subcaption that provides a subfigure command.

\documentclass[a4paper,12pt]{article}
\usepackage{graphicx}
\usepackage{subcaption}

\begin{document}
\begin{figure}[htb]
\centering
  \begin{subfigure}[b]{.24\linewidth}
    \centering
    \includegraphics[width=.99\textwidth]{example-image-a}
    \caption{A subfigure}\label{fig:1a}
  \end{subfigure}%   
  \begin{subfigure}[b]{.24\linewidth}
    \centering
    \includegraphics[width=.99\textwidth]{example-image-b}
    \caption{A subfigure}\label{fig:1b}
  \end{subfigure}%  
  \begin{subfigure}[b]{.24\linewidth}
    \centering
    \includegraphics[width=.99\textwidth]{example-image-c}
    \caption{A subfigure}\label{fig:1c}
  \end{subfigure}%  
  \begin{subfigure}[b]{.24\linewidth}
    \centering
    \includegraphics[width=.99\textwidth]{example-image}
    \caption{A subfigure}\label{fig:1d}
  \end{subfigure}\\%   
  \begin{subfigure}[b]{.24\linewidth}
    \centering
    \includegraphics[width=.99\textwidth]{example-image-a}
    \caption{A subfigure}\label{fig:1e}
  \end{subfigure}%
  \begin{subfigure}[b]{.24\linewidth}
    \centering
    \includegraphics[width=.99\textwidth]{example-image-b}
    \caption{A subfigure}\label{fig:1f}
  \end{subfigure}%
  \begin{subfigure}[b]{.24\linewidth}
    \centering
    \includegraphics[width=.99\textwidth]{example-image-c}
    \caption{A subfigure}\label{fig:1g}
  \end{subfigure}%
  \begin{subfigure}[b]{.24\linewidth}
    \centering
    \includegraphics[width=.99\textwidth]{example-image}
    \caption{A subfigure}\label{fig:1h}
  \end{subfigure}\\%     
  \begin{subfigure}[b]{.24\linewidth}
    \centering
    \includegraphics[width=.99\textwidth]{example-image-a}
    \caption{A subfigure}\label{fig:1i}
  \end{subfigure}%
  \begin{subfigure}[b]{.24\linewidth}
    \centering
    \includegraphics[width=.99\textwidth]{example-image-b}
    \caption{A subfigure}\label{fig:1j}
  \end{subfigure}%
  \begin{subfigure}[b]{.24\linewidth}
    \centering
    \includegraphics[width=.99\textwidth]{example-image-c}
    \caption{A subfigure}\label{fig:1k}
  \end{subfigure}%
  \begin{subfigure}[b]{.24\linewidth}
    \centering
    \includegraphics[width=.99\textwidth]{example-image}
    \caption{A subfigure}\label{fig:1l}
  \end{subfigure}\\%  
  \begin{subfigure}[b]{.24\linewidth}
    \centering
    \includegraphics[width=.99\textwidth]{example-image}
    \caption{A subfigure}\label{fig:1m}
  \end{subfigure}%    
  \caption{This is   lot of figures arranged side by side in matrix form with captions for each and a main caption}\label{fig:1}
\end{figure}
\end{document}

output:
latex_fig2

c) Using new subfig (subfigure is obsolete):

\documentclass[a4paper,12pt]{article}
\usepackage{graphicx}
\usepackage{subfig}


\begin{document}
\begin{figure}[htb]
\centering
  \subfloat[A subfigure]{%
    \includegraphics[width=.24\textwidth]{example-image-a}}\hfill
  \subfloat[A subfigure]{%
    \includegraphics[width=.24\textwidth]{example-image-b}}\hfill
  \subfloat[A subfigure]{%
    \includegraphics[width=.24\textwidth]{example-image-c}}\hfill
  \subfloat[A subfigure]{%
    \includegraphics[width=.24\textwidth]{example-image}}\\
  \subfloat[A subfigure]{%
    \includegraphics[width=.24\textwidth]{example-image-a}}\hfill
  \subfloat[A subfigure]{%
    \includegraphics[width=.24\textwidth]{example-image-b}}\hfill
  \subfloat[A subfigure]{%
    \includegraphics[width=.24\textwidth]{example-image-c}}\hfill
  \subfloat[A subfigure]{%
    \includegraphics[width=.24\textwidth]{example-image}}\\
  \subfloat[A subfigure]{%
    \includegraphics[width=.24\textwidth]{example-image-a}}\hfill
  \subfloat[A subfigure]{%
    \includegraphics[width=.24\textwidth]{example-image-b}}\hfill
  \subfloat[A subfigure]{%
    \includegraphics[width=.24\textwidth]{example-image-c}}\hfill
  \subfloat[A subfigure]{%
    \includegraphics[width=.24\textwidth]{example-image}}\\
  \subfloat[A subfigure]{%
    \includegraphics[width=.24\textwidth]{example-image}}
  \caption{This is   lot of figures arranged side by side in matrix form with captions for each and a main caption}\label{fig:1}
\end{figure}
\end{document}

16. Inserting n number of blank lines

Use

\vspace*{n * \baselineskip} % empty line

Where n=\{1,2,3..\} (an integer)