4

drop shadows use transform canvas, consequently node's shadow is not inside picture bounding box. if i like to draw a node from left to right border of the tex area such, that shadow not spill out of text border, i need to reduce node width for amount of shadow xshift size. I wonder, how to obtain its size in definition of node style.

so far i try the following:

\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}

which gives:

enter image description here

as you can see, my attempt was unsuccessful. the question is, where is the error in using of the \pgfkeysvalueof{...}. did i at use of \pgfkeysvalueof{...} miss something or is my attempt to determine the size of the shadow xshift incorrect?

or is my expectation, that on this way is possible to obtain size of shadow xshift naive?

2
  • Why do you want to cast a shadow? Are you a groundhog? – user121799 Mar 10 '18 at 22:52
  • @marmot, good question :-) i had some (crazy) ideas about composing shapes styles from predefined building blocks. another reason was to learn a bit more about tikz. and not on the end, i'm not groundhog :-). – Zarko Mar 11 '18 at 9:11
6

As a workaround you could perhaps use .store in to save #2 in the DS style to a macro, and subsequently use that macro in A.

output of code

\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}
1
  • thank you for answer (+1). since i'm not familiar with .store in i will first search/read in tikz manual to find more information. on the first sight it seem to be very promising. – Zarko Mar 10 '18 at 22:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.