2

I defined a new theorem with the ntheorem package. If i want to add a label to a certain theorem i get an error from the caption package. And referencing doesn't work.

Package caption Warning: \label without proper \caption on input line 170.
See the caption package documentation for explanation.


LaTeX Warning: Reference `def:edge-factor' on page 11 undefined on input line 310.

The theorem looks like this:

\begin{mydef}[Edge-Weight]
    \label{def:edge-weight}
    [...]
\end{mydef}

The caption is set as an environment variable. How could i get a proper label without adding an additional caption? Minimal Example

\documentclass[pdftex,a4paper, twoside]{scrreprt}
\usepackage{caption}

\usepackage{newfloat}
\usepackage[standard, hyperref]{ntheorem}

\DeclareFloatingEnvironment[fileext=frm,placement={H},name=Definition, listname={List of Definitions}]{deffloat}
\theoremstyle{break}
\theoremsymbol{\ensuremath{\clubsuit}}
\theoremseparator{:}
\theoremprework{\begin{deffloat}[H]}
\theorempostwork{\end{deffloat}}
\newtheorem{mydef}{Definition}[chapter]

\begin{document}

\begin{mydef}[Edge-Factor] \label{def:edge-factor}
    Definition
\end{mydef}

Text \ref{def:edge-factor}

\end{document}

While checking the Example i got to know its because the new float environment.

  • 1
    erhm, I cannot see the proper context for \caption here. So please provide a minimal example, i.e. a small document (as small as possible), that include preamble etc. that we can just copy'n'paste and verify on own own systems. – daleif May 22 '14 at 11:25
2

Since you are already loading the caption package, you can use \phantomcaption to generate the anchor needed without using \caption:

\documentclass[pdftex,a4paper, twoside]{scrreprt}
\usepackage{caption}

\usepackage{newfloat}
\usepackage[standard, hyperref]{ntheorem}

\DeclareFloatingEnvironment[fileext=frm,placement={H},name=Definition, listname={List of Definitions}]{deffloat}
\theoremstyle{break}
\theoremsymbol{\ensuremath{\clubsuit}}
\theoremseparator{:}
\theoremprework{\begin{deffloat}[H]}
\theorempostwork{\end{deffloat}}
\newtheorem{mydef}{Definition}[chapter]

\begin{document}

\begin{mydef}[Edge-Factor]
\phantomcaption
\label{def:edge-factor}
Definition
\end{mydef}

Text~\ref{def:edge-factor}

\end{document}

Notice, however that now you have another issue: the counters are not in synchrony since now the cross-reference to the definition picks up the string formed by the float counter, which doesn't follow the numbering scheme from the definitions; in the example code above the definition is numbered "0.1" (0 for the value of the chapter counter) whereas the cross-reference is just "1". You'll need to make provision to keep the counters synchronous.

It's not clear to me, however, why you surround your definition environment with a float; definitions might then float away and possibly appear after the point in which they are needed, not to mention the other problems already discussed. If all you need is the possibility of a list, the ntheorem package already offers this feature.

Now that in a comment it has been mentioned that the reason behind the float is just to prevent definitions from allowing page breaks, a better alternative is to enclose the definitions inside a minipage; in this way, everything will work as expected without additional work:

\documentclass[a4paper, twoside]{scrreprt}
\usepackage{caption}
\usepackage[standard, hyperref]{ntheorem}

\theoremstyle{break}
\theoremsymbol{\ensuremath{\clubsuit}}
\theoremseparator{:}
\theoremprework{\vskip\topsep\par\noindent\begin{minipage}{\linewidth}}
\theorempostwork{\end{minipage}\par\vskip\topsep}
\newtheorem{mydef}{Definition}[chapter]

\begin{document}

\begin{mydef}[Edge-Factor]
\label{def:edge-factor}
Definition
\end{mydef}

Text~\ref{def:edge-factor}

\end{document}
  • I don't really need the float, specially since i use it with positioning 'H'. I wanted to avoid that a definition is broken over two pages. And a minipage solution seemed not good for me. – zeroset May 22 '14 at 13:28
  • @zeroset I see. However, there's still a problem with the counters that you will need to take care of (see the comments I've added to my answer). I'd suggest you to use the minipage approach instead (as in the last example code in my answer). – Gonzalo Medina May 22 '14 at 13:49

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.