1

I am trying to reproduce this picture using tikz:enter image description here

My mwe is (Only the CPU box):

\documentclass[10pt,xcolor=dvipsnames,xcolor=table]{beamer}
\usepackage{amsmath, tikz}
\usetikzlibrary{positioning,arrows}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{shadows.blur, shapes.arrows}
\synctex=1
% \usepackage{listings}%, fancyvrb}
\usepackage[T1]{fontenc}

\begin{document}
\tikzstyle{sblock} = [rectangle, draw, %fill=Apricot!70, 
text width=5em, text centered, rounded corners, minimum height=0em, node distance=3.5cm]
\tikzstyle{block} = [rectangle, draw, fill=Apricot!70, 
text width=10em, text centered, rounded corners, minimum height=0em]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,
minimum height=2em]

\begin{frame}[fragile]
    \begin{tikzpicture}[scale=.85]
      \node[block, text width=1cm, rounded corners= 0ex, draw= none]at (-1.3,0) (cpu1)
      {PC};
      \node[block, text width=3cm, rounded corners= 0ex, draw= none] at (0,
      -2)(cpu2){BUS Interface};
      \node[block, text width=1cm, rounded corners= 0ex, draw = none, text
      height=1.5cm]at (.3,0) (cpu3) {Register file}; 
      \node[block, text width=1cm, rounded corners= 0ex, draw= none,
      text height=2cm] at (3, 0) (cpu3){ALU};

      \node[double arrow, fill=Black, rotate=90] at
      (0,-2){\phantom{aa}};
      \node[single arrow, fill=Black] at
      (1.5,-.2){\phantom{aa}};
      \node[single arrow, fill=Black, rotate=180] at
      (1.5,.72){\phantom{aaa}};
    \end{tikzpicture}
\end{frame}
\end{document}

The problem is I am placing the arrows as node, and that is not working. The output of the mwe is:

here

How can I place the arrows in proper way? e.g. can I use the arrow as path?

Kindly help.

BaRud
  • 2,179

2 Answers2

2

You can use arrows as paths.

MWE

\documentclass[10pt,xcolor=dvipsnames,xcolor=table]{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows,arrows.meta}
\begin{document}
\tikzset{block/.style={rectangle, draw, fill=Apricot!70,
text width=10em, text centered, rounded corners=0pt, minimum height=0em}}
\tikzset{arw/.style={>={Triangle[length=3mm,width=5mm]},line width=2mm,draw=gray}}
\begin{frame}[fragile]
        \begin{tikzpicture}[scale=.85]
        \node[block, text width=1cm, draw= none]at (-1.3,0) (cpu1){PC};
        \node[block, text width=1cm, minimum height=2cm, draw = none, right=0.5cm of cpu1] (cpu3) {Register file};
        \node[block, text width=3cm, draw= none, below=0.7cm of cpu3] (cpu2){BUS Interface};
        \node[block, text width=1cm, minimum height=2cm, draw= none,right=1cm of cpu3]  (cpu4){ALU};
        \draw[arw,<->] (cpu3.south|-cpu2.north) -- (cpu3);
        \draw[arw,->] (cpu3.340) -- (cpu4.200);
        \draw[arw,<-] (cpu3.20) -- (cpu4.160);
        \end{tikzpicture}
\end{frame}
\end{document}

enter image description here

nidhin
  • 7,932
  • 1
    @marmot I thought this is what OP was asking for. The question that you mentioned also makes sense. Thanks for the arrows.meta suggestion, with that it looks better. :) – nidhin Dec 04 '18 at 17:54
0

To use the nodes and their shape as if they were figures drawn on the path, you can use the relative placement of the nodes relative to each other. To do this, simply use the syntax of the positioning library you have already loaded.

Thus, instead of anchoring each node to a specific coordinate point, it is sufficient to use the key right = below = below left=, etc.

See page 229 of manual 3.0.1a.

I slightly cleaned up the code of the superfluous: for example, you specify draw=none for each block call. Just delete the draw key in the style of the node. But I'm far from having written everything correctly, for example, the \tikzstyle syntax is obsolete.

\tikzstyle{block} = [rectangle, draw, fill=Apricot!70, 
text width=10em, text centered, rounded corners, minimum height=0em]

Etc.

This is only a first sketch that you need to rework to your liking. I changed some colors to make it easier for you to read this new code.

Sketch and code:

sketch

\documentclass[10pt,xcolor=dvipsnames,xcolor=table]{beamer}
\usepackage{amsmath, tikz}
\usetikzlibrary{positioning,arrows}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{shadows.blur, shapes.arrows}
\synctex=1
% \usepackage{listings}%, fancyvrb}
\usepackage[T1]{fontenc}

\begin{document}
\tikzstyle{sblock} = [rectangle, draw, %fill=Apricot!70, 
text width=5em, text centered, rounded corners, minimum height=0em, node distance=3.5cm]
\tikzstyle{block} = [rectangle, fill=Apricot!70, text centered]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,
minimum height=2em]

\begin{frame}[fragile]
    \begin{tikzpicture}[scale=.85]
      \node[block, text width=1cm, ]at (-1.3,0) (cpu1)
      {PC};
      \node[block, text width=1.2cm,  text height=1.5cm,right=5mm of cpu1](cpu2) {Register file}; 
      \node[block, text width=1cm, ,text height=2cm,right=1.5 of cpu2] (cpu3){ALU};

      \node[double arrow, fill=Black, rotate=90,below = 6mm of cpu2] (double-arrow)
      {\phantom{aa}};
     \node[single arrow, fill=blue,above right=-20mm and 5mm of cpu2] (single-arrow){\phantom{aa}};
      \node[single arrow, fill=red, rotate=180,above right=-5mm and 10mm  of cpu2] {\phantom{aaa}};

      \node[block, text width=3cm, below=1cm of cpu2,below left= 4mm and -3mm of double-arrow] (cpu4){BUS Interface};

    \end{tikzpicture}
\end{frame}
\end{document}
AndréC
  • 24,137