I managed to solve the "problem" as it turned out not to be problem at all.
As already stated in the question, removing the twoside
option resulted in the MWE functioning again. At first I didn't realise this, but as the book
documentclass has by default the layout set as two-sided! So including it doesn't add anything, but more importantly, removing the statement doesn't change anything either!
In essence, the fix in the question was already the answer, but it is a mystery why the explicit statement of a default setting would result in these error messages.
I then did some further testing with classes that do not as a default have the twoside
option enabled such as the article
class. Without any statement (so default, oneside
) the effect is as desired and doesn't give any error messages. However, when the option twoside
is passed it again results in errors.
In summary, it would seem that the fltpage
and caption
packages are incompatible when used in a documentclass that:
a. has not, by default, a twoside
layout; and a twoside
layout is required and therefore passed as an option; or
b. has by default a twoside
layout but this is also given as a statement when devining the documentclass.
My question related to the second option and is therefore answered, remove the optional mentioning of the twoside
option. The issue remains for people wanting to use it in other documentclasses such as article
, in combination with twoside
layout.
This seems to work but I don't really understand why. Note that I don't have your images so I had to replace them and the white doesn't show up as well on the examples from mwe
. However, you can see the captions if you look closely...
\documentclass{article}
\usepackage{graphicx,caption,subcaption,tikz}
\usetikzlibrary{backgrounds}
\usetikzlibrary{calc}
\DeclareCaptionFormat{overlay}{\gdef\capoverlay{#1#2#3\par}}
\DeclareCaptionStyle{overlay}{format=overlay}
\DeclareCaptionFormat{suboverlay}{\gdef\subcapoverlay{(\thesubfigure) #3\par}}
\DeclareCaptionStyle{suboverlay}{format=suboverlay}
\newcommand{\captionOverlay}[1]{%
\captionsetup{format=overlay}
\caption{}%
\begin{tikzpicture}
\node [inner sep=0] (image) {#1};
\draw node [white] {\capoverlay};
\end{tikzpicture}%
}
\captionsetup[subfigure]{format=suboverlay}
\newcommand{\subcaptionOverlay}[1]{%
\subcaption{}%
\begin{tikzpicture}
\node [inner sep=0] (image) {#1};
\draw node [white] {\subcapoverlay};
\end{tikzpicture}%
}
\begin{document}
\begin{figure}[htpb]
\centering
\begin{subfigure}[b]{.3\textwidth}
\centering
\subcaptionOverlay{\includegraphics[width=\textwidth]{example-image-a}}
\label{subA}
\end{subfigure}
\begin{subfigure}[b]{0.3\textwidth}
\centering
\subcaptionOverlay{\includegraphics[width=\textwidth]{example-image-a}}
\label{subB}
\end{subfigure}
\caption{}
\label{mainFig}
\end{figure}
\begin{figure}[htpb]
\centering
\captionOverlay{\includegraphics[width=\textwidth]{example-image-a}}
\label{normalFig}
\end{figure}
\end{document}
Best Answer
Protecting the command should solve the problem: