Tag Archives: hyperref

Setting PDF meta information

PDFs have meta document information which usually can be read and modified using standard PDF viewers such as Acrobat Reader or Preview (Mac). In Acrobat Reader search for “Properties” in the file-menu. When creating a document using LaTeX, the hyperref package helps setting some of these information, including:

  • Title
  • Author
  • Subject
  • Creator
  • Producer
  • Keywords
  • and many other display and information options (see section 3.6 of the documentation)

 

Here is how:

While loading the package, the meta information is set by specifying key-value pairs in the optional arguments field, i.e.:

\usepackage[key1=value1, key2=value2]{hyperref}

A complete code example:

\documentclass[11pt]{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage[pdftex,
 pdfauthor=Tom,
 pdftitle={PDF meta information},
 pdfsubject={Sample document with blind text},
 pdfkeywords={hyperref, PDF meta information},
 pdfproducer=TeXShop,
 pdfcreator=pdflatex]{hyperref}
\begin{document}
\blindtext
\end{document}

Using the Acrobat Reader, the meta information can be read and changed through the menu item “file -> properties” (or similar):

pdf meta information

PDF meta information example

A comprehensive list of options is provided in section 3.6 of the hyperref package documentation.


10 ways to customize toc/lof/lot

I put together this list of 10 ways to customize the Table of Contents, List of Figures and List of Tables. Some of them are pretty common, some may be new to you. Hope you enjoy the list…

Some pieces of code below require the tocloft package which provides extensive customization functionality for table of contents, list of figures and list of tables. It will be indicated wherever the tocloft or any other package needs to be loaded in the preamble.

Note: I will use the abbreviations toc for table-of-contents, lof for list-of-figures and lot for list-of-tables in the article below.

1. Change the lists headings

Change the heading can be done without loading any specific package. Obviously, the name has to be changed before creating the list.

\renewcommand\contentsname{}
\tableofcontents
\renewcommand\listfigurename{}
\listoffigures
\renewcommand\listtablename{}
\listoftables

2. Add “Page” above page numbers

Several people asked me how to place the word “Page” on top of the page numbers in toc/lof/lot. Here is how you do it:

\tableofcontents
\addtocontents{toc}{~\hfill\textbf{Page}\par}
\chapter{...}

"Page" above page numbers

It works the same way with lof and lot. The code was taken from here.

3. Change depth of entries

You can change the depth, i.e. how many levels shall be printed using the respective counter:

\setcounter{tocdepth}{1}
\tableofcontents

0: chapter (not available for \documentclass{article),
1: section,
2: subsection, etc.
The default depth is 3, subsubsection.
Similarly, including subfigures and subtables can be achieved using:

\setcounter{lofdepth}{2}
\setcounter{lotdepth}{2}

4. Roman page numbers for toc/lof/lot

To get a different page number style for toc/lof/lot, use:

\pagenumbering{}

and change it back to arabic before the first chapter starts.

Available styles are arabic, roman, Roman, alph and Alph.

Complete code example:

...
\pagenumbering{roman}
\tableofcontents
\listoffigures
\listoftables
\clearpage
\pagenumbering{arabic}
\chapter{...}
...

5. Hyperlinks to content

Loading the hyperref package will let you navigate from toc/lof/lot entries directly to the respective content:

\usepackage{hyperref}

If you only want the page number to be clickable, you’ll need to load the package with the following option:

\usepackage[linktocpage=true]{hyperref}

6. Adding the lists to toc

Adding entries to toc/lof/lot can be done manually with a single command. Usually, to be sure the page number is correct, it’s advisable to add entries directly before or after the actual content to list. And here is how:

\addcontentsline{}{}{}

The file line(s) shall be added (toc, lof or lot), the type of the entry (chapter, figure, etc.) and the entry text itself.

To add the three lists to the toc use:

\tableofcontents
\addcontentsline{toc}{chapter}{Contents}
\listoffigures
\addcontentsline{toc}{chapter}{List of Figures}
\listoftables
\addcontentsline{toc}{chapter}{List of Tables}

Adding toc/lof/lot to contents

7. Changing the font of entries

To change the way the actual entries look, you can make use of a command provided by the tocloft package. The command will affect the number as well as the text. However, it will not change the page number and the separator (if there are any). The nice thing here is that since it’s placed just in front of the sequence number, you can also use it to add words such as “Chapter 1: Biology … Here are a few examples for illustration:

\usepackage{tocloft}
\renewcommand{\cftchapfont}{\scshape}
\renewcommand{\cftsecfont}{\bfseries}
\renewcommand{\cftfigfont}{Figure }
\renewcommand{\cfttabfont}{Table }

Try it and make sure you don’t forget the space behind Figure_ and Table_, otherwise it will be glued to the number.

8. Creating you own list of …

Again, the tocloft package has to be loaded. First, define a new list environment as well as the item which are later being listed. In this case, we are defining lemmas, but it could also be proofs, equations, a special list of figures, footnotes, anything. The last line of the lemma command defines how lemmas should be numbered, here “chapter.lemma”.

\usepackage{tocloft}
...
\newcommand{\listoflemmas}{List of Lemmas}
\newlistof{lemma}{lem}{\listoflemmas}
\newcommand{\lemma}[1]{%
  \refstepcounter{lemma}
  \par\noindent\textbf{Lemma \thelemma. #1}
  \addcontentsline{lem}{lemma}
  {\protect\numberline{\thechapter.\thelemma}#1}\par
}
...
\listoflemmas
...
\lemma{My first lemma}
\label{lem:lemma1}

You can find a complete code example here.

9. Alternative text in toc/lof/lot for headings and captions

In case your caption is too long for the lof/lot, you can give it an alternative text. Similarly, the headings can be given an alternative name in the toc:

\caption[]{}
\chapter[]{}

10. Chapter specific tocs with minitoc

Finally, minitoc produces beautiful tocs at the beginning of every chapter (or any other heading) and therefore, I will dedicate this 10th and last entry to that package:

\usepackage{minitoc}
...
\dominitoc
\tableofcontents
...
\chapter{...}
\minitoc

A minitoc example

Here is an earlier post I wrote about the package as well as the complete documentation.

Wow, that’s the longest post I ever wrote. Hope you’ve enjoyed my list, have fun customizing :-) .


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.


Follow

Get every new post delivered to your Inbox.

Join 316 other followers