4

In order to define additional anchors in TikZ, I use the code from this popular answer. Unfortunately, after updating to TikZ 3.0, the code does not work anymore. I now receive several errors and my file does not compile.

! Package PGF Math Error: Unknown function `westsouthwest' (in 'westsouthwest').

See the PGF Math package documentation for explanation. Type H for immediate help. ...

l.38 \draw (a.westsouthwest) -- (a.north);

I assume that some command has been changed due to the update, but I don't really know how fix this. Here is the code:

MWE

\documentclass{article}
\usepackage{tikz}

\makeatletter
\def\pgfaddtoshape#1#2{%
  \begingroup
  \def\shape@name{#1}%
  \let\anchor\pgf@sh@anchor
  #2%
  \endgroup
}

\def\useanchor#1#2{\csname pgf@anchor@#1@#2\endcsname}

\def\@shiftback#1#2#3#4#5#6{%
    \advance\pgf@x by -#5\relax
    \advance\pgf@y by -#6\relax
}

\pgfaddtoshape{rectangle}{%
  \anchor{westsouthwest}{%
    \pgf@process{\northeast}%
    \pgf@ya=.5\pgf@y%
    \pgf@process{\southwest}%
    \pgf@y=1.5\pgf@y%
    \advance\pgf@y by \pgf@ya%
    \pgf@y=.5\pgf@y%
  }%
}

\makeatother

\begin{document}
\begin{tikzpicture}
\node (a) at (0,0) {1};
\draw (a.westsouthwest) -- (a.north);
\end{tikzpicture}
\end{document}
4
  • @GonzaloMedina Thanks for the hint, I forgot to include this in MWE. I updated the question.
    – maetra
    Commented Mar 8, 2014 at 16:49
  • I think \shape@name is now \pgf@sm@shape@name Commented Mar 8, 2014 at 17:06
  • Alternatively you could replace (a.westsoutwest) with ($(a.west)!.5!(a.southwest)$). Commented Mar 8, 2014 at 17:43
  • @MarkWibrow Thanks, your guess is right. Do you want to turn your comment into an answer?
    – maetra
    Commented Mar 8, 2014 at 18:45

1 Answer 1

10

In the newer version of PGF \shape@name is now \pgf@sm@shape@name:

\documentclass[tikz,border=5]{standalone}
\makeatletter
\long\def\pgfshapeaddanchor#1#2{%
{%
  \def\pgf@sm@shape@name{#1}%
  \let\anchor=\pgf@sh@anchor%
  #2}%
}
\pgfshapeaddanchor{rectangle}{%
  \anchor{west north west}{%
    \pgf@process{\northeast}%
    \pgf@ya=1.5\pgf@y%
    \pgf@process{\southwest}%
    \[email protected]\pgf@y%
    \advance\pgf@y by \pgf@ya%
    \pgf@y=.5\pgf@y%
  }%
  \anchor{north north west}{%
    \pgf@process{\southwest}%
    \pgf@xa=1.5\pgf@x%
    \pgf@process{\northeast}%
    \[email protected]\pgf@x%
    \advance\pgf@x by \pgf@xa%
    \pgf@x=.5\pgf@x%
  }%
  \anchor{west south  west}{%
    \pgf@process{\northeast}%
    \pgf@ya=.5\pgf@y%
    \pgf@process{\southwest}%
    \pgf@y=1.5\pgf@y%
    \advance\pgf@y by \pgf@ya%
    \pgf@y=.5\pgf@y%
  }%
  \anchor{south south  west}{%
    \pgf@process{\northeast}%
    \pgf@xa=.5\pgf@x%
    \pgf@process{\southwest}%
    \pgf@x=1.5\pgf@x%
    \advance\pgf@x by \pgf@xa%
    \pgf@x=.5\pgf@x%
  }%
}

\makeatother
\tikzset{shape example/.style={
    color=black!30, draw, fill=yellow!30,
    line width=.5cm, inner xsep=2.5cm, inner ysep=0.5cm,
}}
\begin{document}
\Huge
\begin{tikzpicture}
\node[name=s,shape=rectangle,shape example] {Rectangle\vrule width 1pt height 2cm};
\foreach \anchor/\placement in
  {north west/above left, north/above,
   west/left,  south west/below left, south/below}
    \draw[shift=(s.\anchor)] plot[mark=x] coordinates{(0,0)}
      node[\placement] {\scriptsize\texttt{(s.\anchor)}};

\foreach \anchor/\placement in
  {west south west/below left, west north west/above left,
   north north west/above, south south west/below}
    \draw[red,shift=(s.\anchor)] plot[mark=x] coordinates{(0,0)}
      node[\placement] {\scriptsize\texttt{(s.\anchor)}};
\end{tikzpicture}

\end{document}

enter image description here

1

You must log in to answer this question.

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