Update: To let mdframed
know the right dimensions of the frame to calculate the page breaks we must give them as invisible margins (middleline
) and adjust everything according to these. See the updated code below.
Marco’s comment lead me to the relevant parts in the manual. Here is my code
\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{calc,arrows}
\usepackage{etoolbox}
\usepackage[framemethod=tikz]{mdframed}
\tikzstyle{excursus arrow}=[%
line width=4pt,
draw=blue,
rounded corners=2ex
]
\tikzstyle{excursus head}=[%
fill=white,
font={\bfseries\sffamily},
text=blue,
anchor=base,
]
\makeatletter
\newcommand{\drawexcursusarrow}{%
\patchcmd{\mdf@putbox@single}{\mdfcreateextratikz}{
\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 arrow, round cap->]
($(O)+(5em,0ex)$) -| (M) |- %
($(Q)+(6em,0ex)$) .. controls +(0:16em) and +(185:6em) .. %
++(23em,2ex);
\node [excursus head] at ($(Q)+(4.5em,-2pt)$) {Excursus};
}{}{}%
\patchcmd{\mdf@putbox@first}{\mdfcreateextratikz}{
\path let \p1=(P), \p2=(O) in (\x2,\y1) coordinate (Q);
\path [excursus arrow,->]
(O) |- %
($(Q)+(6em,0ex)$) .. controls +(0:16em) and +(185:6em) .. %
++(23em,2ex);
\node [excursus head] at ($(Q)+(4.5em,-2pt)$) {Excursus};
}{}{}%
\patchcmd{\mdf@putbox@second}{\mdfcreateextratikz}{
\path let \p1=(P), \p2=(O) in (\x2,\y1) coordinate (Q);
\path [excursus arrow,round cap-]
($(O)+(5em,0ex)$) -| (Q);
}{}{}%
\patchcmd{\mdf@putbox@middle}{\mdfcreateextratikz}{
\path let \p1=(P), \p2=(O) in (\x2,\y1) coordinate (Q);
\path [excursus arrow]
(O) -- (Q);
}{}{}%
}
\makeatother
\newmdenv[%
middlelinewidth=24pt,
middlelinecolor=green,
rightline=false,
innertopmargin=0ex,
innerbottommargin=0ex,
innerrightmargin=2pt,
innerleftmargin=0ex,
leftmargin=-11pt,
skipabove=12pt,
skipbelow=-1pt,%=12-24/2-2/2
settings=\drawexcursusarrow,
]{excursus}
\usepackage{lipsum}
\begin{document}
\lipsum[3]
\begin{excursus}
\lipsum[1]
\end{excursus}
\lipsum[3]
\end{document}
I used \pathcmd
to differentiate between the broken and unbroken frames. Furthermore I draw the arrow with \drawexcursusarrow
and apply this via the settings
key only to the {excursus}
environment, so my changes don’t effect the other frames.
Bonus question
is it possible to let mdframed
ignore the descenders of the last line in the frame? Otherwise the (optical) innerbottomsep
depends on these.
You have to understand the calculation of the arc by TikZ. This is important because mdframed
has no extra modification for the inner arc. Of course I can implement it.
Let's take the following mwe:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[line width=2ex,rounded corners = 1ex] (0,0) rectangle (7,4);
\end{tikzpicture}
\end{document}
The line width is 2ex
and the arc is 1ex
. The result is:
As you can see the inner arc isn't there. If you you increase rounded corners
greater than 2ex
you will get:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[line width=2ex,rounded corners = 3ex] (0,0) rectangle (7,4);
\end{tikzpicture}
\end{document}
Related to your example: Your are using innerlinewidth=0.1em
, middlelinewidth=1.0em
and outerlinewidth=0.1em
which leads to the width 1.2em
. On the other hand you are specifying roundcorner=0.5em
. As explained 0.5em
is too small.
So you can either use a greater dimension for roundcorner
or you redefine some internal commands to specify an inner arc.
Best Answer
@DavidCarlisle was correct. MikTeX was installed containing all required packages, but TinyTeX had also been installed, and Rmarkdown was choosing the latter. Errors pointed to
\tikz
/mdframed
because the first piece of code run called those packages, but in reality TinyTeX may have had none of the packages I needed.Problem was solved by
tinytex::uninstall_tinytex()
.I also subsequently ran
remove.packages("tinytex")
. Note the order here is important!).Note the distinction between
tinytex
andTinyTeX
:TinyTeX
is a LaTeX installation (just like MikTeX, ...) which can be run without R, whereastinytex
is an R package which provides easy use/installation/package management ofTinyTeX
.