我的 mwe 是(仅 CPU 盒):
\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}
问题是我将箭头放置为节点,但不起作用。mwe 的输出为:
我怎样才能以正确的方式放置箭头?例如,我可以使用箭头作为路径吗?
请帮忙。
答案1
您可以使用箭头作为路径。
平均能量损失
\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}
答案2
要使用节点及其形状,就像它们是路径上绘制的图形一样,您可以使用相对位置节点相对于彼此的相对位置。为此,只需使用positioning
已加载的库的语法即可。
因此,不需要将每个节点锚定到特定的坐标点,只需使用键right =
below =
below left=
等就足够了。
请参阅手册 3.0.1a 第 229 页。
我稍微清理了多余的代码:例如,draw=none
每次block
调用时都要指定。只需删除节点样式中的 draw 键即可。但我还远没有正确地编写所有内容,例如,语法\tikzstyle
已经过时了。
\tikzstyle{block} = [rectangle, draw, fill=Apricot!70,
text width=10em, text centered, rounded corners, minimum height=0em]
ETC。
这只是第一个草图,您需要根据自己的喜好重新设计。我更改了一些颜色,以便您更轻松地阅读此新代码。
草图和代码:
\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}