2

Could you please help me with the following problem.

Code

\documentclass[a4paper,11pt]{scrreprt}
\usepackage{tikz}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{calc}
\usepackage{ntheorem}
\begin{document}
    \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}{%
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};
\else
   \node [excursus head] at ($(Q)+(2.5em,-0.75pt)$) {\mdf@digressiontitle:\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};
\else
   \node [excursus head] at ($(Q)+(2.5em,-0.75pt)$) {\mdf@digressiontitle:\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}{section}[section]

\chapter{Chapter}
\section{test}

\begin{df}
    TEXT!!!
\end{df}

\begin{df}
    TEXT 2!
\end{df}

\end{document}

I would like to number all the definitions like Definition 1.1, Definition 1.2 and so on. But i don't know how to do it correctly. Does anyone have an idea how to do it?

Best regards

tech.

PS: I'm new in stackexchange, so please apologize my coding in here.

3
  • Welcome to TeX.SX! Can you add the part before \begin{document} that makes the document compilable?
    – egreg
    Sep 28, 2015 at 13:24
  • Would answers with tcolorbox instead of mdframed also welcome?
    – Ignasi
    Sep 28, 2015 at 13:32
  • There you go, egreg.
    – Tech
    Sep 28, 2015 at 13:46

1 Answer 1

2

Here you go:

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

\newcounter{mydef}[section]
\renewcommand\themydef{\arabic{section}.\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}

enter image description here

Basically, all you had to do was to create a counter, prepend the section counter to it and use it after the header. The line

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

should have been

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

Using tcolorbox, however, your code looks simpler:

\documentclass{book}
\usepackage[most]{tcolorbox}

\tcbset{
mybox/.style={
  breakable,
  enhanced,
  boxrule=0pt,
  colframe=white,
  coltitle=white,
  coltitle=blue,
  colback=white,
  fonttitle=\sffamily\bfseries,
  frame code={},
  attach boxed title to top left={xshift=20pt},
  boxed title style={colback=white,frame code={},bottom=0pt,boxsep=0pt},
  overlay unbroken={
    \draw[line width=2pt,gray!40] (title.south east) -- ([xshift=-43pt]frame.east|-title.south east);
    \draw[line width=2pt,gray!40,rounded corners=2ex] 
    (title.south west) -| (frame.south west) -- ([xshift=50pt]frame.south west);
  },
  overlay first={
    \draw[line width=2pt,gray!40] (title.south east) -- ([xshift=-43pt]frame.east|-title.south east);
    \draw[line width=2pt,gray!40,rounded corners=2ex] 
    (title.south west) -| (frame.south west);
  },
    overlay middle={
    \draw[line width=2pt,gray!40] (frame.north west) -- (frame.south west);
  },
  overlay last={
    \draw[line width=2pt,gray!40,rounded corners=2ex] 
    (frame.north west) -| (frame.south west) -- ([xshift=50pt]frame.south west);
  }
 }
}

\newtcolorbox[auto counter]{tcbdf}{
  mybox,
  title=Definition~\thetcbcounter.\arabic{section}
}

\begin{document}

\chapter{Chapter}
\section{test}

\begin{tcbdf}
test text
\end{tcbdf}

\end{document}

enter image description here

8
  • Tcolorbox solutions are also welcome, of course.
    – Tech
    Sep 28, 2015 at 14:01
  • @Tech You're welcome! I added to my answer the translation of the original code to tcolorbox, in case you are interested in switching. Sep 28, 2015 at 14:07
  • Could you explain why there is an overlay middle and an overlay last? Or in the mdframed example: why do i need those second extra and middle extra and stuff? I haven't quite understood that.
    – Tech
    Sep 28, 2015 at 14:14
  • I have also defined some "new" theorems with
    – Tech
    Sep 28, 2015 at 14:42
  • @Tech because is a box has a page break, the fframe bahaves differently on the first part (where it begins), the last part (where it ends) and possibly in the middle part (pages in the middle). If page breaks are present, the first part should have the ending curve; the last part shouldn't have the title and the initial lines, etc. So you need to control the look of the box for the initial, last and middle parts. Sep 28, 2015 at 14:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .