Mdframed 和 newtheorems 在标题中具有相同的计数器和引号

Mdframed 和 newtheorems 在标题中具有相同的计数器和引号

我有以下问题:我想在 \newtheorem 中使用相同的计数器,例如

代码

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

如下面 mdframed 定理所示:

代码

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

我如何使用与 mdframed 定义中相同的计数器?您如何格式化这里的代码?我真的需要转到每一行并在那里输入 4 个空格吗?还有一件事我想在 mdframed 定义和定理中添加。如果我可以使用 bibtex 的 cite 命令在那里引用,那就太好了。此外,如果有必要,我想在那里添加一个标题:类似于“定义 1.1(勾股定理)[Pyth03,定义 6]”。所以我想我需要类似的东西:ifempty,什么也不做。如果 notempty,将其作为定义/定理等的标题插入。

如果您能向我展示如何解决 mdframed 定义和 \newtheorem 定理的这个问题,那就太好了。

非常感谢您的帮助

技术。

答案1

  1. 您可以使用

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

因此thmprop结构将与定义的计数器共享它们的计数器mydef

  1. 您已经拥有了所需的一切。只需使用带有键的可选参数myttile,例如

    \begin{df}[mytitle=Pythagorean Theorem]
    test text
    \end{df}
    
  2. 要在用 定义的结构头部进行引用\newtheorem,可以使用可选参数,例如

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

对于df使用 定义的环境mdframed,您可以使用 mytitle 键,如下所示

    \begin{df}[mytitle={Pythagorean Theorem, See~\cite[page 6]{test}}]
    test text
    \end{df}
  1. 要在此处轻松格式化代码块,请突出显示代码并按Ctrl+K

代码:

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

在此处输入图片描述

相关内容