3

Is there any way to modify this example so the line to "Hey!" stops at the edge of its node boundary? (Or at least stops drawing some distance short of its final position) I know I can use a fill but I don't want to in this case.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}
\begin{document}
\begin{tikzpicture}[node distance=2cm,>=latex, every node/.style={
    font=\sffamily\scriptsize
    },  
    circtext/.style={draw,circle,minimum size=8pt,inner sep=2pt},
    dot/.style={draw,circle,fill=black,minimum size=0.6mm,inner sep=0pt}
]
{
\node[rectangle, fill=green!10!white!90!black, minimum width=6cm, minimum height=3cm] at (2,0){};
\node[circtext, fill=yellow](A) at (0,0) {A};
\node[circtext, fill=yellow, right=of A](B){B};
\draw[->] (A) -- node[dot, pos=0.5](C){}(B);
\draw[-] (C) --++(1,1) node[draw, inner sep=1pt]{Hey!};
}
\end{tikzpicture}
\end{document}

enter image description here

6
  • Either add above or anchor=<something> or similar, or place the node before and then connect it. There also might be the possibility to use mark connection node from the decoration.markings library, though I prefer the node placed before. Commented May 13, 2015 at 20:38
  • 1
    You can shorten it by writing \draw[-,shorten >=6pt] ....
    – Alenanno
    Commented May 13, 2015 at 20:38
  • @Qrrbrbirlbel: how do I place a node at a specific offset (e.g. (1,1)) relative to another node?
    – Jason S
    Commented May 13, 2015 at 20:41
  • Hmm, I just discovered pin=, that seems to sort of do what I want.
    – Jason S
    Commented May 13, 2015 at 20:41
  • 1
    \node at ([shift=(1,1)]C) {Hey!} (or at ($(C)+(1,1)$) with the calc library) or \node[above right=1 and 1 of C]{Hey} (see positioning library) and possibily the on grid option. Commented May 13, 2015 at 20:43

1 Answer 1

3

References:

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning,backgrounds,calc}
\newcommand*\mydrawing{%
 % \node[rectangle, fill=green!10!white!90!black, minimum width=6cm, minimum height=3cm] at (2,0){};
  \node[circtext, left, fill=yellow](A) at (0,0) {A};
  \node[circtext, fill=yellow, right=of A](B){B};
  \draw[->] (A) -- node[dot, pos=0.5](C){}(B);}
\tikzset{every picture/.append style={execute at begin picture=\mydrawing, node distance=2cm, >=latex,
  every node/.style={font=\sffamily\scriptsize},
  circtext/.style={draw,circle,minimum size=8pt,inner sep=2pt},
  dot/.style={draw,circle,fill=black,minimum size=0.6mm,inner sep=0pt},
  gridded}}
\begin{document}
\tikz\draw (C) --++(1,1) node[draw, inner sep=1pt]{Hey!};
\tikz\node[inner sep=1pt, draw] at ([shift={(1,1)}]C) {Hey!}              edge (C);
\tikz\node[inner sep=1pt, draw] at ($(C)+(1,1)$) {Hey!}                   edge (C);
\tikz\node[inner sep=1pt, draw, above right=1 and 1 of C] {Hey!}          edge (C);
\tikz[on grid]\node[inner sep=1pt, draw, above right=1 and 1 of C] {Hey!} edge (C);
\tikz\path (C) ++(1,1) node[draw, inner sep=1pt] {Hey!}                   edge (C);
\tikz\path[pin distance=1cm] (C)
  [late options={pin={[draw, inner sep=1pt, pin edge={thin,black}]above right:Hey!}}];
\tikz\path[every pin edge/.style={thin,black}, pin distance=1cm] (C)
  [late options={pin={[draw, inner sep=1pt]above right:Hey!}}];
% This is the same as saying \node[pin=…] (C) {};
\end{document}

You must log in to answer this question.

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