Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to draw a line from (p) to (x0), but I want that the line starts inside the node (p) and not at the border. I tried using "xshift" but it doesn't work.

\begin{tikzpicture}[auto,>=latex', thick, overlay]
    \path[->]<1-> node[cell, label=left:\texttt{x}] at (-1,0) (x0) {};
    \path[->]<1-> node[cell, label=left:\texttt{p}] at (-3,2) (p) {};
    \path[->,red,xshift=-5mm]<1-> (p) edge [bend left] (x0);
\end{tikzpicture}

Thank you in advance.

share|improve this question
3  
try (p.center) in place of (p). –  Ben Webster Apr 3 '12 at 3:01
1  
Also setting inner sep=0 will make the border be tighter around the text. –  Caramdir Apr 3 '12 at 3:33
    
Thank you all! All the answers were useful to me :D –  Leo Rodríguez Apr 4 '12 at 1:27
add comment

2 Answers

up vote 10 down vote accepted

I think that comments and Gonzalo's answer are correct but I want to add more informations. First the good and natural way it's to use (node.center) if you want to draw something from the center of a node.

outer sep is used to placed the anchors (except center anchor) so it's damage to modify outer sep. Below I place a picture to explain how to use the different options.

enter image description here

Now in your case, there are some remarks to add. First , you use edge but if you use toand if you want to get the center of the final node, you can find another way. The first picture shows the normal way. outer sep with line width are determined to get the start and the end of the edge near the shape of the node. The interesting case is the third one, because edge is a special operation (see the pgfmnual) and in the edge is drawn before the last node and the arrow goes to (2,-1).

\documentclass{article}
\usepackage{tikz}
\usepackage{spath}

\begin{document} 

\begin{tikzpicture}
\node[circle,draw](A) {A};
\node[circle,draw](B) at (2,-1){B}; 
\draw[->,red,thick] (A) edge [bend left] (B);
\end{tikzpicture}
\begin{tikzpicture}
\node[circle,draw](A) {A};
\node[circle,draw](B) at (2,-1){B}; 
\draw[->,red,thick] (A.center) edge [bend left] (B.center);
\end{tikzpicture} 
\begin{tikzpicture}
\node[circle,draw](A) {A};
\draw[->,red,thick] (A) edge [bend left]   node[at end,circle,draw,black,thin]{B}(2,-1) ;
\end{tikzpicture} 
\begin{tikzpicture}
\node[circle,draw](A) {A};
\node[circle,draw](B) at (2,-1){B}; 
\draw[->,red,thick] (A.center) to [bend left] (B);
\end{tikzpicture}
\end{document} 

enter image description here

share|improve this answer
1  
Je suis toujours impressionné par la qualité et les détails de vos réponses –  Frédéric Apr 4 '12 at 3:50
    
Merci ! :) mais cela dépend beaucoup du sujet traité ! –  Alain Matthes Apr 4 '12 at 7:53
add comment

There are several options here. You can set inner sep to 0pt and use p.center instead of p (as suggested in the comments), or you can use the shorten <= option to shorten the start of the line by the given distance. A little example illustrating those approaches (I removed some of your settings since you didn't provide the appropriate definitions in your code snippet):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}

\begin{document}

\begin{tikzpicture}[auto,>=latex', thick, overlay]
  \path[->] node[label=left:\texttt{x}] at (-1,0) (x0) {};
  \path[->] node[label=left:\texttt{p}] at (-3,2) (p) {};    
  \path[->,red] (p) edge [bend left] (x0);

\begin{scope}[xshift=3cm]
  \path[->] node[label=left:\texttt{x}] at (-1,0) (x0) {};
  \path[->] node[inner sep=0pt,label=left:\texttt{p}] at (-3,2) (p) {};    
  \path[->,red] (p.center) edge [bend left] (x0);
\end{scope}

\begin{scope}[xshift=6cm]
  \path[->] node[label=left:\texttt{x}] at (-1,0) (x0) {};
  \path[->] node[label=left:\texttt{p}] at (-3,2) (p) {};    
  \path[->,red,shorten <= -5pt] (p) edge [bend left] (x0);
\end{scope}

\begin{scope}[xshift=9cm]
  \path[->] node[label=left:\texttt{x}] at (-1,0) (x0) {};
  \path[->] node[label=left:\texttt{p}] at (-3,2) (p) {};    
  \path[->,red,shorten <= -10pt] (p) edge [bend left] (x0);
\end{scope}

\end{tikzpicture}

\end{document}

enter image description here

There's also a shorten >= option to shorten the end of the line by the given distance.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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