Home > tikz pgf > How to draw a line into a node

# How to draw a line into a node

December 13Hits:1

I'm trying to replicate a picture like the following:

I'm only at the beginning stages of this replication, as a result I have the following:

\documentclass[margin=10pt]{standalone}  \usepackage{tikz} \usetikzlibrary{arrows,decorations,pathmorphing,backgrounds,positioning,fit,petri}  \begin{document}  %% Set up the style \tikzstyle{rom} = [square, draw, text width=5em, text centered,   minimum height=4em]  \begin{tikzpicture}   %% Start drawing the nodes   \node[rom] (rom1) {ROM};   \node[rom] (rom2) [below=of rom1] {ROM};    \draw[->] (rom1.west) \end{tikzpicture} \end{document} 


Which produces:

How can I go about drawing the A2, A1, & A0 lines going into the top node? My guess was, that we'll create an invisible node to the left, and then we can draw the lines from the invisible node to the drawn node?

First, here's a simple way to draw the first one. Note that I had to change your code in several places as it would not compile without errors.

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,positioning,fit,petri}

\begin{document}

%% Set up the style
\tikzset{%
rom/.style = {draw, text width=5em, text centered, minimum height=4em}
}

\begin{tikzpicture}
%% Start drawing the nodes
\node[rom] (rom1) {ROM};
\node[rom] (rom2) [below=of rom1] {ROM};

\draw[<-] (rom1.west) -- +(-20mm,0) node [left] (a1) {$A_1$};
\end{tikzpicture}
\end{document}



Looking at the picture as a whole, I would be inclined to use a pic to draw the ROM boxes because they are identical and the pattern of connections is always the same. You can then use a couple of loops to add several of the lines and finish with the more complex cases, handling those one-by-one.

\documentclass[tikz,border=10pt]{standalone}



\usetikzlibrary{arrows.meta,positioning,calc}

\begin{document}

%% Set up the style



We use a counter to name the ROM boxes. The first will be rom1, the second rom2 and so on.

\newcounter{rom}
\setcounter{rom}{0}
\tikzset{%
rom/.style = {draw, text width=5em, text centered, minimum height=4em, font=\sffamily},
a node/.style = {inner sep=1pt, font=\scriptsize},



Here comes the code for the pic, rom node:

  rom node/.pic = {%



Increment the counter:

    \stepcounter{rom}%



Draw and name the basic box:

    \node [rom] (rom\therom) {ROM};



Now we create the connections rom<counter>-a0, rom<counter>-a1 and rom<counter>-a2 on the left and label them.

    \foreach \i [count=\j from 0] in {1/4,1/2,3/4} \node (rom\therom-a\j) [a node, right] at ($(rom\therom.south west)!\i!(rom\therom.north west)$) {$A_\j$};



Now for connections rom<counter>-d0 and rom<counter>-d1 on the right.

    \node (rom\therom-d1) [a node, left] at (rom\therom-a2 -| rom\therom.east) {$D_1$};
\node (rom\therom-d0) [a node, left] at (rom\therom-a0 -| rom\therom.east) {$D_0$};



This is the label at the top:

    \node [a node, below] at (rom\therom.north) {$8 \times 2$};



Now we want connections rom<counter>-oe and rom<counter>-ce at the bottom.

    \node (rom\therom-ce) [a node, above, xshift=-10pt] at (rom\therom.south) {$CE$};
\node (rom\therom-oe) [a node, above, xshift=10pt] at (rom\therom.south) {$OE$};
},



A style for drawing the lines where one end is on another line would be useful.

  bullet arrow/.style={{Circle[width=2pt,length=2pt]}->, shorten <=-1pt}
}



Change the default arrow tip for the picture.

\begin{tikzpicture}[>={Latex[]}]
%% Start drawing the nodes



Now for the two rom node pics:

  \pic {rom node};
\pic [below=of rom1] {rom node};



Using the connections from the pics we can loop over the d connections on the right and add the arrows to d0, d1, d2 and d3.

  \foreach \i/\j in {rom1-d1/3,rom1-d0/2,rom2-d1/1,rom2-d0/0}
\draw [->] (\i) -- +(20mm,0) node (d\j) [a node, right] {$D_\j$};



Now for the arrows entering the higher ROM box on the left and for the connections from these arrows into the corresponding connectors in the lower ROM box. We mark the spots where the connections to the lower box should begin when drawing the arrows into the higher box and then add the connections from those spots using a second \draw.

  \foreach \i in {0,1,2}
{
\draw [<-] (rom1-a\i) -- +(-20mm,0) coordinate [pos=(3-\i)/6] (a\i x) node (a\i) [a node, left] {$A_\i$};
\draw [bullet arrow] (a\i x) |- (rom2-a\i);
}



Next, the arrows into rom2-ce and rom2-oe, marking the spots where we want to add further arrows later.

  \draw [<-] (rom2-oe) |- +(20mm,-5mm) coordinate [pos=.85] (oex) coordinate (oe);
