Tag Archives: report

Create small TOCs/LOFs/LOTs using \minitoc

In large documents, it is helpful to add a “mini-table-of-contents” at the beginning of every chapter in order to get a better overview of the chapter. The minitoc-package provides a nice, easy-to-use and customizable layout for TOCs on a chapter level.

How to crate a minitoc:

\usepackage{minitoc}

Any minitoc can only be created if you have a “global” table-of-contents, its content is used for generation. So in your document, you first have to notify Latex you want to use minitoc and then create the overall table of contents:

\dominitoc
\tableofcontents

Now you can add minitocs at the beginning of your chapters:

\chapter{...}
\minitoc
\section{...}

Minilofs and minilots:

Similarly, \minilof and minilot will create list-of-figures and list-of-tables for your chapters.

Remarks:

Obviously, this only makes sense in books and reports, as in articles there are no chapters available. Here the minitoc-package provides additional commands for articles:

\secttoc
\sectlof
\sectlot

and to partition books:

\parttoc
\partlof
\partlot

The package documentation can be found at CTAN


Define your own “list of …”

I got this very interesting question lately, how to define a custom list of examples, similar to the list of figures. But as this is not only applicable to examples, but to all sorts of things (e.g. questions, theorems, proofs, lemmas, answers, etc.) and hence might be useful for other people, I decided publish a new post on that issue.

As usual, you will need to import a package.

\usepackage{tocloft}

The package lets you customise your table of contents, list of figures or list of tables (which is basically what the name stands for).

In addition, the package also lets you define your custom lists easily and hence is exactly what we were looking for.

In order to keep this as general as possible, I will use “X” instead of “example”, “proof”, etc. At the end, I will post a complete example, showing how to create a “list of examples”, which you can simply copy-paste and adapt for your needs.

After having added the package, we want to define the name that appears as a title of our list:

\newcommand{\listXname}{List of Xs}

Next we use the command provided by tocloft to define a new list of whatever:

\newlistof{X}{ex}{\listXname}

Now we define the actual X-command (similar to figure or table), which has a counter that is increased by one every time an X is used:

