
바이트를 표현하기 위해 다중 부분 노드를 생성하려고 합니다.
나는 글을 쓰거나 얻을 수 있었으면
\Byte{0 1 0 0 1 1 0 0}
좋겠다 \Byte {0, 1, 0, 0, 1, 1, 0, 0}
.
\documentclass[12pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\newcommand{\Byte}{
\node [rectangle split,rectangle split parts=8, rectangle split horizontal,draw ] at (2,2)
{\nodepart{one}0\nodepart{two}1\nodepart{three}0\nodepart{four}0\nodepart{five}1\nodepart{six}1\nodepart{seven}0\nodepart{eight}0};
}
\begin{document}
\begin{tikzpicture}
\Byte
\end{tikzpicture}
\end{document}
답변1
\foreach
여기에 a를 사용 하여 노드 콘텐츠를 구축하고 노드를 호출하기 전에 노드를 준비하는 두 번째 원하는 호출로 이를 수행하는 한 가지 방법이 있습니다 .
\documentclass[12pt]{standalone}
%\url{http://tex.stackexchange.com/q/67923/86}
\usepackage{etoolbox}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\def\numtext#1{%
\ifcase#1\or one\or two\or three\or four\or five\or six\or seven\or eight\or nine\or ten\or
eleven\or twelve\or thirteen\or fourteen\or fifteen\or sixteen\or seventeen\or eighteen\or nineteen\or twenty\or Lots\fi}
\newcommand{\Byte}[1]{
\def\nodecontents{}%
\foreach[count=\l] \k in {#1} {
\xappto{\nodecontents}{\noexpand\nodepart{\numtext{\l}}\k}
}
\node [rectangle split,rectangle split parts=8, rectangle split horizontal,draw ] at (2,2)
{\nodecontents};
}
\begin{document}
\begin{tikzpicture}
\Byte {0, 1, 0, 0, 1, 1, 0, 0}
\end{tikzpicture}
\end{document}
결과:
답변2
이를 사용하면 \def
다음과 같은 내용을 작성할 수 있습니다 \Byte(0,1,0,0,1,0,1,1)
.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\def\Byte(#1,#2,#3,#4,#5,#6,#7,#8){
\node [rectangle split,rectangle split parts=8, rectangle split horizontal,draw ] at (2,2)
{\nodepart{one}#1\nodepart{two}#2\nodepart{three}#3\nodepart{four}#4\nodepart{five}#5\nodepart{six}#6\nodepart{seven}#7\nodepart{eight}#8};
}
\begin{document}
\begin{tikzpicture}
\Byte(0,1,0,0,1,0,1,1)
\end{tikzpicture}
\end{document}