其他 tikz 旁边的节点

其他 tikz 旁边的节点

我想写一个代码来获取网络包结构。

        1          var         4
-------------------------------------
|   Control   |    Casa   |   Mia   |

目前我有下面的代码,但我注意到在单元格 Control 和 Casa 之间有两行而不是一行。有什么帮助吗?

\documentclass{article}

\usepackage[latin9]{inputenc}
%\usepackage[utf8x]{inputenc}
%\usepackage[spanish]{babel}
%\usepackage[spanish]{translator}
\usepackage[OT1]{fontenc}

%TikZ stuff
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgf}
\usetikzlibrary{shapes,arrows,automata,plotmarks,positioning} 


\begin{document}


\begin{tikzpicture}%[scale=1.5]
    \tikzstyle{every path}=[draw, font=\small]

    \node[right,draw, minimum width=2cm,minimum height=0.8cm,fill=white](b0) {Control};
    \node[right=0cm of b0, draw, minimum width=2cm,minimum height=0.8cm,fill=white](b0) {Casa};
\end{tikzpicture}

\end{document}

编辑1:

现在我有了这个,但图形不在中心,并且不知道如何从控制角画一条线来到达另一行的总数在此处输入图片描述

\begin{figure}    
\newcommand{\size}{\linewidth}

\begin{tikzpicture}%[scale=1]
    \tikzstyle{every path}=[draw, font=\small]

    \node[right,draw, minimum width=0.15*\size,minimum height=0.8cm,fill=white](b0) {Control};
    \node[above=-0.2 of b0, minimum width=0.15*\size,minimum height=0.8cm] {1};
    \node[above left=-0.2 and -0.5 of b0, minimum width=0.2*\size,minimum height=0.8cm] {byte};

    \node[right=0cm of b0, draw, minimum width=0.2*\size,minimum height=0.8cm,fill=white](b1) {Longitud};
    \node[above=-0.2 of b1, minimum width=0.2*\size,minimum height=0.8cm] {1};      

    \node[right=0cm of b1, draw, minimum width=0.6*\size,minimum height=0.8cm,fill=white](b2) {Valor};
    \node[above=-0.2 of b2, minimum width=0.6*\size,minimum height=0.8cm] {8};      


    \node[below left=1 and -2 of b0 ,draw, minimum width=0.2*\size,minimum height=0.8cm,fill=white](h0) {Bloqueo};
    \node[below=-0.2 of h0, minimum width=0.15*\size,minimum height=0.8cm] {1};
    \node[below left=-0.2 and -0.5 of h0, minimum width=0.15*\size,minimum height=0.8cm] {bit};

    \node[right=0cm of h0, draw, minimum width=0.3*\size,minimum height=0.8cm,fill=white](h1) {M\'{a}ximo n$^o$ intentos};
    \node[below=-0.2 of h1, minimum width=0.2*\size,minimum height=0.8cm] {3};      

    \node[right=0cm of h1, draw, minimum width=0.2*\size,minimum height=0.8cm,fill=white](h2) {RSV};
    \node[below=-0.2 of h2, minimum width=0.2*\size,minimum height=0.8cm] {1};      

    \node[right=0cm of h2, draw, minimum width=0.4*\size,minimum height=0.8cm,fill=white](h3) {Intentos restantes};
    \node[below=-0.2 of h3, minimum width=0.4*\size,minimum height=0.8cm] {3};



\end{tikzpicture}
\caption{Mi figura}
\end{figure}

答案1

正如所建议的,我认为matrix这是绘制字节和位字段的一个好选择。下一个代码显示如何使用两个矩阵,每个矩阵有两行,以及如何连接它们的角以表示第二个矩阵是详细字段。

\documentclass[tikz,border=2mm]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{lmodern}
\usepackage{textcomp}
\usetikzlibrary{matrix,positioning}

\begin{document}

%\begin{figure}    
\newcommand{\size}{\linewidth}

\begin{tikzpicture}[
    every path/.style={draw, font=\small},
     labelfield/.style={outer sep=0pt, minimum height=5mm,font=\small, anchor=center},
    field/.style={outer sep=0pt, draw, minimum height=8mm,
    minimum width=#1\size,font=\small,anchor=center}]

    \matrix (A) [matrix of nodes, column sep=-\pgflinewidth,
    row 1/.style={nodes=labelfield}, row 2/.style={nodes={field=.15}}] {
    byte & 1 & 1 & 8 \\
     &  Control & |[field=.2]|Longitud &  |[field=.6]| Valor\\
    };

    \matrix (B) [matrix of nodes, column sep=-\pgflinewidth, 
            below=5mm of A,
            row 2/.style={nodes=labelfield}, 
            row 1/.style={nodes={field=.15}}] {
     &  |[field=.2]| Bloqueo & |[field=.3]|Màximo n\textdegree{}  intentos &  |[field=.2]| RSV & |[field=.2]| Intentos restantes\\
    bit & 1 & 3 & 1 & 3\\
    };

    \draw (A-2-2.south west) -- (B-1-2.north west);
    \draw (A-2-2.south east) -- (B-1-5.north east);

\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容