1

I use the mdframed environment for my propositions / theorems and stuff. But now that i have done that the labeled theorems cannot be referenced in the text as in

Code

\documentclass[a4paper,11pt]{scrreprt}
\usepackage{tikz}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{calc}
\usepackage{ntheorem}

\newcounter{mydef}[chapter]
\renewcommand\themydef{\arabic{chapter}.\arabic{mydef}}

\makeatletter
    \def\mdf@mytitle{}
    \define@key{mdf}{mytitle}{%
      \def\mdf@mytitle{#1}}

    \mdf@do@stringoption{digressiontitle=={Digression}}

    \tikzset{
    excursus line/.style={%
    line width=2pt,
draw=gray!40,
rounded corners=2ex,
},
excursus head/.style={%
fill=white,
font=\bfseries\sffamily,
text=blue!80,
anchor=base west,
},
}
\mdfdefinestyle{digressionarrows}{%
extra={\stepcounter{mydef}},%
singleextra={%
\path let \p1=(P), \p2=(O) in (\x2,\y1) coordinate (Q);
\path let \p1=(Q), \p2=(O) in (\x1,{(\y1-\y2)/2}) coordinate (M);
\path [excursus line]
($(O)+(5em,0ex)$) -| (M) |- %
($(Q)+(30em,0ex)$);
%\node at ($(M)$) {M};
%\node [excursus head] at ($(Q)+(2.5em,-0.75pt)$) {Digression};},
\ifx\empty\mdf@mytitle\empty
   \node [excursus head] at ($(Q)+(2.5em,-0.75pt)$) {\mdf@digressiontitle~\themydef};
\else
   \node [excursus head] at ($(Q)+(2.5em,-0.75pt)$) {\mdf@digressiontitle~\themydef:\space\mdf@mytitle};
\fi},
firstextra={%
\path let \p1=(P), \p2=(O) in (\x2,\y1) coordinate (Q);
\path [excursus arrow,-to]
(O) |- %
($(Q)+(12em,0ex)$) .. controls +(0:16em) and +(185:6em) .. %
++(23em,2ex);
%\node [excursus head] at ($(Q)+(2.5em,-2pt)$) {Digression};},
\ifx\empty\mdf@mytitle\empty
   \node [excursus head] at ($(Q)+(2.5em,-0.75pt)$) {\mdf@digressiontitle~\themydef};
\else
   \node [excursus head] at ($(Q)+(2.5em,-0.75pt)$) {\mdf@digressiontitle~\themydef:\space\mdf@mytitle};
\fi},
secondextra={%
\path let \p1=(P), \p2=(O) in (\x2,\y1) coordinate (Q);
\path [excursus arrow,round cap-]
($(O)+(5em,0ex)$) -| (Q);},
middleextra={%
\path let \p1=(P), \p2=(O) in (\x2,\y1) coordinate (Q);
\path [excursus arrow]
(O) -- (Q);},
middlelinewidth=2.5em,middlelinecolor=white,
hidealllines=true,topline=true,
innertopmargin=0.5ex,
innerbottommargin=2.5ex,
innerrightmargin=2pt,
innerleftmargin=2ex,
skipabove=0.87\baselineskip,
skipbelow=0.62\baselineskip,
}
\makeatother

\newmdenv[style=digressionarrows,digressiontitle=Definition]{df}
\newmdenv[style=digressionarrows,digressiontitle=Proposition]{prop}


\begin{document}

\chapter{Chapter}
\section{test}

\begin{df}[mytitle = Pythagoraen Theorem]
test text
\label{pythag}
\end{df}

In the pythagoraen theorem there are $a,b$ and $c$ such that $a^2+b^2 = c^2$ (see \ref{pythag}).

\begin{df}
test text.
\end{df}

\begin{prop}[Proposition bla]
    blablab.
    \label{propbla}
\end{prop}

In proposition \ref{propbla} there are things.

\end{document}

What am I doing wrong here? Thank you in advance.

Tech

1

