9

I've got the following:

\documentclass{article}

\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\begin{document}
\pagestyle{empty}


% Define block styles
\tikzstyle{block} = [rectangle, draw, text width=5em, text centered,
  minimum height=4em]

\begin{tikzpicture}[node distance = 2cm, auto]
  % Place nodes
  \node [block] (I/O) {I/O};
  \node [block, below of = I/O] (CPU1) {CPU};
  \node [block, right of = CPU1] (CPU2) {CPU};
  \node [block, below of = CPU1] (Mem) {Memory};

  \draw [--] (I/O) -- (CPU1);
  \draw [--] (I/O) -| (CPU2);
  \draw [--] (CPU1) -- (Mem);
  \draw [--] (CPU2) |- (Mem);
\end{tikzpicture}


\end{document}

Which yields

enter image description here

How do I move the center CPU node (CPU1) to the left and replicate CPU2? Sorry if that isn't more clear, Basically just move the middle node to line up the right edge with the left edges of I/O and Memory.

9

I think it's easier if you use the calc library and change the commands for the positioning a bit.

By the way, I suggest you name the nodes with simple references, typing I/O gets tedious after a bit. Use lowercase, avoid extra symbols preferring letters and/or numbers only.

Output

example image

Code

\documentclass[margin=10pt]{standalone}   
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning,calc}
\begin{document}
\pagestyle{empty}


% Define block styles
\tikzstyle{block} = [rectangle, draw, text width=5em, text centered,
  minimum height=4em]

\begin{tikzpicture}%[node distance = 2cm, auto]
  % Place nodes
    \node [block] (io) {I/O};
    \node [block, below =2cm of io] (mem) {Memory};
    \node [block, anchor=east] (CPU1) at ($(io.south west)!.5!(mem.north west)$) {CPU};
    \node [block, anchor=west] (CPU2) at ($(io.south east)!.5!(mem.north east)$) {CPU}; 

    \draw (io) -| (CPU1);
    \draw (io) -| (CPU2);
    \draw (CPU1) |- (mem);
    \draw (CPU2) |- (mem);

\end{tikzpicture}
\end{document}
| improve this answer | |
  • Short addendum: The same effect can be achieved without the calc library syntax, e.g. \path (io.south west) -- node[block,left] (CPU1) {CPU} (mem.north west) (io.south east) -- node[block,right] (CPU2) {CPU} (mem.north east); – Torbjørn T. Dec 4 '15 at 18:58
8

Here is a solution using:

  • positioning TikZ library (new and better syntax: left=of ...)
  • node distance with two lengths (to use Manhattan distance)
  • on grid option to position nodes relatively to their centers
  • \tikszet instead of \tikzstyle

enter image description here

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[node distance = 2cm and 2cm,on grid]
  % Define block styles
  \tikzset{
    block/.style={
      rectangle, draw,
      text width=5em, text centered,
      minimum height=4em,
    }
  }

  % Place nodes
  \node [block] (I/O) {I/O};
  \node [block, below left= of I/O] (CPU1) {CPU};
  \node [block, below right= of I/O] (CPU2) {CPU};
  \node [block, below right= of CPU1] (Mem) {Memory};

  \draw (I/O) -| (CPU1);
  \draw (I/O) -| (CPU2);
  \draw (CPU1) |- (Mem);
  \draw (CPU2) |- (Mem);
\end{tikzpicture}
\end{document}
| improve this answer | |

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.