![如何在节点样式定义中获取“shadow xshift”的大小?](https://linux22.com/image/371990/%E5%A6%82%E4%BD%95%E5%9C%A8%E8%8A%82%E7%82%B9%E6%A0%B7%E5%BC%8F%E5%AE%9A%E4%B9%89%E4%B8%AD%E8%8E%B7%E5%8F%96%E2%80%9Cshadow%20xshift%E2%80%9D%E7%9A%84%E5%A4%A7%E5%B0%8F%EF%BC%9F.png)
阴影使用变换画布,因此节点的阴影不在图片边界框内。如果我想从文本区域的左边界到右边界绘制一个节点,这样阴影就不会溢出文本边界,我需要减少节点宽度以适应尺寸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}