2

I have the following code, which works fine when package caption is inactive. However with caption the title of the "steckbrief" moves out of the box. What is it that caption changes that the title moves to the outside?

I had previously the boxedminipae environment gone into the \fs@my block but that produced overfull boxes. Removing the \fs@my block puts the caption below the factsheet.

Any help appreciated.

Kind regards

Bernhard

(this has been asked on comp.text.tex without any answer.)

    \documentclass[fontsize=10pt,twoside,draft]{scrbook}
\usepackage[english,ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\selectlanguage{ngerman}
\usepackage[a4paper,textwidth=13.5cm,textheight=22cm]{geometry}
\usepackage{calc,boxedminipage2e,float, capt-of}
%\usepackage{caption}
\makeatletter
\newcommand\fs@my{%Caption im Rahmen
\let\@fs@capt\floatc@plain
\let\@fs@iftopcapt\iftrue%
\def\@fs@mid{}%
\def\@fs@pre{}%
\def\@fs@post{}%
}
\floatstyle{my}
\newfloat{factsheet}{hbtp}{los} % Steckbrief, Factsheet
\floatname{factsheet}{Factsheet}
\newlength{\figurewidth}\setlength{\figurewidth}{11.5cm}
\newcounter{stbr}
\newenvironment{FS}[3]%factsheet
{\begin{boxedminipage}{1\figurewidth}\centering%begindef
\captionof{figure}{\textbf{#2}}\label{fs:#3}%
\refstepcounter{stbr}
\begin{list}{}%
{\renewcommand\makelabel[1]{\bfseries\footnotesize{##1}\hfil}%
\settowidth\labelwidth{\makelabel{#1}}%
\setlength\leftmargin{\labelwidth+\labelsep}\footnotesize}% 
}
{  \end{list}%enddefinition
 \end{boxedminipage}%
}
\makeatother
\begin{document}
\begin{factsheet*}[b!]
\centering
\begin{FS}{Bildung und Ziel}%
 {Thyrotropin"=Releasing Hormon}{trh}
\item [Gen]Chromosom: 3; Genort: 3q13.3-q21
\item [Sequenz]\textbf{p{EHP}-NH$_2$}
\item [Bildung und Ziel] TRH wird vor allem im{PVN} gebildet...
\end{FS}
\end{factsheet*}
\end{document}
  • Your example does not compile – user31729 Jan 17 '16 at 10:03
  • it does now, sorry – Bernhard Kleine Jan 17 '16 at 10:12
  • it looks the same but is not, in that topic it was the overfull boxes, which here are avoided. Here it is a strange behaviour of caption that I donot understand and which has not been answered in the comp.text.tex newsgroup. – Bernhard Kleine Jan 17 '16 at 14:34
  • What exactly are you trying to do? If you want this to be a new type of float, then why would you want the caption to be as if it was a figure? caption is sensitive to this kind of new float, and therefore tries to do the right thing. But that assumes that what you are asking it to do makes sense. Here, it really doesn't. – cfr Jan 17 '16 at 22:58
2

Without caption package, \captionof{figure} simply expands to \def\@captype{figure}\caption. \caption has been redefined by the float package. The float package author has decided to make this redefinition globally. (A different approach would be redefining \caption only inside own environments.) Since the redefinition is globally, the new code of \caption needs something to detect if it was called within a float controlled by the float package or not. It uses the following code:

\ifx \csname @float@c@\@captype \endcsname \relax
% no environment of the float package
\else
% environment controlled by the float package
\fi

So what happens when compiling your code? The environment factsheet starts. \captionof is used which changes \@captype from factsheet to figure and uses \caption afterwards. \caption checks for \ifx \csname @float@c@\@captype \endcsname \relax which is true since \@captype was redefined from factsheet to figure and figure is not controlled by the float package. So the float package thinks it's not responsible for this caption and therefore the ordinary caption code will be used. As result the caption will be typeset inside the box and there is no caption outside the box since the float package behaves as there was no \caption inside factsheet at all.

In total your code uses the following undocumented(!) facts:

  1. \caption is redefined by the float package globally
  2. \caption uses \@captype to distinguish between ordinary floating environments and ones controlled by the float package

If the implementation of the float package would differ in only one of these two points your caption would be typeset outside the box, since this is the documented(!) way the float package operates. The only reason why it's typeset inside the box (which is the unexpected behaviour!) is that using \captionof makes the check of the float package doomed to fail. (Try using \caption instead of \captionof and you'll see that the caption won't be inside the box either.)

Remember: You have even told the float package where to put captions of factsheet: \let\@fs@iftopcapt\iftrue which means "Typeset the caption on top of the float body".

If you don't want the caption to be typeset outside the float body, one could use the documented(!) way to tell this to the float package:

There is a \restylefloat* command which will restyle an existing float type but will keep the new float style from taking over the \caption command. In this case the user is responsible for handling their own captions.

So adding \restylefloat*{factsheet} right after \newfloat{factsheet}... is the documented way to tell the float package that you would like to typeset the caption inside the float body and not outside.

So far I have answered the question "Why is the caption typeset inside the box which is opposite to the documented and therefore expected behavior of the float package?". Now I would like to answer "Why is the caption without caption package within the box and with caption outside?". Well that's an easy one. Since the caption package redefines \caption as well it cannot emulate every internal implementation detail of the float package (and all the other packages the new \caption code has to work with). Instead it tries to emulate the documented behavior of the packages (or as cfr has expressed it in the comments above: "tries to do the right thing"), which means in your case: "Typeset the caption outside the float body, on top of it."

So when adding \restylefloat*{factsheet} you should see the same behavior with and without caption package.

BTW: Why are you defining factsheet anyway, why don't you simply use figure and \caption instead of factsheet and \captionof{figure}?

  • 1
    Thank you! factsheets are supposed to contain condensed information in my book about a hormone and a hormone building enzyme, figures are for illustrations – Bernhard Kleine Jan 26 '16 at 11:57
  • When you change \def\@fs@pre{}% \def\@fs@post{}% to \def\@fs@pre{\setlength{\fboxsep}{2pt}\begin{boxedminipage}[t][\relax][c]{0.96\linewidth}}% \def\@fs@post{\end{boxedminipage}} than you see that the outer box is to large by some pt. I have difficulties to understand this. I have already asked Scott Pakin and I also has no idea. I would appreciate if you have a solution for this problem. Bernhard – Bernhard Kleine Jan 27 '16 at 15:22
  • @BernhardKleine I will take a look at it at Saturday, and report. – Axel Sommerfeldt Jan 28 '16 at 19:54
  • @BernhardKleine When I add \restylefloat*{factsheet} and make your code changes, I get no difference between "without caption package" and "with caption package". What difference do you get? – Axel Sommerfeldt Jan 31 '16 at 12:38
  • sorry I dit not see your comment. I will check and come back – Bernhard Kleine Feb 9 '16 at 18:24

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.