[Tex/LaTex] How to make a thick line connect completely with the side of a box in TikZ

arrowsboxestikz-pgf

In my figure, I have a thick line that connects with the side of a box. However, the line does not connect completely with the box. Also, the line covers part of the box (which I don't want).

So, I want the lower edge of the line to connect completely with the box, and prevent the upper edge of the line to cover part of the box. It probably says how to deal with this in the PGF manual but I can't find it (and since I don't know the terminology for this, I can't search for it either).

enter image description here

Here is minimal example for the figure above.

\documentclass{standalone}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
  \node [draw, minimum size = 1cm] (box) {};
  \draw [line width = 5pt] (2cm, 2cm) -- (box.east);
\end{tikzpicture}
\end{document}

Best Answer

\documentclass{standalone}   
\usepackage{tikz}
\usetikzlibrary{calc} 
\begin{document} 

  \tikzset{%
    add/.style args={#1 and #2}{to path={%
 ($(\tikztostart)!-#1!(\tikztotarget)$)--($(\tikztotarget)!-#2!(\tikztostart)$)%
  \tikztonodes}}
}                

\begin{tikzpicture}  
   \node [ minimum size = 1cm] (box) {};  
   \draw [line width = 5pt,add=0 and .1] (2cm, 2cm) to (box.east);   
   \node [draw, fill=white,minimum size = 1cm]  {};

\end{tikzpicture}
\end{document} 

enter image description here

second solution

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc} 
\begin{document} 

  \tikzset{%
    add/.style args={#1 and #2}{to path={%
 ($(\tikztostart)!-#1!(\tikztotarget)$)--($(\tikztotarget)!-#2!(\tikztostart)$)%
  \tikztonodes}}
}                

\begin{tikzpicture}  
   \node [draw, fill=white,minimum size = 1cm] (box) {};  
   \clip (box.south east) rectangle (2.1cm, 2.1cm);   
   \draw [line width = 5pt,add=0 and .1] (2cm, 2cm) to (box.east);   
\end{tikzpicture}
\end{document} 

Third solution

\documentclass{article}   
\usepackage{tikz}
\usetikzlibrary{calc,backgrounds} 
\begin{document} 

  \tikzset{%
    add/.style args={#1 and #2}{to path={%
 ($(\tikztostart)!-#1!(\tikztotarget)$)--($(\tikztotarget)!-#2!(\tikztostart)$)%
  \tikztonodes}}
}                

\begin{tikzpicture}
   \draw[help lines] (0,0) grid (2,2);    
   \node [draw,minimum size = 1cm,fill=white] (box) {}; 
   \begin{pgfonlayer}{background}
      \draw [line width = 5pt,add=0 and .1] (2cm, 2cm) to (box.east);      
   \end{pgfonlayer}
\end{tikzpicture}

\end{document} 

Fourth version With reverseclip

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[remember picture]

% A path that follows the edges of the current page
\tikzstyle{reverseclip}=[insert path={(current page.north east) --
  (current page.south east) --
  (current page.south west) --
  (current page.north west) --
  (current page.north east)}
]

\node [draw, minimum size = 1cm,inner sep=0pt,ultra thick,red] (box) at (.5cm,.5cm){};
\coordinate (D) at (box.north west);
\coordinate (C) at (box.north east);
\coordinate (B) at (box.south east);
\coordinate (A) at (box.south west);

\begin{pgfinterruptboundingbox} 
\path [clip] (A) -- (B) -- (C) -- (D) -- cycle [reverseclip];
\end{pgfinterruptboundingbox}

\draw [line width = 15pt] (.5cm, 1.5cm) to (.8cm,-.5cm);
\end{tikzpicture}
\end{document}

enter image description here