2

I have the following problem: I want to use the same counter in a \newtheorem like

Code

\newtheorem{thm}{Theorem}[chapter]
\theoremseperator{\smallskip}
\newtheorem{prop}[thm]{Proposition}

as in the following mdframed theorem:

Code

\documentclass{book}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{calc}

\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}

\begin{document}

\chapter{Chapter}
\section{test}

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

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

\end{document}

How can I use the same counter as in the mdframed definitions? And how do you format the code in here? Do I really need to go to every line and type 4 spaces there? And there is another thing i would like to add in the mdframed Definition and in the theorems. It would be nice if i could do a quote there with the cite command of bibtex. Also i would like to add a title there if necessary: Something like "Definition 1.1 (Pythagorean Theorem) [Pyth03, Definition 6]". So i guess i need something like: ifempty, do nothing. if notempty insert this as a title of the definition / theorem etc.

It would be nice if you can show me how to solve this problem both for the mdframed definition and the \newtheorem theorem.

Thank you very much for your help

Tech.

  • It's not clear to me what the numbering schema should be. Lets' sat, do you want numbering per section or per chapter? Let's say, the first definition what number should receive? 1.1, for example, where the first 1 is the chapter and the second 1 is the number of the definition? Please clarify – Gonzalo Medina Sep 28 '15 at 15:59
  • Yes, the numbering should be 1.1 for the first definition of the chapter. 1.2 the next def. / theorem / lemma / ... of the chapter. I already changed the code. – Tech Sep 28 '15 at 16:19
  • Thanks. Then, I guess, my answer below, with the edit, does what you need? – Gonzalo Medina Sep 28 '15 at 16:23
  • Yeah. That's what i needed. The only thing that is missing is the citation. And the proposition theorem should inherit the theorem properties. I forgot to mention that it should be \newtheorem{thm}\theoremseperator{\smallskip}[chapter] and the skip should be there in the proposition too. I'll change that in the question. – Tech Sep 28 '15 at 16:29
  • Please, I told you to mention all requirements from the beginning. What do you need with the citation? I don't understand what you mean with this. Please clarify; I'm sure someone will answer your questions. – Gonzalo Medina Sep 28 '15 at 16:31
1
  1. You can use

    \newtheorem{thm}[mydef]{Theorem}
    \newtheorem{prop}[mydef]{Proposition}
    

so the thm and prop structures will share their counter with the mydef counter for definitions.

  1. You already have what you need. Simply use an optional argument with the myttile key, as in

    \begin{df}[mytitle=Pythagorean Theorem]
    test text
    \end{df}
    
  2. To have citations in the head of structures defined with \newtheorem, you can use the optional argument, as in

    \begin{thm}[See~\cite{test}]
    test theorem
    \end{thm}
    

In the case of the df environment defined with mdframed, you can use the mytitle key, as in

    \begin{df}[mytitle={Pythagorean Theorem, See~\cite[page 6]{test}}]
    test text
    \end{df}
  1. To easily format code blocks here, highlight the code and press Ctrl+K

The code:

\documentclass{book}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{calc}
\usepackage{amsthm}

\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}

\newtheorem{thm}[mydef]{Theorem}
\newtheorem{prop}[mydef]{Proposition}

\begin{document}

\chapter{Chapter}
\section{test}

\begin{df}[mytitle={Pythagorean Theorem, See~\cite[page 6]{test}}]
test text
\end{df}

\begin{thm}[See~\cite{test}]
test theorem
\end{thm}

\begin{prop}
test proposition
\end{prop}

\begin{thebibliography}{9}
\bibitem{test} Test
\end{thebibliography}

\end{document}

enter image description here

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.