3

I'm trying to draw multiple bit strings below and next to each other. Unfortunately, my current solution does not what I want. I've created a single bit string but adding another one next to it leads to the problem that it is cut off at the edge.

What I want is something like that: example. So I want another array on the right side and two others below.

This is what I have at the moment:

\documentclass[tikz, border=3mm]{standalone}
\usetikzlibrary{chains,decorations.pathreplacing}

\begin{document}
    \begin{tikzpicture}[
node distance=0pt,
 start chain = A going right,
    X/.style = {rectangle, draw,% styles of nodes in string (chain)
                minimum width=2ex, minimum height=3ex,
                outer sep=0pt, on chain},
                        ]
\foreach \i in {0,0,1,1,0,0,1,0,0}
    \node(p1)[X] {\i};
\hspace*{5mm}
\foreach \j in {1,0,0,1,1,0,0,1,0}
    \node(p2)[X] {\j};

    \end{tikzpicture}
\end{document}
3
  • As for your meanwhile deleted comment: I added a possible way in the second part of my post below. – user230294 Dec 8 '20 at 18:54
  • I changed your code to highlight a single element. Is there also a way to draw a thick border on specific elements, e.g. the 3th and the 6th of a single chain (and not on all chains)? – joni Dec 11 '20 at 9:04
  • I think so. Probably you want to ask a separate question for this. – user230294 Dec 11 '20 at 15:17
5

You only need to start different chains.

\documentclass[tikz, border=3mm]{standalone}
\usetikzlibrary{chains,decorations.pathreplacing}

\begin{document}
    \begin{tikzpicture}[
node distance=0pt,
    X/.style = {rectangle, draw,% styles of nodes in string (chain)
                minimum width=2ex, minimum height=3ex,
                outer sep=0pt, on chain},
                        ]
\begin{scope}[start chain = A1 going right]
\foreach \i in {0,0,1,1,0,0,1,0,0}
    \node[X] {\i};
\end{scope}
% 
\begin{scope}[start chain = A2 going right,yshift=-1cm]
\foreach \j in {1,0,0,1,1,0,0,1,0}
    \node(p2)[X] {\j};
\end{scope}
%
\begin{scope}[start chain = B1 going right,xshift=5cm]
\foreach \i in {0,0,1,1,0,0,1,0,0}
    \node[X] {\i};
\end{scope}

\end{tikzpicture}
\end{document}

For a more structured construction of these you may work with pics, and put them in a matrix. You can also add styles, here I added ibold which is an integer form which on the border will be drawn thick. You can add more of such keys as needed. pics also have the advantage that the nodes inside inherit the name from the pic, so

 \draw[thick,-stealth] (L2-5.south) to[out=-90,in=90,looseness=0.6] (R3-4.north);

will connect the 5th node of the L2 chain with the 4th node of the R3 chain, as illustrated in

\documentclass[tikz, border=3mm]{standalone}
\usetikzlibrary{chains}

\begin{document}
    \begin{tikzpicture}[ibold/.initial=20,
node distance=0pt,
    X/.style = {rectangle, draw,% styles of nodes in string (chain)
                minimum width=2ex, minimum height=3ex,
                outer sep=0pt, on chain},
                pics/.cd,chain/.style={code={
                    \begin{scope}[start chain =A going right,pic actions]
                \foreach \i [count=\j]in {#1}
                 {\unless\ifnum\j<\pgfkeysvalueof{/tikz/ibold}
                 \tikzset{X/.append style={thick}}
                 \fi
                 \node  [X] (-\j) {\i};}
                \end{scope}
                }}]
\matrix[column sep=1cm,row sep=8mm]{
\pic[ibold=5](L1){chain={0,0,1,1,0,0,1,0,0}};
&
\pic[ibold=6](R1){chain={0,0,1,1,0,0,1,0,0}};\\
\pic[ibold=3](L2){chain={1,0,0,1,1,0,0,1,0}};
&
\pic(R2){chain={0,0,1,1,0,0,1,0,0}};\\
\pic(L3){chain={0,0,1,1,0,0,1,0,0}};
&
\pic(R3){chain={0,0,1,1,0,0,1,0,0}};\\
};
\draw[thick,-stealth] (L1-6.south) -- (R2-3.north);
\draw[thick,-stealth] (L2-5.south) to[out=-90,in=90,looseness=0.6] (R3-4.north);
\end{tikzpicture}
\end{document}

enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.