In the linked question the page frame is drawn in the footer. Moving the page frame into the header instead will change the order and should display the frame before, i.e. below, the text.
To give an explanation: As far I know the page is processed the following way: The main text is typeset and TeX collects a page worth of text. It then places the header on the page, followed by the already processed text and finally adds the footer. So material in the footer is placed above the text while material in the header is placed below it. It surprises me that the code in the linked question works as it is.
The chamfered rectangle
shape uses the height, depth and width of the node’s text box as well as the inner separator to compute its path (as every other shape).
This can be simulated with a normal node with inner sep
set to zero (the spy nodes use this too):
\tikz
\node[draw, chamfered rectangle, minimum width=2cm, minimum height=1cm, inner sep=0pt] {};
So, the next idea would be to include an inner sep
again in the every spy on node
as well as the every spy in node
.
My other solution provides a specific fix for the chamfered rectangle
which will use the minimum height
and minimum width
as a replacement for the text box.
The yellow box shows in both solutions where the 2cm × 1cm
will be measured.
Code A (inner sep
)
\documentclass[tikz,convert=false]{standalone}
\usetikzlibrary{spy,decorations.fractals,shapes.misc}
\begin{document}
\begin{tikzpicture}[
spy using outlines={
shape=chamfered rectangle,
every spy on node/.append style={inner sep=+.3333em},
every spy in node/.append style={inner sep=+.3333em},
magnification=3,
width=2cm,
height=1cm,
connect spies
}]
\draw [decoration=Koch curve type 1]
decorate{ decorate{ decorate{ (0,0) -- (2,0) }}};
\spy[red] on (1.6,0.3) in node at (3,1);
\node[draw=green, thick, minimum width=2cm/3, minimum height=1cm/3] at (1.6,.3) {};
\end{tikzpicture}
\end{document}
Code B (specific fix)
\documentclass[tikz,convert=false]{standalone}
\usepackage{etoolbox}
\usetikzlibrary{spy,decorations.fractals,shapes.misc}
\makeatletter
\newif\iftikz@lib@spy@active
\expandafter\patchcmd\csname pgfk@/tikz/spy scope/.@cmd\endcsname
{\copy\tikz@lib@spybox\tikz@lib@spy@collection}
{\copy\tikz@lib@spybox\tikz@lib@spy@activetrue\tikz@lib@spy@collection}{}{}
\expandafter\patchcmd\csname pgf@sh@s@chamfered rectangle\endcsname{%
\pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/inner xsep}}%
\advance\pgf@xa.5\wd\pgfnodeparttextbox%
\pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/inner ysep}}%
\advance\pgf@ya.5\ht\pgfnodeparttextbox%
\advance\pgf@ya.5\dp\pgfnodeparttextbox%
}{%
\pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/inner xsep}}%
\pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/inner ysep}}%
\iftikz@lib@spy@active
\pgfmathaddtolength\pgf@xa{.5*(\pgfkeysvalueof{/pgf/minimum width}-2*(\pgfkeysvalueof{/pgf/chamfered rectangle xsep}))}%
\pgfmathaddtolength\pgf@ya{.5*(\pgfkeysvalueof{/pgf/minimum height}-2*(\pgfkeysvalueof{/pgf/chamfered rectangle ysep}))}%
\else
\advance\pgf@xa.5\wd\pgfnodeparttextbox%
\advance\pgf@ya.5\ht\pgfnodeparttextbox%
\advance\pgf@ya.5\dp\pgfnodeparttextbox%
\fi}{}{}
\makeatother
\begin{document}
\begin{tikzpicture}[
spy using outlines={
shape=chamfered rectangle,
magnification=3,
width=2cm,
height=1cm,
connect spies
}]
\draw [decoration=Koch curve type 1]
decorate{ decorate{ decorate{ (0,0) -- (2,0) }}};
\spy[red] on (1.6,0.3) in node at (3,1);
\node[draw=green, thick, minimum width=2cm/3, minimum height=1cm/3] at (1.6,.3) {};
\end{tikzpicture}
\end{document}
Output (both)
![enter image description here](https://i.stack.imgur.com/1WDos.png)
Best Answer
Here's a quick solution. It can be made more customizable, probably to incorporate
pgfkeys
for key-value options.Code
Output
Edit 1: Oh, you wanted the inverse gradient. Here are both variants, with more things to tweak to your liking:
Code
Output
Edit 2: Fixed a problem with the border width computation:
Code
Output