\draw [<-] (rom2-ce) |- ([yshift=-2.5mm]oe) coordinate [pos=.8] (cex);



And here are the later arrows connecting the marked spots to rom1-oe and rom1-ce.

  \draw [bullet arrow] (oex) |- ([yshift=-5mm]rom1-oe.south) -- (rom1-oe.south);
\draw [bullet arrow] (cex) |- ([yshift=-7.5mm]rom1-ce.south) -- (rom1-ce.south);
\end{tikzpicture}
\end{document}



Complete code:

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{arrows.meta,positioning,calc}

\begin{document}

%% Set up the style
\newcounter{rom}
\setcounter{rom}{0}
\tikzset{%
rom/.style = {draw, text width=5em, text centered, minimum height=4em, font=\sffamily},
a node/.style = {inner sep=1pt, font=\scriptsize},
rom node/.pic = {%
\stepcounter{rom}%
\node [rom] (rom\therom) {ROM};
\foreach \i [count=\j from 0] in {1/4,1/2,3/4} \node (rom\therom-a\j) [a node, right] at ($(rom\therom.south west)!\i!(rom\therom.north west)$) {$A_\j$};
\node (rom\therom-d1) [a node, left] at (rom\therom-a2 -| rom\therom.east) {$D_1$};
\node (rom\therom-d0) [a node, left] at (rom\therom-a0 -| rom\therom.east) {$D_0$};
\node [a node, below] at (rom\therom.north) {$8 \times 2$};
\node (rom\therom-ce) [a node, above, xshift=-10pt] at (rom\therom.south) {$CE$};
\node (rom\therom-oe) [a node, above, xshift=10pt] at (rom\therom.south) {$OE$};
},
bullet arrow/.style={{Circle[width=2pt,length=2pt]}->, shorten <=-1pt}
}

\begin{tikzpicture}[>={Latex[]}]
%% Start drawing the nodes
\pic {rom node};
\pic [below=of rom1] {rom node};
\foreach \i/\j in {rom1-d1/3,rom1-d0/2,rom2-d1/1,rom2-d0/0}
\draw [->] (\i) -- +(20mm,0) node (d\j) [a node, right] {$D_\j$};
\foreach \i in {0,1,2}
{
\draw [<-] (rom1-a\i) -- +(-20mm,0) coordinate [pos=(3-\i)/6] (a\i x) node (a\i) [a node, left] {$A_\i$};
\draw [bullet arrow] (a\i x) |- (rom2-a\i);
}
\draw [<-] (rom2-oe) |- +(20mm,-5mm) coordinate [pos=.85] (oex) coordinate (oe);
\draw [<-] (rom2-ce) |- ([yshift=-2.5mm]oe) coordinate [pos=.8] (cex);
\draw [bullet arrow] (oex) |- ([yshift=-5mm]rom1-oe.south) -- (rom1-oe.south);
\draw [bullet arrow] (cex) |- ([yshift=-7.5mm]rom1-ce.south) -- (rom1-ce.south);
\end{tikzpicture}
\end{document}


Tags:nodes, tikz pgf

## Related Articles

• ### Is there a better way to draw parallel lines between two nodes that are neither aligned vertically or horizontallyJuly 12

