1

In trying to answer this question, I thought it would be easy to add a new float environment using the float package. However, the labeling of the caption is not getting correctly formatted.

Because I'm creating a new float that I want labeled with a side caption, I dug into the sidecap package and created a new environment to match the new float.

Here's a MWE:

\documentclass{book}     

%% setting up new float
\usepackage{float}
\floatname{mySpecialFloat}{Special Float}
\newfloat{mySpecialFloat}{tbhp}{lst}[chapter]
\newcommand{\listofSpecialFloats}{\listof{mySpecialFloat}{List of Special Floats}}

%% setting up side captions
\usepackage[wide]{sidecap}                                      
\makeatletter
\@ifdefinable\SC@specialFloat@vpos{\def\SC@specialFloat@vpos{b}}
\newenvironment{SCspecialFloat}{\SC@float[\SC@specialFloat@vpos]{mySpecialFloat}}{\endSC@float}
\newenvironment{SCspecialFloat*}{\SC@dblfloat[\SC@specialFloat@vpos]{mySpecialFloat}}{\endSC@dblfloat}
\makeatother

%% setting up formatting for cpations
\usepackage
  [
    font=footnotesize,
    format=plain,
    labelfont={bf,sf},
    textfont={it},
    width=10pt
  ]{caption}

\usepackage{lipsum}
\pagestyle{empty}
\begin{document}
\listofSpecialFloats

\begin{mySpecialFloat}
  \centering
    Hello
  \caption[toc entry for hello]{Hello}
\end{mySpecialFloat}

\begin{SCspecialFloat}
\begin{minipage}[t]{\textwidth}
  \lipsum[1-2]
\end{minipage}
  \caption[toc entry for lipsum]{My caption content}
  \label{fig:src:01}
\end{SCspecialFloat}

\end{document}

which produces

enter image description here

What I find interesting is that everything seems to be working correctly. The listing command knows about all my special floats. The only thing that doesn't seem to be working correctly is the label for the caption for the side caption float.

I know this could be accomplished with newfloat, but I'm wondering what's happening here. Why is the label name getting lost in the sidecap environment?

UPDATE

There seems to be a conflict in naming conventions used by float and those expected by sidecap.

It seems this can be fixed if I add the following line to my code for setting up the captions:

\@namedef{mySpecialFloatname}{Special Float}
2

The caption package bundle resp. the newfloat package already offers this functionality since it defines an SC-variant automatically if the sidecap package is loaded:

\documentclass{book}     

%% setting up side captions
\usepackage[wide]{sidecap}                                      

%% setting up new float
\usepackage{newfloat}
\DeclareFloatingEnvironment
  [name={Special Float},listname={List of Special Floats},fileext=lst,placement=tbhp]
  {SpecialFloat}

%% setting up formatting for cpations
\usepackage
  [
    font=footnotesize,
    format=plain,
    labelfont={bf,sf},
    textfont={it},
    width=10pt
  ]{caption}

\usepackage{lipsum}
\pagestyle{empty}
\begin{document}
\listofSpecialFloats

\begin{SpecialFloat}
  \centering
    Hello
  \caption[toc entry for hello]{Hello}
\end{SpecialFloat}

\begin{SCSpecialFloat}
\begin{minipage}[t]{\textwidth}
  \lipsum[1-2]
\end{minipage}
  \caption[toc entry for lipsum]{My caption content}
  \label{fig:src:01}
\end{SCSpecialFloat}

\end{document}

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.