13

I would like to change the default float options for my figures, so that I only need to adjust one option in order to change the behavior of all figures in the document. On my previous computer (Ubuntu 14.04), I had been doing something like this:

\documentclass{article}
\newcommand{\defaultplacement}{htb}
\begin{document}
\begin{figure}[\defaultplacement]
\caption{Example}
\end{figure} 
\end{document}

I'm now trying to build on Ubuntu 16.04, and am getting the following error:

./figures/ch1/coordinate_system.tex:1: LaTeX Error: Unknown float option `\'.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.1 \begin{figure}[\defaultplacement]

It seems that previously, LaTeX was replacing \defaultplacement with its value before processing, but now it is processing the macro in place. My guess is that my original solution was a bit of a hack, and that there is a better way to reset the default figure (and table?) placement that I've just been unable to find.

2 Answers2

19

LaTeX uses the contents of macro \fps@<float> as the default parameters for the float type <float>. It can be redefined, e.g. for figure:

\makeatletter
\renewcommand*{\fps@figure}{htb}
\makeatother

Then, the options of the macro applies, if the float is used without the optional argument:

\begin{figure}
...
\end{figure}
Heiko Oberdiek
  • 271,626
  • 2
    Excellent, thank you! For anyone who, like me, was mystified by \makeatletter and \makeatother, here's a helpful question: https://tex.stackexchange.com/questions/8351/what-do-makeatletter-and-makeatother-do#8353 – sudo make install Apr 15 '17 at 10:49
12

Heiko's already shown the correct declaration, but to answer

It seems that previously, LaTeX was replacing \defaultplacement with its value before processing, but now it is processing the macro in place.

No. Previously, unknown characters were silently ignored, so

[\defaultplacement]

was same as

[\ d e f a u lt pl a c e m e n t]

which, after ignoring unknown and duplicate options, was same as

[tp]

Incidentally, are you sure you want a default of htb ?

Disallowing p (float pages) massively increases the chance that all floats go to the end of the document.

David Carlisle
  • 757,742
  • 2
    I'm continually astounded by the intricacy of my own bugs. Thanks very much for pointing this out--while I've accepted @Heiko Oberdiek's answer because it most directly addresses the question I posed, yours no doubt has saved me from a quagmire down the line. Have a lovely day! – sudo make install Apr 15 '17 at 10:51