I know how to draw parallel lines between two nodes that are either aligned horizontally or vertically. \documentclass{article} \usepackage{tikz} \usetikzlibrary{calc} \begin{document} \begin{tikzpicture}[myn/.style={circle,draw,inner sep=0.25cm,oute

• ### How can I draw multiple lines connected via "nodes" with SlimDX?August 7

I currently read out XML data with the following scheme: Position x,y,z I try to add one new Vertex for each position node and add it to a Vertex array. Then I try to render this list of vertices so I get all those lines connected to represent a "pat

• ### Drawing a line betwen two nodes which are in separate imagesDecember 20

Is it possible to draw a line between two circles in the below code? \documentclass[border=1cm]{standalone} \usepackage{tikz} \begin{document} \tikzset{ crcl/.style={draw, thick, shape=circle } } \newcommand*{\MyPic}[2]{ \begin{tikzpicture} \draw #1

• ### Draw two lines between two nodes with tikzJune 22

I have two nodes \node (A) {A}; \node [below=of A] (B) {B}; I can draw a line between them with \draw (A) -- (B); But I need two lines between them. If I'm using \draw (A) -- (B); \draw (B) -- (A); it will draw the two lines on top of each other. Can

• ### how to draw a line between a node and a line in TikZ?November 10

I am a beginner in TikZ. I want to draw a simple network with 2 nodes and a network like this: My code is here: \documentclass[border=1pt]{standalone} \usepackage{tikz} \usetikzlibrary{arrows, shapes, trees, calc} \begin{document} % Define styles \ti

• ### How to draw a line into a nodeDecember 13

I'm trying to replicate a picture like the following: I'm only at the beginning stages of this replication, as a result I have the following: \documentclass[margin=10pt]{standalone} \usepackage{tikz} \usetikzlibrary{arrows,decorations,pathmorphing,ba

• ### How to draw dotted line between two nodesApril 11

\begin{tikzpicture} \tikzset{grow'=right,level distance=60 pt} \Tree [.I \edge node[auto=left]{M};[.II \edge node[auto=left]{L};$3,3$ \edge node[auto=right]{R};[.$x,0$ ]] \edge node[auto=left]{B};[.II \edge node[auto=left]{L};$0,0$ \edge node[auto=ri

• ### draw half line between two nodes tikzFebruary 8

I have the following graph: \documentclass[border=1mm]{standalone} \usepackage{siunitx} \usepackage{tikz} \begin{document} \begin{tikzpicture} ] \node (n1) at (0,0) [draw=black,auto=left,circle,thick,fill=red!50,scale=1.3] {$\mathbf{X}_1$}; \node (n2

• ### How to draw saturation symbol inside a node in TikZAugust 1

I'm working on a block diagram using TikZ. I'd like to create a symbol like below, which means I have to draw 5 lines inside a node and write a letter in the upper-right corner. What's the best way to achieve what I need? Any hints appreciated. -----

• ### TikZ how to draw lines to/from nodes correctly? December 18

I have the following tikz code % compilation command: pdflatex --jobname=Diag-f1 Diag.tex \documentclass{book} \usepackage{tikz} \pgfrealjobname{Diag} \begin{document} \beginpgfgraphicnamed{Diag-f1} \begin{tikzpicture}[node distance=3em] \node(G)[rec

• ### Drawing a vertical line between two nodes in TikZ December 18

I have the following tikz code % compilation command: pdflatex --jobname=Diag-f1 Diag.tex \documentclass{book} \usepackage{tikz} \pgfrealjobname{Diag} \begin{document} \beginpgfgraphicnamed{Diag-f1} \begin{tikzpicture}[node distance=3em] \node(G)[rec

• ### Tikz: how to draw a horizontal line between 2 nodesSeptember 15

Code: \documentclass[preview]{standalone} \usepackage[utf8]{inputenc} \usepackage[english]{babel} \usepackage{tikz} \usetikzlibrary{positioning} \begin{document} \begin{tikzpicture} \node [draw] (1) {Node}; \node [draw, below = of 1] (1) {Long text};

• ### Tikz - How to Draw Boxes Around Set of NodesJanuary 13

How to draw the boxes as shown in the attached image? I could only manage to draw the chart but could not highlight the desired node / nodes with a rectangle box. Preferably dotted. I could not draw dotted in MS paint. \documentclass{article} \usepac

• ### How to draw a line passing through a point and perpendicular to another?May 29

I'm having a bit of a headache right now as I can't draw this basic figure: A straight line goes through points A and B. Another line is perpendicular to AB and goes through an arbitrary point P. I fiddled with the |- operator but it only seems to wo

• ### How to draw a line passing through a point and parallel to another?May 29

How to draw a line passing through a point and parallel to another? \draw (0,0) -- (1,0); \node (A) at (1,1); I need \draw (0,1) -- (1,1); parallel to first line. --------------Solutions------------- You can use the calc library to calculate the vect

• ### How to draw tangent line of an arbitrary point on a path in TikZAugust 17

Suppose I specify some node as occurring at some point on a path. Say for example the node (P) defined on the following path. \path[draw] (0,9) to[out=-90,in=180] (9,0) node[pos=0.7,circle] (P) {}; I would now like to draw the tangent line at (P) to

• ### Draw an arc between 2 nodes and label it in TikZSeptember 2

I have already drawn two ellipses l1 and l2, l2 is on the left below l1: \begin{tikzpicture} \node (l1) [ellipse, draw=black, fill=white!20, text=black, scale=0.8, text centered]{ $l_1$}; \node (l2) [ellipse, draw=black, fill=white!20, text=black, sc

• ### Draw sign lines with function expressions? October 5

As you have probably guessed from the title my mother tounge is not English. Therefore I have no idea if "Functional lines" is the correct term for what I am looking for. Basically I am looking to make a command similar to the one below \functio

• ### Draw comparison lines between two listingsJanuary 11

I have a LaTeX code set up as so: \documentclass[a4paper,10pt]{report} \usepackage[utf8]{inputenc} \usepackage{fullpage} \usepackage{listings} \usepackage{graphicx} \usepackage{float} \usepackage{parcolumns} \usepackage{qtree} \usepackage{url} \usepa

• ### Draw a line through one column of a matrixMarch 12

I'd like to "cancel" (draw a line through) a column of a matrix (using \begin{pmatrix}..\end{pmatrix}). How can I do this? --------------Solutions------------- The usual TikZ answer using \tikzmark to mark the top and bottom points where you wan