Got it! I got rid of the "extra" entry in the mfdefinestyle and added

settings = \refstepcounter{mydef}

in the \newmdenv options. Then the references in the text work as they should work.

\documentclass[a4paper,11pt]{scrreprt}
\usepackage{tikz}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{calc}
\usepackage{ntheorem}

\newcounter{mydef}[chapter]
\renewcommand\themydef{\thechapter.\arabic{mydef}}

\makeatletter
    \def\mdf@mytitle{}
    \define@key{mdf}{mytitle}{%
      \def\mdf@mytitle{#1}}

    \mdf@do@stringoption{digressiontitle=={Digression}}

    \tikzset{
    excursus line/.style={%
    line width=2pt,
draw=gray!40,
rounded corners=2ex,
},
excursus head/.style={%
fill=white,
font=\bfseries\sffamily,
text=blue!80,
anchor=base west,
},
}
\mdfdefinestyle{digressionarrows}{%
%extra={\refstepcounter{mydef}},%
singleextra={%
\path let \p1=(P), \p2=(O) in (\x2,\y1) coordinate (Q);
\path let \p1=(Q), \p2=(O) in (\x1,{(\y1-\y2)/2}) coordinate (M);
\path [excursus line]
($(O)+(5em,0ex)$) -| (M) |- %
($(Q)+(30em,0ex)$);
%\node at ($(M)$) {M};
%\node [excursus head] at ($(Q)+(2.5em,-0.75pt)$) {Digression};},
\ifx\empty\mdf@mytitle\empty
   \node [excursus head] at ($(Q)+(2.5em,-0.75pt)$) {\mdf@digressiontitle~\themydef};
\else
   \node [excursus head] at ($(Q)+(2.5em,-0.75pt)$) {\mdf@digressiontitle~\themydef:\space\mdf@mytitle};
\fi},
firstextra={%
\path let \p1=(P), \p2=(O) in (\x2,\y1) coordinate (Q);
\path [excursus arrow,-to]
(O) |- %
($(Q)+(12em,0ex)$) .. controls +(0:16em) and +(185:6em) .. %
++(23em,2ex);
%\node [excursus head] at ($(Q)+(2.5em,-2pt)$) {Digression};},
\ifx\empty\mdf@mytitle\empty
   \node [excursus head] at ($(Q)+(2.5em,-0.75pt)$) {\mdf@digressiontitle~\themydef};
\else
   \node [excursus head] at ($(Q)+(2.5em,-0.75pt)$) {\mdf@digressiontitle~\themydef:\space\mdf@mytitle};
\fi},
secondextra={%
\path let \p1=(P), \p2=(O) in (\x2,\y1) coordinate (Q);
\path [excursus arrow,round cap-]
($(O)+(5em,0ex)$) -| (Q);},
middleextra={%
\path let \p1=(P), \p2=(O) in (\x2,\y1) coordinate (Q);
\path [excursus arrow]
(O) -- (Q);},
middlelinewidth=2.5em,middlelinecolor=white,
hidealllines=true,topline=true,
innertopmargin=0.5ex,
innerbottommargin=2.5ex,
innerrightmargin=2pt,
innerleftmargin=2ex,
skipabove=0.87\baselineskip,
skipbelow=0.62\baselineskip,
}
\makeatother

\newmdenv[style=digressionarrows, settings = \refstepcounter{mydef}, digressiontitle=Definition]{df}
\newmdenv[style=digressionarrows, settings = \refstepcounter{mydef}, digressiontitle=Proposition]{prop}


\begin{document}

\chapter{Chapter}
\section{test}

\begin{df}[mytitle = Pythagoraen Theorem]
test text
\label{pythag}
\end{df}

In the pythagoraen theorem there are $a,b$ and $c$ such that $a^2+b^2 = c^2$ (see \ref{pythag}).

\begin{df}
test text.
\end{df}

\begin{prop}
    blablab.
    \label{propbla}
\end{prop}

In proposition \ref{propbla} there are things.

\end{document}
|improve this answer|||||

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.