# How to place two plots inside a node?

I'm eager to have two plots (of the algebraic functions) placed horizontally inside a node. I'd like them to be signed, so something like caption (below the plot) is needed.

One of them — "the good case" — would be to the left inside the node, and "the bad case" would be to the right.

Here's my code sample below. It compiles. After uncommenting it could provide the solution, but, unfortunately, it does not. One look is worth a thousand words — just compile and become as dissatisfied with the output as me.

\documentclass[11pt]{article}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{backgrounds,fit,positioning}

\begin{document}

\begin{center}
\begin{tikzpicture}[remember picture]

\node[fill=white,rounded corners,text width=16cm,text=black,align=right]
(teacher1) {Some text goes here};

\node[fill=white,rounded corners,text width=16cm,text=black,align=left,below=of teacher1]
(teacher2) {And here goes the thought and its illustration by means of two plots:

\begin{tikzpicture}[remember picture]

\node (good) {
\begin{tikzpicture}
\node (origingreen) {};
\node[above=of origingreen] (topgreen) {};
\node[right=of origingreen] (rightgreen) {};

\draw [green, thick, samples=50,domain=0:5] plot (\x, {\x + sin(\x r)});
\draw [->] (origingreen) -- (rightgreen) node [right] {\text{t}};
\draw [->] (origingreen) -- (topgreen);
\end{tikzpicture}
%\caption{The good case; well, actually, this caption is really long in my paper}
};

\begin{tikzpicture}
\node (originred) {};
\node[above=of originred] (topred) {};
\node[right=of originred] (rightred) {};

%\draw [red, thick, samples=50,domain=0:5] plot (\x, {(\x*\x*\x)* exp(-\x)});
\draw [->] (originred) -- (rightred) node[right=1pt] {t};
\draw [->] (originred) -- (topred);
\end{tikzpicture}
%\caption{The bad case; well, actually, this caption is really long in my paper}
};

\end{tikzpicture}

};

\begin{scope}[on background layer]
\node [fill=cyan,fit=(teacher1) (teacher2)] {};

\end{scope}

\end{tikzpicture}
\end{center}
\end{document}


The following doesn't work either (figures are not fine if you past them into the node):

\documentclass[11pt]{article}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{backgrounds,fit,positioning}

\begin{document}

\begin{center}
\begin{tikzpicture}[remember picture]

\node[fill=white,rounded corners,text width=16cm,text=black,align=right]
(teacher1)    {Some text goes here};

\node[fill=white,rounded corners,text width=16cm,text=black,align=left,
below=of teacher1] (teacher2) {A text up and above:
\bigskip

\begin{figure}[htp]
\begin{minipage}{0.95\linewidth}
\centering

\newlength{\figwidth}
\setlength{\figwidth}{0.4\linewidth}
\begin{minipage}{\figwidth+1cm}%
\centering
\begin{tikzpicture}
\draw [->] (0,0) -- (5,0) node [right] {$t$};
\draw [->] (0,0) -- (0,5);
\draw [green, thick, samples=50,domain=0:5] plot (\x, {\x + sin(\x r)});
\end{tikzpicture}
\\
the caption
\end{minipage}
\begin{minipage}{\figwidth+1cm}%
\centering
\begin{tikzpicture}
\draw [->] (0,0) -- (5,0) node [right] {$t$};
\draw [->] (0,0) -- (0,5);
\draw [red, thick, samples=50,domain=0:5] plot (\x, {(\x*\x*\x)* exp(-\x)});
\end{tikzpicture}
\\
the caption \\
the prolongation of the caption
\end{minipage}
\end{minipage}
\end{figure}

};

\begin{scope}[on background layer]
\node [fill=cyan,fit=(teacher1) (teacher2)] {};

\end{scope}

\end{tikzpicture}
\end{center}
\end{document}

• Welcome to TeX SE! Nested tikzpictures are known to cause problems. Sometimes you can get away with it, but they are generally to be avoided. Why can't you create the 2 plots as sub-figures? Why do they need to be inside a node? It they really do (which I doubt), you could save each in a box and then just use the boxes inside the node. \newsavebox{\myonebox}\sbox{\myonebox}...\node {\usebox{\myonebox}\usebox{\mytwobox}};... or something similar, but I think that should be a last resort. – cfr Apr 7 '15 at 2:41
• It would be helpful if you would make your code so we can compile it i.e \documentclass... and a document environment. It makes it easier for people to help. – cfr Apr 7 '15 at 2:43
• Thank you for the comment, it's reasonable. Made the complete code from the chunk. – Alex Garkusha Apr 7 '15 at 4:16
• I think they need to be inside a node — it's the current "colourful markup" of all the information in the document (it would be great if you give me another idea of how to make the plain text document colourful). If you compile the first sample, you likely get what I mean. – Alex Garkusha Apr 7 '15 at 4:24
• Note that figures float. So it isn't really surprising that they do not work inside nodes! You can't use captions outside floats, though you could use something like caption's \captionof command. But why not use something like tcolorbox rather than nesting tikzpictures? – cfr Apr 7 '15 at 12:30

