我正在使用 Tikz 创建漂亮的边注,例如 Gonzalo 对为边注创建一个框架环境 我使用“drop shadow =”为这些笔记添加了阴影,后面跟着颜色。效果很好。
但是,这些笔记有时包含 TikZ 图片,或使用 获得的绘图pgfplots
。但这些图形有阴影。有没有什么解决方案可以禁用内部 Tikz 图片的阴影?
pgfplots
下面是一个带有不必要阴影的边注内的代码示例:
\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}
答案1
我将定义一个\caution*
不应用阴影的。以下是使用\caution
和 的输出\caution*
:
代码:
\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}