2

In the case, when you have in some shape (rectangle in my case) a TikZ picture, than it seems that parameters of outer shape also influences on parameters of inner picture. This can be eliminate with redefinition of all this parameters. But, what to do, if outer shape has determined "text width", but in shape of inner picture I like to determine only minimum width" (that the width of shape is automatically adjust to width of text)? For example:

\documentclass[12pt,tikz,border=1mm]{standalone}
\usetikzlibrary{chains,shapes.multipart}

    \begin{document}
        \begin{tikzpicture}[start chain = going right]
        \node[rectangle split,rectangle split parts=2,
              inner ysep=1mm, inner ysep=2mm, text width=55mm, draw] 
        {adjust time\qquad
    \tikz[every node/.style={shape=rectangle,
                             inner xsep=0.5mm,outer sep=0mm, 
                             text width=1.1ex,% here I like to have minimum width ...
                             node distance=0.5mm,on chain}]
        {\node[fill=gray!10]{0};\node[fill=gray!10]{0};\node{:};
         \node[fill=gray!10]{0};\node[fill=gray!10]{0};}
    \nodepart{two} only text
                    };
        \end{tikzpicture}
    \end{document}

Is there a way to tell inside picture, that "text width" determined for outer shape should not influence on text width of text width of inner influence or to determine it in inner shape, that it will automatically adjust to width of actual text? enter image description here

On above picture the width of node with semicolon (:) is to wide, i like that width will be automatically adjusted to its width.

I also like to solve a problem, how to align text in inner rectangle with text in outer one.

4

To align the baseline of the text in the inner node on the baseline of the outer text you can use \tikz[baseline,nodes={anchor=base,...}] for the inner picture.

To prevent the influence of the outer node options save the inner picture in a box:

\documentclass[12pt,tikz,border=1mm]{standalone}
\usetikzlibrary{chains,shapes.multipart}
\newbox\mytikzBox
\newcommand{\savetikzBox}[2][\mytikzBox]{%
  \sbox#1{\pgfinterruptpicture#2\endpgfinterruptpicture}}

\begin{document}
\begin{tikzpicture}
  \savetikzBox{%
    \tikz[
      baseline,
      start chain = going right,
      nodes={anchor=base,
        fill=gray!10,
        inner xsep=0.5mm,outer sep=0mm,
        on chain}
        ,node distance=.5mm
      ]
    {\node{0};\node{0};
    \node[fill=none,inner xsep=0pt]{:};
    \node{0};\node{0};}
  }
  \node[
    rectangle split,rectangle split parts=2,
    inner ysep=2mm,
    text width=55mm,
    draw] 
  {adjust time\qquad\usebox\mytikzBox
  \nodepart{two} only text
  };
\end{tikzpicture}
\end{document}

enter image description here

  • Thank you very much! Your solution also work if I collect options for inner picture as well four outer node in one "tikzset" (with different name, of course). – Zarko Apr 19 '14 at 1:57

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.