2

This question already has an answer here:

How to avoid that the styles of a node style pass in a schema included in the node

thus on the ECM below, the node of right becomes green and is cut in 2 and that of left does not change of color but is cut off

enter image description here

\documentclass{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{tikz}
\usetikzlibrary{fit, positioning}
\usetikzlibrary{shapes.multipart}

\begin{document}
\tikzset{rougelarge/.style={fill=red!20,minimum width=15em,minimum height=4em,text width=15em,draw}}

\newcommand{\nodeUn}{
\begin{tikzpicture}
\node[rougelarge](aa){texte sur plusieurs lignes\\texte sur plusieurs lignes};
\node[right=5em of aa,draw](bb){texte};
\end{tikzpicture}
}
\begin{tikzpicture}
\node[rectangle split, rectangle split parts=2,fill=green]{texte sur plusieurs lignes
\nodepart{two}
\nodeUn
};
\end{tikzpicture}
\end{document}

marked as duplicate by user121799, Mensch, Bobyandbob, Stefan Pinnow, Phelype Oleinik Mar 22 '18 at 20:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • You should try to avoid nesting TikZ pictures. – user121799 Mar 16 '18 at 17:03
  • @marmot, can you explain? – rpapa Mar 16 '18 at 17:05
  • 1
    You should avoid nesting TikZ pictures. Nesting is not supported. If it works, that's an unfortunate coincidence. (Unfortunate because it will likely break unexpectedly later.) – cfr Mar 17 '18 at 0:35
1

As I have been told long time ago, I never used a tikzpicture nested in another one. Consider to change your approach.

In this case, one way is to define completely the style of each node as you it looks like ant that will prevent the ineherit interraction problem:

enter image description here

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{tikz}
\usetikzlibrary{fit, positioning}
\usetikzlibrary{shapes.multipart}


\tikzset{
    rouge large/.style={%
        fill=red!20,
        minimum width=15em,
        minimum height=4em,
        text width=15em,
        draw,
        rectangle},
    blanc etroit/.style={%
        draw,
        fill=white,
        rectangle},
    }

\newcommand{\nodeUn}{
\begin{tikzpicture}
    \node[rouge large] (aa)
        {texte sur plusieurs lignes\\texte sur plusieurs lignes};
    \node[right=5em of aa, blanc etroit] (bb) {texte};
\end{tikzpicture}
}


\begin{document}

\begin{tikzpicture}
\node[rectangle split, rectangle split parts=2,fill=green]
                    {texte sur plusieurs lignes
\nodepart{two}
\nodeUn
};
\end{tikzpicture}

\nodeUn
\end{document}
  • 1
    This still nests tikzpictures and this is expected to break. Even if it seems to work, it is going to come unstuck sooner or later - usually sooner, unless later would be less convenient, in which case, later. – cfr Mar 17 '18 at 0:38
3

You put a TikZ picture (stored in the definition of \nodeUn) into the node of another TikZ picture. This very often leads to complications. And there is really no need for that.

\documentclass{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{tikz}
\usetikzlibrary{fit, positioning,backgrounds}
\usetikzlibrary{shapes.multipart}

\begin{document}
\tikzset{rougelarge/.style={fill=red!20,minimum width=15em,minimum height=4em,text width=15em,draw}}
\begin{tikzpicture}
\node[rougelarge](aa){texte sur plusieurs lignes\\texte sur plusieurs lignes};
\node[right=5em of aa,draw](bb){texte};
\path(aa.west)--(bb.east) node[midway,above=1cm](cc){texte sur plusieurs lignes};
\begin{scope}[on background layer]
\node [fit=(aa) (bb) (cc),fill=green,rectangle]{};
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

UPDATE: Of course, you could just switch the option off.

\documentclass{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{tikz}
\usetikzlibrary{fit, positioning}
\usetikzlibrary{shapes.multipart}

\begin{document}
\tikzset{rougelarge/.style={fill=red!20,minimum width=15em,minimum height=4em,text width=15em,draw}}

\newcommand{\nodeUn}{
\begin{tikzpicture}[rectangle split parts=1]
\node[rougelarge](aa){texte sur plusieurs lignes\\texte sur plusieurs lignes};
\node[right=5em of aa,draw](bb){texte};
\end{tikzpicture}
}
\begin{tikzpicture}
\node[rectangle split, rectangle split parts=2,fill=green]{texte sur plusieurs lignes
\nodepart{two}
\nodeUn
};
\end{tikzpicture}
\end{document}

enter image description here

I do not recommend going this way. It is foreseeable that it will backfire.

  • Non, I don't want a fit node. is there a command that resets styles to default styles? – rpapa Mar 16 '18 at 17:22
  • 2
    @rpapa Not that I know. All I know is that nesting TikZ pictures can have undesired consequences, i.e. lead to a result that cannot be controlled. Of course, there are ways to retrieve the TikZ keys (e.g. using \pgfkeysvalueof), i.e. your "default values", but I strongly recommend not to go this way. In this case, you'd have to store these values in some macros and then set them in the inner node. What a mess! – user121799 Mar 16 '18 at 17:33
  • 1
    @rpapa And even with the mess, it won't work properly. – cfr Mar 17 '18 at 0:36

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