我正在尝试使用 TikZ 创建下图:
除了文本之外,我不知道如何创建其他任何东西。
到目前为止,我拥有的代码只生成文本。我找不到按我想要的方式生成任何箭头的方法:
\begin{tikzpicture}
\draw[->] (0, 1) -- (2, 1);
\node[draw] at (0, 0) {\ttfamily 01101100};
\node[draw] at (2, 0) {\ttfamily 00011110};
\node[draw] at (4, 0) {\ttfamily 10111100};
\node[draw] at (6, 0) {\ttfamily 00000000};
\end{tikzpicture}
笔记曾经有过箭头尝试,但结果与我想要的无关;而且,我的节点周围有一个矩形边界框。
答案1
一个可能的解决方案。
\documentclass[border=3mm,tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw [<-, very thick] (0,0) -- ++(1.7,0) node [midway, below] {01101100} node [midway, above] {\scriptsize bit order};
\draw [<-, very thick] (2,0) -- ++(1.7,0) node [midway, below] {00011110};
\draw [<-, very thick] (4,0) -- ++(1.7,0) node [midway, below] {10111100};
\draw [<-, very thick] (6,0) -- ++(1.7,0) node [midway, below] {00000000};
\draw [->, very thick] (0,0.5) -- (7.7,0.5) node [midway, above] {\scriptsize byte order};
\end{tikzpicture}
\end{document}
编辑:根据修改的解决方案玛丽安的建议:
\documentclass[border=3mm,tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\draw [<-, very thick] (0,0) node (start) {} -- ++(1.7,0) node [midway, below] {\ttfamily 01101100} node [midway, above] {\scriptsize bit order};
\draw [<-, very thick] (2,0) -- ++(1.7,0) node [midway, below] {\ttfamily 00011110};
\draw [<-, very thick] (4,0) -- ++(1.7,0) node [midway, below] {\ttfamily 10111100};
\draw [<-, very thick] (6,0) -- ++(1.7,0) node (end) {} node [midway, below] {\ttfamily 00000000};
\draw [->, very thick] ($(start) + (0,0.5)$) -- ($(end) + (0,0.5)$) node [midway, above] {\scriptsize byte order};
\end{tikzpicture}
\end{document}
答案2
只是为了好玩:用矩阵。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[node font=\sffamily]
\begin{scope}[local bounding box=A]
\matrix[matrix of nodes,inner sep=0pt,nodes={font=\ttfamily,inner sep=1pt},column sep=1em] (mat)
{ 01101100 & 00011110 & 10111100 & 00000000 \\
};
\foreach \X in {1,...,4}
{\draw[-latex,thick] ([yshift=0.5ex]mat-1-\X.north east) --
([yshift=0.5ex]mat-1-\X.north west)
\ifnum\X=1
node[midway,above] {bit order}
\fi;}
\end{scope}
\draw[-latex,thick] ([yshift=1ex]A.north west) --
([yshift=1ex]A.north east) node[midway,above] {byte order};
\end{tikzpicture}
\end{document}