3

I am using Tikz to create nice margin notes, like Gonzalo's answer to create a framed environment for a margin note I added a shadow to these notes with `drop shadow =' followed by a color. It works just fine.

However, these notes sometimes contain a TikZ picture, or a plot obtained with pgfplots. But theses figures then have a shadow. Is there any solution to disable the shadow for the inner Tikz picture ?

Here is an example of code with a pgfplots inside a margin note with unwanted shadow :

\documentclass{article}
\usepackage[lmargin=5cm,textwidth=15cm,marginparwidth=4cm]{geometry}
\usepackage[dvipsnames]{xcolor}
\usepackage{ragged2e}
\usepackage{xparse}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}
\usepackage{lipsum}
\usetikzlibrary{shadows}
\usepackage{pgfplots}

\newcounter{mycaution}
\newcommand\pointeranchor{}
\newcommand\boxanchor{}
\newlength\boxvshift
\newlength\uppertrianglecorner

\newcommand\tikzmark[1]{%
  \tikz[remember picture,overlay]\node[inner xsep=0pt,outer sep=0pt] (#1) {};}

\NewDocumentCommand{\caution}{O{c}O{BrickRed}O{Caution!}m}{%
\stepcounter{mycaution}%
\tikzmark{\themycaution}%
\renewcommand\pointeranchor{mybox\themycaution.east}%
\renewcommand\boxanchor{east}%
\setlength\boxvshift{0pt}%
\setlength\uppertrianglecorner{3pt}%
\begin{tikzpicture}[remember picture,overlay]
\node[draw=#2,anchor=\boxanchor,xshift=-\marginparsep,yshift=\boxvshift,drop shadow=#2!80!black!50!white,fill=white]   
  (mybox\themycaution)
  at ([yshift=3pt]current page text area.west|-\themycaution) 
  {\parbox{\marginparwidth}{\vskip10pt\RaggedRight\small#4}};
\node[fill=white,font=\color{#2}\sffamily,anchor=west,xshift=7pt]
  at (mybox\themycaution.north west) {\ #3\ };
\end{tikzpicture}%
}

\newcommand\Test{Nulla malesuada porttitor diam. Donec felis erat, congue non, volutpat at, tincidunt tristique, libero. Vivamus viverra fermentum felis. Donec nonummy pellentesque ante. Phasellus adipiscing
semper elit.}

\begin{document}

\lipsum*[4]\caution[t]{\begin{tikzpicture}[]
\begin{axis}[xmin=-1,xmax=2,ymin=0.4,ymax=1.5,width=\marginparwidth,axis lines=middle,xtick=1,xticklabels=$a$,ytick=\empty]
\addplot[red,mark=none,domain=-1:1]{1};
\addplot[red,mark=none,domain=1:2]{x-0.5};
\end{axis}
\end{tikzpicture}}\lipsum[3]\par

\end{document}

Which produces this : enter image description here

5
  • Box the pgfplots or the tikzpicture before puting it in the margin note. Aug 18, 2015 at 18:04
  • 1
    Can you please add a complete, little dummy document showing how exactly are you adding the shadow and a pgfplots inheriting it? Aug 18, 2015 at 18:07
  • @Gonzalo : I added an example.
    – mvienney
    Aug 19, 2015 at 6:09
  • What version of pgf do you use? I can't reproduce your result. On my computer (pgf 3.0.0), disabling tikzpagenodes (I don't have it), there is no shadow for the plots. Aug 19, 2015 at 11:43
  • @TonioElGringo : I am using 3.0.1.
    – mvienney
    Aug 20, 2015 at 16:37

1 Answer 1

2

I would define a \caution* which does not apply the shadow. Here is the output using \caution and \caution*:

enter image description here

Code:

\documentclass{article}
\usepackage[lmargin=5cm,textwidth=15cm,marginparwidth=4cm]{geometry}
\usepackage[dvipsnames]{xcolor}
\usepackage{ragged2e}
\usepackage{xparse}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}
\usepackage{lipsum}
\usetikzlibrary{shadows}
\usepackage{pgfplots}

\newcounter{mycaution}
\newcommand\pointeranchor{}
\newcommand\boxanchor{}
\newlength\boxvshift
\newlength\uppertrianglecorner

\newcommand\tikzmark[1]{%
  \tikz[remember picture,overlay]\node[inner xsep=0pt,outer sep=0pt] (#1) {};}

\NewDocumentCommand{\caution}{sO{c}O{BrickRed}O{Caution!}m}{%
    \stepcounter{mycaution}%
    \tikzmark{\themycaution}%
    \renewcommand\pointeranchor{mybox\themycaution.east}%
    \renewcommand\boxanchor{east}%
    \setlength\boxvshift{0pt}%
    \setlength\uppertrianglecorner{3pt}%
    \IfBooleanTF{#1}{%
        \tikzset{shadow options/.style={}}
    }{%
        \tikzset{shadow options/.style={drop shadow=#3!80!black!50!white}}
    }%
    \begin{tikzpicture}[remember picture,overlay]
    \node[draw=#3,anchor=\boxanchor,xshift=-\marginparsep,yshift=\boxvshift,shadow options,fill=white]   
      (mybox\themycaution)
      at ([yshift=3pt]current page text area.west|-\themycaution) 
      {\parbox{\marginparwidth}{\vskip10pt\RaggedRight\small#5}};
    \node[fill=white,font=\color{#3}\sffamily,anchor=west,xshift=7pt]
      at (mybox\themycaution.north west) {\ #4\ };
    \end{tikzpicture}%
}

\newcommand\Test{Nulla malesuada porttitor diam. Donec felis erat, congue non, volutpat at, tincidunt tristique, libero. Vivamus viverra fermentum felis. Donec nonummy pellentesque ante. Phasellus adipiscing
semper elit.}

\newcommand{\CautionTikz}{%
    \begin{tikzpicture}[]
    \begin{axis}[xmin=-1,xmax=2,ymin=0.4,ymax=1.5,width=\marginparwidth,axis lines=middle,xtick=1,xticklabels=$a$,ytick=\empty]
    \addplot[red,mark=none,domain=-1:1]{1};
    \addplot[red,mark=none,domain=1:2]{x-0.5};
    \end{axis}
    \end{tikzpicture}%
}%

\begin{document}

\lipsum*[3]%
\caution[t]{\CautionTikz}%
\par
\lipsum*[3]%
\caution*[t]{\CautionTikz}%
\lipsum[3]

\end{document}

You must log in to answer this question.

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