This code draws sequence of words, each word in a separate block. I want to manipulate it as one block. For example, how can I get next picture?enter image description here (I want to add $\rho$ in front of it).



\tikzset{DNA Style/.style={minimum size=0.5cm, draw=gray, line width=1pt, inner sep = 2pt}}{}

\newcounter{ColumnCounter}% Prefix for node labels

    % https://tex.stackexchange.com/questions/12091/tikz-foreach-loop-with-macro-defined-list
    \foreach [count=\xi] \Label/\Color in \Sequence {%
            \node [DNA Style, fill=\Color, anchor=west] (\NodeName) {\Label};
            \node [DNA Style, fill=\Color, anchor=west, xshift=-\pgflinewidth] at (\PreviousNode.east)(\NodeName) {\Label};
  • 1
    You can include label=left:{$\rho$:} in the options of the first node, maybe with label distance=.5cm or something like that. – Qrrbrbirlbel May 6 '13 at 8:43
  • @Qrrbrbirlbel I have problems with accessing the first node. If I write \DNASequence{mysec}{C/cyan, B/red}; then I should access first node with mysec-1, right? – ashim May 6 '13 at 8:57
  • The first node is the one in the true branch of \IfStrEq. The correct syntax would be \DNASequence[mysec]{C/cyan, B/red}. But the \DNASequence doesn’t reset the ColumnCounter, so you might end-up with mysec-10 instead of -0 if the previous \DNASequence had 10 nodes. – Qrrbrbirlbel May 6 '13 at 9:03
  • @Qrrbrbirlbel I tried you suggestion, I have problem that the label is too close to the edge of a page. I tried to add two nodes in \IfStrEq but it does not draw two nodes. – ashim May 6 '13 at 9:16
  • Nevermind, I was able to add extra node which is a label essentially. Anyway thanks! – ashim May 6 '13 at 9:22

You can either use an extra node or a label. I also have simplified the macro with the usage of the chains library which automatically names the node <chain name>-<increasing integer>.



  @expand me/.style={#1},% auxiliary style
  DNA Style/.style={minimum size=0.5cm, draw=gray, line width=1pt, inner sep = 2pt}

    % http://tex.stackexchange.com/questions/12091/tikz-foreach-loop-with-macro-defined-list
    \scope[start chain=#1 going right, node distance=+-\pgflinewidth]
      \foreach \Label/\Style[count=\xi] in \Sequence {
        \IfStrEq{\Style}{}{\def\Style{none}\tikzset{DNA Style/.append style={draw=none}}}{}
        \node [DNA Style, fill=\Style, anchor=west, on chain=#1] {\Label};
\tikz[nodes={text depth=+0pt,font=\vphantom{A}}]{
  \DNASequence[Example 1]{$\rho$:/, C/cyan, B/red}

  \DNASequence[Example 1]{C/cyan, B/red}
  \path [late options={name=Example 1-1,label={[text depth=+0pt,label distance=.5cm]left:$\rho$:\vphantom{A}}}];


enter image description here

enter image description here

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.