2

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}

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

enter image description here

What is going on here? Let's start with

\documentclass[tikz]{standalone}
\begin{document}
  \begin{tikzpicture}
    \path node[draw](n1){text};
    \path[fill=blue](n1.north east) circle[radius=0.1pt]
    (n1.north west)circle[radius=0.1pt];
    \path[draw,red](n1.north east)--(n1.north west);
  \end{tikzpicture}
\end{document}

enter image description here

This does not have any unnecessary gap. If you uncomment

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

you get

enter image description here

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.

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.