# Work-around for Error: Float(s) lost

=======================================================

# -> Update <-

After a half day trial and error, it's safe to say that this is caused by the

"famous" error Error: Float(s) lost.

I have been reading on this site, but it seems that the only way was to take it out of the mini-figure thing. No other useful work around at the moment.

# =======================================================

Code:

\documentclass[12pt,a4paper]{report}

\usepackage{amsmath,amsthm,enumerate}
\usepackage{graphicx,subfigure}% for pictures
\graphicspath{{Pictures/}} % Specifies the directory where pictures are stored

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Example and Solution

\usepackage[most]{tcolorbox}

\NewTColorBox[auto counter, number within=section]{example}{+O{}}{%
enhanced,
breakable,
coltitle=black,
fonttitle=\bfseries,
title={Example~\thetcbcounter:},
%lowerbox=invisible,
bicolor,
colback=black!5!white,
colbacklower=black!3!white,
#1}
%\tcbset{student/.style={lowerbox=invisible}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\pdfoptionpdfminorversion 6

\begin{document}

\begin{example}

Figure~\ref{fig:conti_pdf_cdf} gives the probability density function $f(x)$ and its cumulative function $F(x)$.
\begin{figure}[!hp]
\centering
\subfigure[$f(x)$]{\includegraphics[scale=0.6]{15-1.pdf}}  %1.5 version
\\[2ex]
\subfigure[$F(x)$]{\includegraphics[scale=0.6]{15-2.pdf}}
\caption{Illustration of $f(x)$ and $F(x)$ for a (continuous) piecewise function}
\label{fig:conti_pdf_cdf}
\end{figure}

\tcblower

Figure~\ref{fig:conti_pdf_cdf} gives the probability density function $f(x)$ and its cumulative function $F(x)$.
\begin{figure}[!hp]
\centering
\subfigure[$f(x)$]{\includegraphics[scale=0.6]{14-1.pdf}} %1.4 version
\\[2ex]
\subfigure[$F(x)$]{\includegraphics[scale=0.6]{14-2.pdf}}
\caption{Illustration of $f(x)$ and $F(x)$ for a (continuous) piecewise function}
\label{fig:conti_pdf_cdf}
\end{figure}

\begin{center}
\includegraphics[scale=0.4]{chap3_eg1.pdf} % 1.4 version
\end{center}

\end{example}

\end{document}


If I compile it without the example environment, it works fine.

If I then add the example environment, it does not compile (no graph for the 1.4 or 1.5 version PDF). Ignoring the warning, only the {chap3_eg1.pdf} shows in the final PDF.

Would there be any specific things (in the PDF) that is causing latex not to compile the PDF? Both 1.4 and 1.5 version is the same file. I used Acrobat to convert between versions.

So any solution?

=======================================================

# OLD post

Sorry about the messy title. I will try to make it simple.

In the first instance, I was trying to implement implement this solution (see comments). So I used

\NewTColorBox[auto counter]{exercise}{+O{}}{%
enhanced, breakable,
coltitle=black,
fonttitle=\bfseries,
title={Exercise~\thetcbcounter:},
#1}


I got an error.

! pdfTeX error (setup): \pdfminorversion cannot be changed after data is written to the PDF file.


No PDF file was produced. It worked fine after I did

% \pdfoptionpdfminorversion 6


With a different .tex file, I got this error and I found the lost PDFs (version 1.5)

! LaTeX Error: Float(s) lost.


They were coded using

\begin{figure}[!hp]
\centering
\subfigure[$f(x)$]{\includegraphics[scale=0.6]{chap3_eg3_den.pdf}}
\\[2ex]
\subfigure[$F(x)$]{\includegraphics[scale=0.6]{chap3_eg3_cum.pdf}}
\caption{Illustration of $f(x)$ and $F(x)$ for a (continuous) piecewise function}
\label{fig:conti_pdf_cdf}
\end{figure}


Did some research, says something to do with figures in figures or \marginpar. But looking at my code, I don't think it is this case here.

I have other PDF (also 1.5) that works fine.

I guess my question really is - What's causing it?

The packages? The Floats (subfigure)? Or The PDFVersion thing??

• Invest 15 minutes in a better problem description. One with a complete example demonstrating the (first) error, log-file and a description of your tex system. As it is the question is a mess. – Ulrike Fischer Jun 5 '18 at 11:54
• Use example-image instead of the pdfs and see if you still get an error? – Troy Jun 5 '18 at 13:15
• @Troy (same) still error, tried with example-image. I have even tried using .jpg. I think there is just something clashing with example environment was introduced. But weirdly, if I take out the whole environment, it compiles fine, even mixed versions of PDFs. – Chen Stats Yu Jun 5 '18 at 13:43
• My point is that: then it's not an issue with the pdf versions? Get rid of the floating (figure) environments in the example environment. Just use includegraphics and see if it compiles. – Troy Jun 5 '18 at 13:51
• @Troy Yes, I think it's safe to say that this problem is caused by the example environment. I have been reading on this tex.stackexchange.com/questions/79185/… but was not able to find any useful workarounds. Thanks. – Chen Stats Yu Jun 5 '18 at 14:18

It's not difficult to define a nonfloating version of figure.

In the code I changed subfigure (deprecated for about 15 years) to subfig and, consequently, \subfigure to \subfloat.

\documentclass[12pt,a4paper]{report}

\usepackage{amsmath,amsthm,enumerate}
\usepackage{graphicx,subfig}% for pictures

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Example and Solution

\usepackage[most]{tcolorbox}

\NewTColorBox[auto counter, number within=section]{example}{+O{}}{%
enhanced,
breakable,
coltitle=black,
fonttitle=\bfseries,
title={Example~\thetcbcounter:},
%lowerbox=invisible,
bicolor,
colback=black!5!white,
colbacklower=black!3!white,
#1}
%\tcbset{student/.style={lowerbox=invisible}}

\makeatletter
\newenvironment{fixedfigure}
{\def\@captype{figure}\center}
{\endcenter}
\makeatother

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\pdfoptionpdfminorversion 6

\begin{document}

\begin{example}

Figure~\ref{fig:conti_pdf_cdf} gives the probability density function $f(x)$ and its cumulative function $F(x)$.
\begin{fixedfigure}
\subfloat[$f(x)$]{\includegraphics[width=3cm]{example-image}}\qquad
\subfloat[$F(x)$]{\includegraphics[width=3cm]{example-image}}
\caption{Illustration of $f(x)$ and $F(x)$ for a (continuous) piecewise function}
\label{fig:conti_pdf_cdf}
\end{fixedfigure}

\tcblower

Figure~\ref{fig:conti_pdf_cdf-B} gives the probability density function $f(x)$ and its cumulative function $F(x)$.
\begin{fixedfigure}
\subfloat[$f(x)$]{\includegraphics[width=3cm]{example-image}}\qquad
\subfloat[$F(x)$]{\includegraphics[width=3cm]{example-image}}
\caption{Illustration of $f(x)$ and $F(x)$ for a (continuous) piecewise function}
\label{fig:conti_pdf_cdf-B}
\end{fixedfigure}

\begin{center}
\includegraphics[width=5cm]{example-image} % 1.4 version
\end{center}

\end{example}

\end{document}