\newcommand{\X}[1]{%
\refstepcounter{X}
\par\noindent\textbf{X \theexample. #1}
\addcontentsline{exp}{example}
{\protect\numberline{\thechapter.\theexample}#1}\par}

By using the X-command (\X{Your text}), Latex will print the following:

X 1 Your text

The last line will add all your typed Xs to the list of Xs.

That’s it for the definition. The command “\listofX” will create a list of all your defined Xs similar to the ToC, LoF and LoT.

\begin{document}
\tableofcontents
\newpage
\listofX
\newpage
...
\end{document}

You can also add references to the different Xs, by adding a label just after the X-command (see example below):

Example: List of Examples

\documentclass{report}
\usepackage{tocloft}
\usepackage[english]{babel}
\newcommand{\listexamplename}{List of Examples}
\newlistof{example}{exp}{\listexamplename}
\newcommand{\example}[1]{%
\refstepcounter{example}
\par\noindent\textbf{Example \theexample. #1}
\addcontentsline{exp}{example}
{\protect\numberline{\thechapter.\theexample}#1}\par}
\begin{document}
\tableofcontents
\newpage
\listofexample
\chapter{Two examples}
\example{Your first example}
\label{1st_ex}
\example{Your second example}
\label{2nd_ex}
\chapter{One example}
\example{Your third example. (See example \ref{1st_ex} and \ref{2nd_ex})}
\end{document}

If you want to reset your example counter for new chapters, you would need to add the following lines before the beginning of your document:

\makeatletter
\@addtoreset{example}{chapter}
\makeatother

Click here for the complete tocloft documentation as well as the package.


Of theorems, lemmas and proofs

Different packages of Latex provide nice and easy-to-use environments for theorems, lemmas, proofs, etc. The following post will show you the mostly used layouts and how to change numbering. 
Theorem styles: For theorems, corollaries and lemmas, you need the following package:

\usepackage{amsthm}

which allows you to define new environments using either:

\newtheorem{env_name}{caption}[within]

or

\newtheorem{env_name}[numbered_like]{caption}

 where

  •  env_name: Environment name
  • caption: Text printed before the number, e.g. Theorem, Lemma, etc.
  • within: The name of a defined counter
  • numberered_like: Name of a defined theorem-like environment

Note: The command may at most have one optional argument. Let me give an example: First we define a new theorem “Theorem”, which takes the numbering of the section plus a consecutive number:

\newtheorem{thm}{Theorem}[section] 

For your theorems you can now use the defined environment:

\begin{thm}...\end{thm}

 For lemmas which have the same numbering as the previous thm-environment, we need to define a new theorem type:

\newtheorem{lem}[thm]{Lemma}

 Note: Environments different from thm, lem or cor need to be defined previously, having a different counter which starts from zero:

\theoremstyle{remark} 
\newtheorem{rem}{Remark}
\begin{rem}This is a remark.\end{rem}

Note: To omit the numbering, you can use the star as for chapters, sections, etc.:

\newtheorem*{lem}[thm]{Lemma}

Proof: A proof usually comes without a numbering as it follows a numbered theorem, corollary, etc. For a proof, you need the following package:

\usepackage{amsthm}

and then you can directly use the proof-environment:

\begin{proof}...\end{proof}

The closing statement automatically prints a qed-sign (square box) on an empty line after the last statement, terminating the proof.Note: If you want to place the qed-sign on the last line, i.e. if your proof ends with an equation, you can use the command:

\qedhere

inside the equation-environment (before the \end{equation}).


Add (Hyper-)Links to PDFs

Adding links to PDFs , both internal and external, certainly only makes sense for digital copies of the file. Nevertheless, they still come in handy, for example for actual WWW-addresses or as direct reference inside a document.

Local references

As usual, you first need the package which handles the links:

\usepackage{hyperref}

This does the job for the moment. The package “hyperref” will automatically insert links wherever you place a citation or reference (\cite{}, \ref{}).

Global references

Referencing to URLs or local files can be done as follows:

\href{url}{text}

Try this:

\href{http://texblog.wordpress.com}{\bf{Blog on Latex Matters}}

Colour references

So far, the references were marked by a colour rectangle around them, which is not very appealing (unless you are using Apple Preview). Here is how you remove the border and if you wish define your own colours for references.

Either add this optional argument to the previous package:

\usepackage[colorlinks]{hyperref}

or use a new line and set the colour:

\usepackage{hyperref}
\hypersetup{colorlinks}

If you want to define your own colours, you will have to use the latter, as the colours are part of the argument of “hypersetup”. But in order to do so, you first need to define colours, which is why you will need the colour-package:

\usepackage{color}

Then you can define different colours you may want to use for your references, e.g.:

\definecolor{darkred}{rgb}{0.5,0,0}
\definecolor{darkgreen}{rgb}{0,0.5,0}
\definecolor{darkblue}{rgb}{0,0,0.5}

Latex uses the standard RGB (red/green/blue) colour model. The three values define the intensity for each channel within the interval I=[0,1] (just because Latex looks nicer:-).

Now you are ready to use the defined colours, by extending the previously used command:

\hypersetup{ colorlinks,
linkcolor=darkblue,
filecolor=darkgreen,
urlcolor=darkred,
citecolor=darkblue }

Note: If your tex-distribution does not contain the hyperref-package, you can download it here (hyperref.zip), including the complete documentation.


Landscape in Latex

The default page layout is “portrait”, but sometimes it is still useful/necessary to have the whole document or only single pages changed to “landscape”. The latter might be due to a large table or figure. This post will tell you how to change the page layout of the whole document or single pages to “landscape”. In addition, it is possible to make single pages appear left side up in the PDF, making them more readable.

Changing the whole document to “landscape” can be done be using the geometry-package:

\usepackage[landscape]{geometry}

You can also just change the page content to landscape, but not the actual page layout through the optional argument of the command “documentclass”. It does not make much sense, but you can do it:

\ documentclass[landscape, 12pt]{report}

Next I will show you how to change the page layout of single pages. The lscape-package provides according possiblities:

\usepackage{lscape}

With

\begin{landscape}
...
\end{landscape}

you define the section of your document to be set to “landscape”, e.g. a large table or figure.

This will not automatically rotate the page in the PDF and is useful if the document is destined for printing.

If you want to make appear the left side up, better readable on screen, the pdflscape-package will do it:

\usepackage{pdflscape}

and again:

\begin{landscape}
...
\end{landscape}

for the page to be “landscape”, while the rest will remain in “portrait” orientation. Nevertheless, the header/footer will also be changed in orientation.


Header/Footer in Latex with Fancyhdr

Creating headers and footers in Latex can be done by using the package “fancyhdr”. This is a short introduction, showing the most important features of the package. If you know “fancyhdr” and are looking for something particular, refer to the fancyhdr-documentation.

First of all, you need to tell Latex to use the package:

\usepackage{fancyhdr}

and change the style from “plain” to “fancy”:

\pagestyle{fancy}

You will now the get the default fancy pagestyle which adds a line at the top of every page, except for some exceptions (title-page, abstract, new chapter in report).

Default fancyhdr page style:

Above the line, Latex will print headings:

Book/report

Left-hand side: section
Right-hand side: chapter
Note: if you use the optional documentclass argument “twoside”, Latex will alter the position of the section and chapter. (e.g. \documentclass[twoside]{report}, also introducing non-symmetric margins).

Article

For acticles, Latex will print the section only (chapters cannot be used with articles).
The footer only includes the page number which is centered by default.

Custom fancyhdr page style:

Even though fancyhdr has a default page style, you are free to define headers/footers yourself , which is not too difficult after all.

First you need to clear the default layout:

\fancyhead{}
\fancyfoot{}

There are seven letters you need to know before you can define your own header/footer:

E: Even page
O: Odd page
L: Left field
C: Center field
R: Right field
H: Header
F: Footer

Now it’s time to start defining your own layout. The definitions are added to the preamble:

\fancyhead[CO,CE]{---Draft---}
\fancyfoot[C]{Confidential}
\fancyfoot[RO, LE] {\thepage}

The decorative lines can be changed by increasing/decreasing their thickness (0pt means no line):

\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}

Note: According to the fancyhdr-documentation, the default layout is produced by the following commands:

\fancyhead[LE,RO]{\slshape \rightmark}
\fancyhead[LO,RE]{\slshape \leftmark}
\fancyfoot[C]{\thepage}
\headrulewidth 0.4pt
\footrulewidth 0 pt


Flush figure before end of page

Usually figures are placed wherever there is enough space, e.g. for “begin{figure}[ht]” at the beginning of the next page. What if you want to place the figure within the text, because you have other figures which you do not want to place only at the beginning of the second next page…

There is a little trick, which lets Latex place figures before the end of a section by using an exclamation mark (\begin{figure}[h!t]), as long as there is enough space on that page.
The exclamation mark let’s you place figures more precisely in the text and is more often useful than not. It can be used to the same extend for tables.


Problem with label for tables having small text-size

I recently had the following problem, I was using a label to reference a table where I placed the “tabular”- environment into the “small”- environment to decrease its size. The number indicated by the reference was not the table index, but rather the number of the section/subsection within which I placed the table. The problems seems to exist in both, Miktex and MacTex…

A table ususally has the following structure (for an introduction to tables click here) with the “small”- environment added to slightly decrease its size:

\begin{table}[htdp]
\caption{default}
\begin{small}
\begin{center}
\begin{tabular}{|c|c|}
\end{tabular}
\end{center}
\end{small}
\label{default}
\end{table}

Placing the label inside both, “small”- and “center”- environment solves the problem.
Hence:

\begin{table}[htdp]
\caption{default}
\begin{small}
\begin{center}
\begin{tabular}{|c|c|}
\end{tabular}
\label{default}
\end{center}
\end{small}
\end{table}

I actually don’t know why Latex does not translate the reference correctly, as the label is still within the “table”-environment, at least the problem can be solved that way.


Using draft to determine overfull hboxes

Latex provides a draft-mode as an optional argument to the document class, having two main effects on the whole document.

Draft is an optional argument of the document class and is therefore used as follows

\documentclass[draft]{...}

The two main effects mentioned before are:

  1. Marking overfull hboxes (no line-break within the margin) by a vertical line, helping to locate overfull hbox warnings. This affects text, but also figures and tables.
  2. Embedded images are not displayed in the generated PDF. Instead only an outline including the file path is shown.

A similar effect as the latter can also be achieved by drafting the graphicx package (\usepackage[draft]{graphicx}).


Creating two columns in article, report or book

Three different styles have to be distinguished when creating multiple columns in a Latex document. Either we want the whole document to have two columns, single pages or only part of a page. In order to do so, three different Latex commands are used…

Whole document (using article to write a paper):

The only thing you need to do is changing the first command of your Latex-file.

\documentclass[11pt,twocolumn]{article}

It will automatically create two columns in the entire document.

Note: if you are writing a paper, IEEE provides useful templates which can be used and adapted to your needs. You can download them from their “Author Digital Tool Box“.

Single pages:

The command \twocolumn starts a new page having two columns. Accordingly, \onecolumn starts a new page with a single column assuming you are in a two column environment as described above. Both commans do not take any arguments.

The is a way to define the distance between the two columns, use

\setlength{\columnsep}{distance}

If you need a line to separate the columns, the following command will do the job:

\setlength{\columnseprule}{thickness}

Part of a page:

I have posted another article on that, just have a look there. \minipage can also be used for text, not only for figures and tables.


Follow

Get every new post delivered to your Inbox.

Join 316 other followers