# Caption placement for new float environment in tufte-handout class

I'm using the class: tufte-handout and I need a new coloured environment for data, examples and details that I want to highlight.

I found this question (with answer) that is literally what I want. It create a coloured rectangle with a caption. If I copy and paste the code, I actually obtain the result that I want with a working caption, but the software shows an error message at the end of the compilation: "Undefined control sequence. \end{example}" and "Missing number, treated as zero. \end{example}". The error message (both combined) is repeated like 3 times.

The MWE is (the answer from Gonzalo Medina):

Caption placement for new float in tufte-book class

(The second one, with the code for the colouration integrated in the definition of the new environment.)

If I copy the MWE provided in the answer, the result is good and without error, if I change only the class (handout instead of book) I obtain the same result but with the error message.

The pdf is ok, but the message itself annoys me. I would have commented on the other discussion, but I haven't the point to that...

There is a way to solve this or to block the showing of the error message?

Thanks,

Drew

The problem seems to be that the answer there assumes the presence of chapters, which are of course present for tufte-book, but tufte-handout lacks them. Simply adapting the code there for the case of section as the higher sectioning level should do:

\documentclass{tufte-handout}
\usepackage{xcolor}
\usepackage{mdframed}
\usepackage{lipsum}

\newcounter{example}[section]
\newcommand\examplename{Example}
\newcommand\listexamplename{List of Examples}
\makeatletter
\newcommand\listofexamples{%
\section*{\listexamplename}%
%  \begin{fullwidth}%
\@starttoc{loe}%
%  \end{fullwidth}%
}

%\renewcommand\theexample{\ifnum \c@section>\z@ \thesection.\fi \@arabic\c@example} % this was adapted for the section case, but doesn't seem to be needed, given the sections are not numbered in the class by default. It would have an effect if the next line is uncommented and a section is added to the document.
%\setcounter{secnumdepth}{1}
\def\fps@example{tbp}
\def\ftype@example{1}
\def\ext@example{loe}
\def\fnum@example{\examplename\nobreakspace\theexample}
\newenvironment{example}[1][htbp]
{\begin{@tufte@float}[#1]{example}{}
{\end{mdframed}\end{@tufte@float}}
\makeatother

\begin{document}

\begin{example}
\caption{Currently, this caption is in the right margin similar to the table caption below.}
\lipsum[2]
\end{example}

\begin{table}
\caption{This is how I want the new float environment caption to behave.}
\centering
\begin{tabular}{llr}
Column 1 & Column 2 & Column 3 \\
Value A1 & Value A2 & Value A3 \\
\end{tabular}
\end{table}

\end{document}

• Thanks, this works beautifully. I had tried to change the code myself with the section option, but I hadn't edited and commented all the needed part! Thanks! Feb 28, 2018 at 21:14