3

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

-> 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:},
        attach title to upper=\quad,
        before lower={\textbf{Solution~\thetcbcounter:\quad}},
        %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:},
    attach title to upper=\quad,
    before lower={\textbf{Solution~\thetcbcounter:\quad}},
    #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??

5
  • 4
    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. Jun 5, 2018 at 11:54
  • Use example-image instead of the pdfs and see if you still get an error?
    – Troy
    Jun 5, 2018 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. Jun 5, 2018 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, 2018 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. Jun 5, 2018 at 14:18

2 Answers 2

4

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:},
        attach title to upper=\quad,
        before lower={\textbf{Solution~\thetcbcounter:\quad}},
        %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}

enter image description here

1
  • Great answer, as always from egreg! To avoid renaming every instance of figure, I went for the radical: \renewenvironment{figure} (it's easy to regex figure to fixedfigure, but my figures are imported by beamer and other classes I use, so it was more convenient to keep the word figure)
    – PatrickT
    Sep 8, 2021 at 8:54
0

In my case, I have large chapters some with tens of figures. This error appeared when I migrated to a different latex template (from memoir to kaobook) however the migration wasn't necessarily the cause of the problem, the problem happened to be latent in the memoir template. Here's a sanitized extract of the code:

\begin{figure*}
\includegraphics[width=\linewidth]{example-image}
\caption[Three layers of an app]{Three layers of an app \sidenote{Image credit: First published somewhere else~\cite{harty_aymer_playbook_2016}}.}
\label{fig:3-layers}
\end{figure*}

The \sidenote{...} for kaobook or \footnote{...} for memoir led to the Float(s) lost message later in the chapter. One of the images was indeed not displayed in the generated PDF.

I used \clearpage before each \section{...} to help me track down where the problem was being triggered. That led me to this figure.

The workaround was to remove the sidenote/footnote command as follows:

\begin{figure*}
\includegraphics[width=\linewidth]{example-image}
\caption[Three layers of an app]{Three layers of an app {Image credit: First published somewhere else~\cite{harty_aymer_playbook_2016}}.}
\label{fig:3-layers}
\end{figure*}

Note: I temporarily left the {} around the text as that was quick and easy to do to test my theory. These were removed once I'd seen the error had been addressed. I hope this may help others who follow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.