3

I have three nodes:

\draw (4,2) node(p1)[label={[label distance=0.9cm]0:$$}]{}; 
\draw (5,3) node(p2)[label={[label distance=0.9cm]0:$$}]{}; 
\draw (6,4) node(p3)[label={[label distance=0.0cm]0:$$}]{}; 

that I try to connect with:

\draw[help lines] (p1) -- (p2);
\draw[help lines] (p2) -- (p3);

but the lines are not ending exactly on those nodes. Someone know why?

I am including also the header files because it is a long list and I am not really able to understand where the problem could come from:

\documentclass[9pt]{article}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{psfrag}
\pagestyle{empty}
\usepackage{subcaption}


%%% List of packages used
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{xcolor}
\usepackage{etoolbox}

\newtoggle{quickdecim}
\usepackage{tikz} %for drawings:
 \usetikzlibrary{shapes}
 \usetikzlibrary{arrows}
 \usetikzlibrary{calc}
 \usetikzlibrary{intersections,plotmarks}
 \usetikzlibrary{positioning}
 \usetikzlibrary{decorations}
 \usetikzlibrary{decorations.pathreplacing}
 \pgfkeys{/pgfplots/axis labels at tip/.style={ % This defines the axis as I want
  xlabel style={at={(current axis.right of origin)}, xshift=10cm, yshift=-10cm, anchor=center},
  ylabel style={at={(current axis.above origin)}, yshift=10cm, xshift=-10cm, anchor=center}}
} 

\usepackage{tkz-fct}     %for functions
%%% Up to here


\parindent=0pt 

%FLOW CHART packages
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\usetikzlibrary{calc}
\usepackage{amssymb}


% For Arrow Head Filled
\tikzset{>=latex}


%++++++++++++++++++
% For Hatch
\usetikzlibrary{patterns}
%++++++++++++++++++


             \usepackage[noheadfoot,nomarginpar,margin=1mm,paperwidth=9cm,paperheight=6cm]{geometry} 

%---------------------------------------------------------------------------%%
 \begin{document}

 \begin{figure}[h]
 \begin{tikzpicture}[x=1cm,y=1cm,
  every path/.style = {scale = 0.52},
  every node/.append style = {font=\sffamily,scale = 1.0},
  ]
  \begin{scope}[shift={(-1.2,-0.2)}]{
   \draw (4,2) node(p1)[label={[label distance=0.9cm]0:$$}]{}; 
   \draw (5,3) node(p2)[label={[label distance=0.9cm]0:$$}]{}; 
   \draw (6,4) node(p3)[label={[label distance=0.0cm]0:$$}]{}; 
   \draw[help lines] (p1) -- (p2);
   \draw[help lines] (p2) -- (p3);}
\end{scope}
\end{tikzpicture}
\end{figure}
\end{document}

I would really appreciate if someone with can help me with this trivial problem.

  • While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. – Peter Grill Feb 9 '16 at 12:03
  • Note also that the order of \end{figure} and \end{tikzpicture} is wrong in your code. – Torbjørn T. Feb 9 '16 at 12:04
  • I'll re-edit the question. Thanks for the suggestions. – dario Feb 9 '16 at 17:08
4

The lines do end at the nodes, you have to consider that nodes have some padding (inner sep, outer sep), and lines are drawn to the edge of the node, not the center. Add draw to the node options and you'll see this:

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (4,2) node(p1)[draw,label={[label distance=0.9cm]0:$$}]{}; 
\draw (5,3) node(p2)[draw,label={[label distance=0.9cm]0:$$}]{}; 
\draw (6,4) node(p3)[draw,label={[label distance=0.0cm]0:$$}]{}; 

\draw[help lines] (p1) -- (p2);
\draw[help lines] (p2) -- (p3);
\end{tikzpicture}
\end{document}

enter image description here

To get a full line you can draw the line between the center anchors, i.e.

\draw[help lines] (p1.center) -- (p2.center) -- (p3.center);

or you can use coordinate instead of node, i.e.

\documentclass[border=4mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[x=1cm,y=1cm,
  every path/.style = {scale = 0.52},
  every node/.append style = {font=\sffamily,scale = 1.0},
  ]
\draw (4,2) coordinate(p1)[label={[label distance=0.9cm]0:$$}]; 
\draw (5,3) coordinate(p2)[label={[label distance=0.9cm]0:$$}]; 
\draw (6,4) coordinate(p3)[label={[label distance=0.0cm]0:$$}]; 

\draw[help lines] (p1) -- (p2);
\draw[help lines] (p2) -- (p3);
\end{tikzpicture}
\end{document}

enter image description here

  • Perfect, thanks a lot. It's exactly the explanation I was looking for. :) – dario Feb 9 '16 at 17:09
  • And again, thanks for the effort, I like when explanation are given other than just the solution. – dario Feb 9 '16 at 17:22

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.