I am definitely unfamiliar with both beamer
and tikz
(do not quite get what the \only
are supposed to do) but perhaps this could go in the direction you want:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{chains}
\newcounter{count}
% helper macro:
\long\def\GobToSemiColon #1;{}
\newcommand\myPicture{
\begin{tikzpicture}
\begin{scope}[start chain = going below]
\ifnum\value{count}<1 \expandafter\GobToSemiColon\fi
\ifnum\value{count}>3 \expandafter\GobToSemiColon\fi
\node[draw, rectangle, on chain] {display only when counter is between
1 and 3};
\ifnum\value{count}>-1 \expandafter\GobToSemiColon\fi
\node[draw, rectangle, on chain] {display only when counter is
negative};
\ifnum\value{count}<100 \expandafter\GobToSemiColon\fi
\ifnum\value{count}>200 \expandafter\GobToSemiColon\fi
\node[draw, rectangle, on chain] {display only if counter is between
100 and 200};
\ifnum\value{count}<3 \expandafter\GobToSemiColon\fi
\ifnum\value{count}>20 \expandafter\GobToSemiColon\fi
\node[draw, circle, on chain] {only when counter is in the range 3 to 20};
\end{scope}
\end{tikzpicture}
}
\begin{document}
\begin{frame}
\only{\setcounter{count}{-3}\myPicture}
\only{\setcounter{count}{105}\myPicture}
\only{\setcounter{count}{39}\myPicture}
\only{\setcounter{count}{2}\myPicture}
\only{\setcounter{count}{5}\myPicture}
\end{frame}
\end{document}
When TikZ places a label (or a pin) it calculates a point that is label distance
(or pin distance
) away from a point on the anchor-border of its parent node.
This point on the anchor-border is directly dependent on the angle/direction before the :
(or the default label position
/pin position
). In the same direction the * distance
is added.
This is the new point where the label
/pin
is placed. (In other words: all the options like direction/angle and distance have an influence on the newly placed node, not the pin edge
.)
The new node is placed at a specific anchor which is calculated internally by TikZ (and snaps to the eight main compass directions and in one special case to the .center
). This is (one of) the cause for the problems in other questions:
The pin edge
(with all its options and defaults and styles) is done in an append after command
(the label/pin placement itself is a append after command
which \tikzlastnode
has been saved in \tikz@save@last@node
so that the inner append after command
can actually access both nodes).
The default pin edge
is a line to
path (= (<parent node>) -- (<pin node>)
). This is drawn with no regard to any anchors calculated or placed at. The --
line is drawn directly between the center of nodes stopping at the nodes’ borders.
The label
and pin
keys aren't really made for precise placement. (Don’t ask my why.)
However, with a few keys we could get what you want (or at least I assume this is what you want):
- The
label anchor
key is taken from my other answer to the first linked question above.
- The
pin anchor
is defined similar.
- The
pin edge pin anchor
key can be used to change the anchor at which the pin edge should end (at the pin).
- The
pin edge parent anchor
key can be used to change the anchor at which the pin edge should start (at the parent node).
The latter keys can also be given an empty value which resets the anchor to “automatically” (as TikZ sees fit).
I have added some auxiliary lines to the drawings that should help understand what I have said before. The arc labelled “60°” shows where the angle 60
is used and the double-arrowed line angled at 60° shows where the pin distance
(3ex
per default) is measured. The bottom-left start of this line points to (<parent node>.60)
and the top-right end of this line points to the point that pin distance
away from the start and where the pin will be placed with its (automatically determined or via pin anchor
set) anchor.
The second double-arrowed line shows how TikZ connects the the nodes (via the line to
edge). In the first two cases (without any pin edge * anchor
set) it connects the nodes on a straight line between their centers. In the third case it uses the specified south west
anchor to draw the line to. In the fourth, the additional north
anchor to start the line from.
Code
\documentclass[tikz]{standalone}
\makeatletter
\newcommand*\ifStrInTF[2]{%
\edef\tikz@temp{{#1}{#2}}%
\expandafter\pgfutil@in@\tikz@temp
\ifpgfutil@in@\expandafter\pgfutil@firstoftwo\else\expandafter\pgfutil@secondoftwo\fi}
\newcommand*\ifStrEmptyTF[1]{%
\def\tikz@temp{#1}\ifx\tikz@temp\pgfutil@empty
\expandafter\pgfutil@firstoftwo\else\expandafter\pgfutil@secondoftwo\fi}
\def\tikz@swapanchor#1.#2\tikz@stop#3#4{#1#4#3}
\newcommand*\tikzAddAnchor[2]{%
\ifStrInTF{.}{#1}{%
\ifStrEmptyTF{#2}
{\edef#1{\expandafter\tikz@swapanchor#1\tikz@stop{}{}}}
{\edef#1{\expandafter\tikz@swapanchor#1\tikz@stop{#2}{.}}}%
}{%
\ifStrEmptyTF{#2}{}% no true
{\edef#1{#1.#2}}%
}}
\tikzset{
pin anchor/.style={tikz@pin@post/.append style={anchor=#1}},
label anchor/.style={tikz@label@post/.append style={anchor=#1}},
pin edge pin anchor/.style={
append after command={\pgfextra\tikzAddAnchor{\tikzlastnode}{#1}\endpgfextra}%
},
pin edge parent anchor/.style={
append after command={\pgfextra\tikzAddAnchor{\tikz@save@last@node}{#1}\endpgfextra}%
}
}
\makeatother
\tikzset{c/.style={circle, minimum size=1cm, draw, densely dotted}}
\begin{document}
\begin{tikzpicture}[every pin/.append style=draw, every pin edge/.style={thick}]
\node [c] [pin=60:test] at (0,0) {};
\node[c] [pin={[pin anchor=west]60:test}] at (2,0) {};
\node[c] [pin={[pin anchor=south,
pin edge pin anchor=south west]60:test}] at (4,0) {};
\node[c] [pin={[pin anchor=south,
pin edge pin anchor=south west,
pin edge parent anchor=north]60:test}] at (6,0) {};
\end{tikzpicture}
\end{document}
Output
Best Answer
For this purpose you can easily set the arrival point when you say:
Change it into:
Here is my MWE (I added some
remember picture
when you call\tikz
):The result is:
Another option could be to specify the angle of the anchor you want to point to:
to get:
In latter case, that I prefer, the arrow is not placed exactly in the corner: you need to compute by mind the angle (it is not difficult), but the result is really better.