行未在有 tikz 的節點上結束

行未在有 tikz 的節點上結束

我有三個節點:

\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);

但這些線並未完全在這些節點上結束。有人知道為什麼嗎?

我還包括頭文件,因為它是一個很長的列表,我真的無法理解問題可能來自哪裡:

\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}

如果有人可以幫我解決這個小問題,我將非常感激。

答案1

線條確實在節點處結束,您必須考慮節點有一些填充(inner sep, outer sep),並且線條繪製到節點的邊緣,而不是中心。新增draw到節點選項,您將看到:

\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}

在此輸入影像描述

要獲得完整的線條,您可以在錨點之間畫線center,即

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

或者你可以使用coordinate, nodeie

\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}

在此輸入影像描述

相關內容