# Draw horizontal line up to rounded rectangle node in TikZ

I have a rounded rectangle node, and I want to draw a horizontal line up to it. I can use things like (A.210) to (A.210 -| -2, 0), but I want to be able to specify the y-coordinate explicitly, and I'm struggling to see a way to do that (short of doing trigonometry by hand to figure out the right angle anchor).

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.misc}

\begin{document}
\begin{tikzpicture}
\node (A) [draw, rounded rectangle, minimum height=4em] {};
\draw (-2, -1em) to (A); % I want this line to be horizontal.
\end{tikzpicture}
\end{document}


Output:

Try this:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[line width=0.5pt,color=red] (-2,0-1em) -- (0,0-1em);
\draw[line width=0.5pt] (0,0) circle (2em);
\fill[color=white] (0,0) circle (2em);
\end{tikzpicture}
\end{document}


You can change the line width and the color to whatever you want. Note that color in \fill must be set as your paper background color to hide the unnecessary part of the red line.

• I need a node[rounded rectangle] (contents were cut for the MWE), but this is close enough to get me on the right lines of drawing the shape over the line. Nov 5, 2018 at 14:33
• @dutchie, try this: \draw (-2, -1em) to (0,-1em);\node (A) [draw,fill=white, rounded rectangle, minimum height=4em] {}; Nov 5, 2018 at 14:33

You could also use intersections for that (in case you put the A node on top of some background, which prevents you from filling it white).

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.misc,intersections}

\begin{document}
\begin{tikzpicture}
\node (A) [draw, rounded rectangle, minimum height=4em,name path=A] {};
\path[name path=B] (-2, -1em) coordinate (aux) -- (0,-1em);
\draw[red,name intersections={of=A and B}] (aux) -- (intersection-1);
\end{tikzpicture}
\end{document}


• This looks like the "right" way to do it, awesome! I'll have to do some more reading about the intersections library. Nov 5, 2018 at 14:35