输入输出框图

输入输出框图

我正在尝试制作如下的 IO 框图: 在此处输入图片描述

我正在使用参考实现框图

目前我在这里遇到困难,有人能帮我完成框图吗?任何帮助都将不胜感激。问候

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usepackage{amsmath,bm,times}
\newcommand{\mx}[1]{\mathbf{\bm{#1}}} % Matrix command
\newcommand{\vc}[1]{\mathbf{\bm{#1}}} % Vector command
\begin{document}
\pagestyle{empty}
% We need layers to draw the block diagram
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
% Define a few styles and constants
\tikzstyle{sensor}=[draw, fill=blue!20, text width=5em, 
text centered, minimum height=2.5em]
\tikzstyle{ann} = [above, text width=6em]
\tikzstyle{naveqs} = [sensor, text width=6em, fill=red!20, 
minimum height=12em, rounded corners]
\def\blockdist{2.3}
\def\edgedist{2.5}
\begin{tikzpicture}
\node (naveq) [naveqs] {conv\_encoder};
\draw [->] (naveq.50) -- node [ann] {output\_tvalid } + (\edgedist,0) ;
   % node[right] {$\vc{v}^l$};
\draw [->] (naveq.20) -- node [ann] {output\_tdata} + (\edgedist,0); 
    %node[right] { $\mx{R}_l^b$};
\draw [->] (naveq.-25) -- node [ann] {output\_tlast} + (\edgedist,0);
    %node [right] {$\mx{R}_e^l$};
\draw [->] (naveq.-50) -- node [ann] {ctrl\_tvalid} + (\edgedist,0); 
    %node[right] {$z$};
\end{tikzpicture}
\end{document}

答案1

从问题来看,你被困在哪里还不完全清楚。但你可以做一些事情,让你的 MWE 接近实际情况:

  • 编码器侧面的定位可以通过使用上下角来解决。然后你可以说($(naveq.south east)!0.5!(naveq.north east)$)在中间到右边。你需要 tikz 库calc
  • 要将文本放置在箭头的边缘,请将节点放在箭头的末端。
  • 左侧箭头可以反向绘制,即从箭头开始向左绘制。
  • arrows.meta您显示的箭头尖端相当大,因此我使用了允许缩放的库。

然后图片就变成了

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,calc,arrows.meta}
\usepackage{amsmath,bm,times}
\newcommand{\mx}[1]{\mathbf{\bm{#1}}} % Matrix command
\newcommand{\vc}[1]{\mathbf{\bm{#1}}} % Vector command
\begin{document}
\pagestyle{empty}
% We need layers to draw the block diagram
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
% Define a few styles and constants
\tikzstyle{sensor}=[draw, fill=blue!20, text width=5em, 
text centered, minimum height=2.5em]
\tikzstyle{ann} = [above, text width=6em]
\tikzstyle{naveqs} = [sensor, text width=6em, fill=red!20, 
minimum height=12em, rounded corners]
\def\blockdist{2.3}
\def\edgedist{1}
\begin{tikzpicture}[>={Latex[scale=1.5]}]
  %% Encoder
  \node (naveq) [naveqs] {conv\_encoder};
  %% Inputs
  \draw[<-] ($(naveq.south west)!0.9!(naveq.north west)$) -- +(-\edgedist,0) node [left] {clk};
  \draw[<-] ($(naveq.south west)!0.75!(naveq.north west)$) -- +(-\edgedist,0) node [left] {rst};
  \draw[<-] ($(naveq.south west)!0.6!(naveq.north west)$) -- +(-\edgedist,0) node [left] {input\_tvalid};
  \draw[<-] ($(naveq.south west)!0.45!(naveq.north west)$) -- +(-\edgedist,0) node [left] {input\_tdata};
  \draw[<-] ($(naveq.south west)!0.3!(naveq.north west)$) -- +(-\edgedist,0) node [left] {input\_tlast};
  \draw[<-] ($(naveq.south west)!0.1!(naveq.north west)$) -- +(-\edgedist,0) node [left] {ctrl\_tvalid};
  %% Outputs
  \draw[->] ($(naveq.south east)!0.9!(naveq.north east)$) -- +(\edgedist,0) node [right] {ctrl\_tready};
  \draw[->] ($(naveq.south east)!0.75!(naveq.north east)$) -- +(\edgedist,0) node [right] {output\_tvalid};
  \draw[->] ($(naveq.south east)!0.6!(naveq.north east)$) -- +(\edgedist,0) node [right] {output\_tlast};
  \draw[->] ($(naveq.south east)!0.4!(naveq.north east)$) -- +(\edgedist,0) node [right] {output\_tdata};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

这展示了如何使用局部边界框创建超节点。

\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,calc,backgrounds}
\usepackage{amsmath,bm,times}
\newcommand{\mx}[1]{\mathbf{\bm{#1}}} % Matrix command
\newcommand{\vc}[1]{\mathbf{\bm{#1}}} % Vector command
\begin{document}
% Define a few styles and constants
\tikzstyle{sensor}=[draw, fill=blue!20]%
\tikzstyle{ann} = [above, midway]%
\tikzstyle{naveqs} = [sensor, text width=6em, fill=red!20, 
minimum height=12em, rounded corners]%
\def\blockdist{2.3}%
\def\edgedist{2.5}%
\begin{tikzpicture}
\node (navname) [sensor] {conv\_encoder};% determine size
\begin{scope}[local bounding box=naveq, on background layer]
  \draw[rounded corners, fill=pink] ($(navname.south west) + (-2em,-4em)$) rectangle ($(navname.north east) + (2em,2em)$);
\end{scope}
\draw [->] ($(naveq.north east)!.2!(naveq.south east)$) -- +(\edgedist,0) node [ann] {output\_tvalid }  ;
   % node[right] {$\vc{v}^l$};
\draw [->] ($(naveq.north east)!.4!(naveq.south east)$) -- +(\edgedist,0) node [ann] {output\_tdata}; 
    %node[right] { $\mx{R}_l^b$};
\draw [->] ($(naveq.north east)!.6!(naveq.south east)$) -- +(\edgedist,0) node [ann] {output\_tlast};
    %node [right] {$\mx{R}_e^l$};
\draw [->] ($(naveq.north east)!.8!(naveq.south east)$) -- +(\edgedist,0) node [ann] {ctrl\_tvalid}; 
    %node[right] {$z$};
\end{tikzpicture}
\end{document}

演示

答案3

使用matrix包、编码器形状backgroundsfit箭头arrows.meta

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                backgrounds,
                fit,
                matrix}
\begin{document}
\begin{tikzpicture}
    \matrix (m) [
        matrix of nodes,
        nodes in empty cells,
        nodes = {
            text height=2ex, text depth=0.5ex,
            inner sep=1mm, outer sep=0mm,
        },
        row sep = 0mm, column sep = 7mm,
        column 1/.style = {nodes={align=right, anchor=south east}},
        column 2/.style = {nodes={align=center, anchor=south, text width=13ex}}, % change width of block here
        column 3/.style = {nodes={align=left, anchor=south west}},
    ] {
    clk             &                   &   ctrl\_tready    \\
    rst             &                   &   output\_tvalid  \\
    input\_tvalid   &                   &   output\_tlast   \\
    input\_tdata    &   conv\_encoder   &                   \\
    input\_tlast    &                   &   output\_tdata   \\
                    &                   &                   \\
    ctrl\_tvalid    &                   &                   \\
    };
    \scoped[on background layer]
        \node (enc)  [draw, rounded corners, semithick, fill=gray!10,
                      inner sep = 0mm, outer sep= 0mm,
                      fit=(m-1-2) (m-7-2)] {};
    \foreach    \i in {1,...,5,7}
        \draw[-{Triangle[angle=60:2pt 4]}]    (m-\i-1) -- (m-\i-2);
    \foreach    \i in {1,...,3,5}
        \draw[-{Triangle[angle=60:2pt 4]}]    (m-\i-2) -- (m-\i-3);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容