because LaTeX matters

The author of LaTeX Beginner’s Guide, Stefan Kottwitz, just notified me that his book is freely available for download as ebook. This offer is only valid for today. If you are interested, you can get a copy from the publisher’s website through this link.

Like this:

In the standard document classes report and book, figure and table counters are reset after every chapter. On the other hand, article does not reset these counters when a new section is started. The chngcntr package provides the \counterwithin and \counterwithout commands to redefine a counter, by adding or removing a dependency. Through these commands, the behavior of the figure and table counters can be changed.

Continuous figure and table numbering in report/book

The \counterwithout command removes a dependency from a counter and redefines \the’counter’ such that it is printed without the dependency.

Through \counterwithout, the figure and table counters can be changed to continuously number these figures and tables throughout a report or book. The command also redefines the way the counter is printed, such that the chapter number is not shown (e.g. ‘Figure 3′ instead of ‘Figure 1.3′). Redefining \the’counter’ can be omitted through the starred version \counterwithout*.

Similarly, a reset-dependency can be added to any counter through \counterwithin. The command also redefines \the’counter’ (e.g. ‘Figure 1.3′ instead of ‘Figure 1′). Again, the package provides a starred version \conterwithin* that does not redefine \the’counter’.

As an example, the \counterwithin command can be used to automatically reset the figure and table counters whenever a new section is started in an article. Also, the command redefines \thefigure to \thesection.\arabic{figure}. Therefore, figure 3 in section 1 will be printed as ‘Figure 1.3′. The same applies to \thetable.

It’s easy to add, remove, or shift rows. Just copy-and-paste or delete the corresponding line in the table. Removing columms is a different story. You might be able to come up with some sophisticated regular expression, which removes the right value in every row. Otherwise, the only way is to use another program or to do it manually. Also, what if you later decide to include the column?

Here is a neat way to hide table columns. This trick requires minimal changes to the table and can be undone easily.

Define a new column type that swallows its content.

The array package implements a macro to define your own column type. This is useful when complicated column styles are reused multiple times. Here, we will use it to hide the column content.

The following code defines a new column type H that packs its content into a box of zero size. To remove the intercolumn space after the column we use: @{}.

I was editing a poster and didn’t know whether or not to include a bibliography. I had already added \cite commands and wanted to get an idea of what it looks like without bibliography. So I commented out \printbiliography to get rid of the bibliography, but the numbers were still in the text. Removing all \cite commands wasn’t an option in case I wanted to have them back.

At first, I tried to overwrite \cite with a command that doesn’t exist:

\let\cite\undefined % \undefined is not defined

This wouldn’t work because \cite becomes undefined and is still called in the text. The LaTeX engine returns “Undefined control sequence”.

The document class options draft is extremely useful to speed up typesetting and visualize overfull \hbox warnings. Even more so, when you work on a large document. I previously introduced the draft and final options here and here.

The ifdraft package adds more flexibility to the draft and final options. It implements three commands with slightly different behavior when draft or final are set.

The command \ifdraft assumes final if no option is set. Furthermore, both options, draft and final, should not be used at the same time.

Let’s see a few examples.

Example 1: Line spacing

It is often easier to proof-read a text with extra space between lines. Especially, if the reader adds his comments on paper. In this case, \ifdraft allows automatic switching between double and single spacing, depending on the option set (draft or final). In the example, the setspace package is used to switch between single and double line spacing (see here for examples on package usage).

Example 2: Single column / two columns

It may be easier to edit a document using a single column style, even if the final version will have two or more columns. Sure, it would be sufficient to replace onecolumn with twocolumn in the list of document class options.

It might not seem like a big thing to do, but often the author switches frequently between draft and final or there are other draft-specific options, e.g. line spacing as shown in the previous example. In this case, it is faster and cleaner to hook all changes to the draft and final options.

Example 3: Removing TODO notes

Todonotes provides functionality to visualize TODOs in the margins of the output PDF. The option disable removes all TODOs from the document. But then again, it’s cleaner and faster to link this behavior to the draft option.

In the following example the todonotes package is loaded without or with the option disable, depending on whether draft or final is used:

Example 4: Draft watermark

This last example shows how the \ifoptiondraft command can be used to produce the watermark “DRAFT” only when draft is set. To learn more about watermarks, see my post on the topic here. In this example, the second argument is empty as nothing is to be done when no option is not given or final is used.