# How to eliminate gap at the start and at the end of a line when it's drawn along a side of a node's bounding box?

There are some gaps.

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\path node(n1){text};
\path[draw](n1.north east)--(n1.north west);
% uncomment following line to see gaps clearly
%\path[draw](n1.north west)--(n1.south west);
\end{tikzpicture}
\end{document}


\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\path node(n1){text};
\path[draw,line cap=rect](n1.north east)--(n1.north west);
% uncomment following line to see gaps clearly
%\path[draw](n1.north west)--(n1.south west);
\end{tikzpicture}
\end{document}


\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\path node[draw](n1){text};

 \path[draw,red](n1.north east)--(n1.north west);

So the gap is there. This is because TikZ is rather "generous" with the bounding box, here it adds the "natural extension" of the line which emerges when you do line cap=rect. Note that the bounding box gets much more "overestimated", see e.g. here. AFAIK there is no built-in way to obtain the exact bounding box.