阴影使用变换画布,因此节点的阴影不在图片边界框内。如果我想从文本区域的左边界到右边界绘制一个节点,这样阴影就不会溢出文本边界,我需要减少节点宽度以适应尺寸shadow xshift
。我想知道,如何在节点样式的定义中获得它的大小。
到目前为止我尝试了以下方法:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,
shadows}
%------------- show page layout. don't use this in real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
\vspace*{5ex}
\noindent\begin{tikzpicture}[
DS/.style args = {#1/#2}{drop shadow={fill=orange,
shadow xshift=#1,
shadow yshift=#2}
},
A/.style = {draw, fill=yellow!30, % my node
text width=\linewidth-2*\pgfkeysvalueof{/pgf/inner xsep}% this work
- \pgfkeysvalueof{/tikz/shadow xshift},% this doesn't provide shadow xshift size
align=center,
},
]
\node (a) [DS=12pt/-4pt, inner sep=12 pt, A] {my annotated text};
\end{tikzpicture}
\end{document}
这使:
如您所见,我的尝试没有成功。问题是,使用时哪里出了错误\pgfkeysvalueof{...}
。我在使用时是否\pgfkeysvalueof{...}
遗漏了什么,或者我尝试确定的大小是否shadow xshift
不正确?
或者我的期望是,通过这种方式有可能获得shadow xshift
天真的尺寸?
答案1
作为一种解决方法,您也许可以使用将样式.store in
保存到宏中,然后在中使用该宏。#2
DS
A
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,
shadows}
%------------- show page layout. don't use this in real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
\vspace*{5ex}
\noindent\begin{tikzpicture}[
DS/.style args = {#1/#2}{drop shadow={fill=orange,
shadow xshift=#1,
shadow yshift=#2},
shadowshift/.store in=\SXShift,
shadowshift=#1
},
A/.style = {draw, fill=yellow!30, % my node
text width=\linewidth-2*\pgfkeysvalueof{/pgf/inner xsep}% this work
- \SXShift,
align=center,
},
]
\node (a) [DS=12pt/-4pt, inner sep=12 pt, A] {my annotated text};
\end{tikzpicture}
\end{document}