Here's a suggestion which doesn't use nesting of tikzpictures. To position the plots I've simply positioned origingreen relative to the teacher2 node using \coordinate (origingreen) at ([yshift=-5cm,xshift=0.5cm]teacher2.south west);. The axis lines are already drawn relative to the origin, so what remains is to shift the plot, and that you can do by adding shift=(origingreen) to the options of the \draw macro.

As the text block in a standard article is narrower than 16cm, I also took the liberty of making the diagram no wider than the \textwidth.

The caption is here just added as a node with text below the origins. If you need actual numbered captions, add \usepackage{caption}, and use \captionof{figure}{caption text} in the node text, instead of just caption text. (See second example below.)

Finally, the white background behind the plots is also drawn on the background layer using the fit library.

\documentclass[11pt]{article}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{backgrounds,fit,positioning}

\begin{document}

\begin{center}
\begin{tikzpicture}[remember picture]

\node[fill=white,rounded corners,text width=0.95\textwidth,text=black,align=right]
(teacher1) {Some text goes here};

\node[text width=0.95\textwidth,align=left,below=of teacher1]
(teacher2) {And here goes the thought and its illustration by means of two plots};

\coordinate (origingreen) at ([yshift=-5cm,xshift=0.5cm]teacher2.south west) {};
\node[above=of origingreen] (topgreen) {};
\node[right=of origingreen] (rightgreen) {};

\draw [green, thick, samples=50,domain=0:5,shift=(origingreen)] plot (\x, {\x + sin(\x r)}) ;
\draw [->] (origingreen) -- (rightgreen) node [right] {\text{t}};
\draw [->] (origingreen) -- (topgreen);

\node [text width=0.43\textwidth,below right=0.3cm and 0cm] (cap1) at (origingreen) {The good case; well, actually, this caption is really long in my paper};

\coordinate (originred) at ([xshift=0.45\textwidth]origingreen) {};
\node[above=of originred] (topred) {};
\node[right=of originred] (rightred) {};

\draw [red, thick, samples=50,domain=0:5,shift=(originred)] plot (\x, {\x*\x*\x)* exp(-\x)});
\draw [->] (originred) -- (rightred) node[right=1pt] {t};
\draw [->] (originred) -- (topred);

\node [text width=0.43\textwidth,below right=0.3cm and 0cm] (cap2) at (originred) {The bad case; well, actually, this caption is really long in my paper};

\begin{scope}[on background layer]
\node [fill=cyan,fit=(teacher1) (teacher2)(cap1)] {};
\node [fill=white,rounded corners,inner sep=0pt,fit=(teacher2)(cap1)] (plots) {};
\end{scope}

\end{tikzpicture}
\end{center}
\end{document}


# With numbered captions

\documentclass[11pt]{article}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{caption}

\usetikzlibrary{backgrounds,fit,positioning}

\begin{document}

\begin{center}
\begin{tikzpicture}[remember picture]

\node[fill=white,rounded corners,text width=0.95\textwidth,text=black,align=right]
(teacher1) {Some text goes here};

\node[text width=0.95\textwidth,align=left,below=of teacher1]
(teacher2) {And here goes the thought and its illustration by means of two plots};

\coordinate (origingreen) at ([yshift=-5cm,xshift=0.5cm]teacher2.south west) {};
\node[above=of origingreen] (topgreen) {};
\node[right=of origingreen] (rightgreen) {};

\draw [green, thick, samples=50,domain=0:5,shift=(origingreen)] plot (\x, {\x + sin(\x r)}) ;
\draw [->] (origingreen) -- (rightgreen) node [right] {\text{t}};
\draw [->] (origingreen) -- (topgreen);

\node [text width=0.43\textwidth,below right=0.3cm and 0cm] (cap1) at (origingreen) {\captionof{figure}{The good case; well, actually, this caption is really long in my paper}};

\coordinate (originred) at ([xshift=0.45\textwidth]origingreen) {};
\node[above=of originred] (topred) {};
\node[right=of originred] (rightred) {};

\draw [red, thick, samples=50,domain=0:5,shift=(originred)] plot (\x, {\x*\x*\x)* exp(-\x)});
\draw [->] (originred) -- (rightred) node[right=1pt] {t};
\draw [->] (originred) -- (topred);

\node [text width=0.43\textwidth,below right=0.3cm and 0cm] (cap2) at (originred) {%
\captionof{figure}{The bad case; well, actually, this caption is really long in my paper}};

\begin{scope}[on background layer]
\node [fill=cyan,fit=(teacher1) (teacher2)(cap1)] {};
\node [fill=white,rounded corners,inner sep=0pt,fit=(teacher2)(cap1)] (plots) {};
\end{scope}

\end{tikzpicture}
\end{center}
\end{document}