# Adding ovals to a Tikz diagram

I have two tikz diagrams, one more complex with a larger number of nodes, and ovals around the nodes; and a simpler one which I made by commenting out, and changing the code from the original.

So far I can't get the code for the ovals around the nodes to work. Here is the code for the less complex diagram including the commented out code for the removed nodes, and the ovals i want to reintroduce.

Could someone help me add ovals to this diagram? Particularly so each of the ovals is the same size and shape.

\documentclass[a4paper,11pt,twoside]{report}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,calc,arrows.meta,shapes,fit}
\usetikzlibrary{arrows,automata}
\begin{document}
\begin{tikzpicture}[loose/.style={inner sep=.7em}]
\newcommand{\p}{\mathbf{p}}
\newcommand{\x}{\mathbf{x}}
\node(p){$\p$};
\node[below=1 of p](pb){$\bar \p$};
%\node[below=2.5 of pb](pt){$\tilde \p$};
\node[right=4 of $(p)!0.5!(pb)$](x1){$\x(\cdot;\p,I)$};
%\node[right =4 of $(pb)!0.5!(pt)$] (x2){$\x(\cdot;\tilde\p,I)$};
%\node[below=2.5 of x1] (x2){$\x(\cdot;\tilde\p,I)$};
\node[right =4 of x1](y){$y(\cdot;\p,I)$};
\draw[-Latex] (p) -- node [above,loose]{$X_\Pi(\p,I)$} (x1);
\draw[-Latex] (pb) -- node [below,loose]{$X_\Pi(\bar\p,I)$} (x1);
%\draw[-Latex] (pt) -- node [below,loose]{$X_\Pi(\tilde\p,I)$} (x2.west);
\draw[-Latex] (x1) -- node [above,loose]{$Y_\Sigma(\x(\cdot;\p,I))$} (y);
%\draw[-Latex] (x2) -- node [below,inner sep=1.2em]{$Y_\Sigma(\x(\cdot;\tilde\p,I))$} (y);
%elipses
%\node[ellipse,draw, fit={(p)($(pb)+(1,0)$)($(pb)-(1,0)$)},inner sep=0mm,label=$\Omega$] (eP) {};
%\node[ellipse,draw, fit={($(p.north)+(4,0)$)($(pt.south)+(4,0)$)(x1)($(x1)+(1,0)$)($(x1)-(1,0)$)},inner
%sep=0mm,label=$\mathscr{F}_\Pi$] {};
%\node[ellipse,draw,%dashed,dotted,thick
% fit={($(p.north)!(y)!($(p.north)+(1,0)$)$)($(pt.south)!(y)!($(pt.south)+(1,0)$)$)($(y)+(1,0)$)($(y)-(1,0)$)},inner
%sep=0mm,label=$\mathscr{G}_\Sigma$]{};
\end{tikzpicture}
\end{document}


So far I can't make it work - Ican't add ovals to the simpler diagram. Does anyone know how to do this?

This diagram shows the more complex diagram this came from. I don't want this structure of branches and nodes, but this is how I would like the ovals to look.

• Can you add, please, an image what exactly would you like? – Sebastiano Aug 3 '18 at 20:36
• make your code snippet compilable (extend them to complete but small as possible document, please. also consider @Sebastiano comment. your question is not clear. help us to help you! – Zarko Aug 3 '18 at 20:48
• @Zarko Thank you very much also for the citation. – Sebastiano Aug 3 '18 at 20:58
• now we see, what you like to obtain. now, please complete your code sniped to document beginning with \documentclass{...} and ending with end{document} that we can copy and compile as it is in our computers. – Zarko Aug 3 '18 at 21:07

But if I add the necessary preamble and uncomment the commented out pieces, I get almost the desired picture. Just had to introduce an auxiliary coordinate in the middle between x1 and x2.

\documentclass[border=3.14mm,tikz]{standalone}
\usepackage{mathrsfs}
\usetikzlibrary{positioning,calc,arrows.meta,shapes.geometric,fit}
\begin{document}
\begin{tikzpicture}[loose/.style={inner sep=.7em}]
\newcommand{\p}{\mathbf{p}}
\newcommand{\x}{\mathbf{x}}
\node(p){$\p$};
\node[below=1 of p](pb){$\bar \p$};
\node[below=2.5 of pb](pt){$\tilde \p$};
\node[right=4 of $(p)!0.5!(pb)$](x1){$\x(\cdot;\p,I)$};
\node[right =4 of $(pb)!0.5!(pt)$] (x3){$\x(\cdot;\tilde\p,I)$};
\node[below=2.5 of x1] (x2){$\x(\cdot;\tilde\p,I)$};
\coordinate (x) at ($(x1.east)!0.5!(x2.east)$);
\node[right =4 of x](y){$y(\cdot;\p,I)$};
\draw[-Latex] (p) -- node [above,loose]{$X_\Pi(\p,I)$} (x1);
\draw[-Latex] (pb) -- node [below,loose]{$X_\Pi(\bar\p,I)$} (x1);
\draw[-Latex] (pt) -- node [below,loose]{$X_\Pi(\tilde\p,I)$} (x2.west);
\draw[-Latex] (x1) -- node [above,loose]{$Y_\Sigma(\x(\cdot;\p,I))$} (y);
\draw[-Latex] (x2) -- node [below,inner sep=1.2em]{$Y_\Sigma(\x(\cdot;\tilde\p,I))$} (y);
%elipses
\node[ellipse,draw, fit={(p)($(pb)+(1,0)$)($(pb)-(1,0)$)},inner sep=0mm,label=$\Omega$] (eP) {};
\node[ellipse,draw, fit={($(p.north)+(4,0)$)($(pt.south)+(4,0)$)(x1)($(x1)+(1,0)$)($(x1)-(1,0)$)},inner
sep=0mm,label=$\mathscr{F}_\Pi$] {};
\node[ellipse,draw,%dashed,dotted,thick
fit={($(p.north)!(y)!($(p.north)+(1,0)$)$)($(pt.south)!(y)!($(pt.south)+(1,0)$)$)($(y)+(1,0)$)($(y)-(1,0)$)},inner
sep=0mm,label=$\mathscr{G}_\Sigma$]{};
\end{tikzpicture}
\end{document}


W/O the commented out stuff:

\documentclass[border=3.14mm,tikz]{standalone}
\usepackage{mathrsfs}
\usetikzlibrary{positioning,calc,arrows.meta,shapes.geometric,fit}
\begin{document}
\begin{tikzpicture}[loose/.style={inner sep=.7em},
oval/.style={ellipse,draw}]
\newcommand{\p}{\mathbf{p}}
\newcommand{\x}{\mathbf{x}}
\node(p){$\p$};
\node[below=1 of p](pb){$\bar \p$};
\node[oval,fit=(p) (pb)]{};
\node[right=4 of $(p)!0.5!(pb)$](x1){$\x(\cdot;\p,I)$};
\node[oval,fit=(x1)]{};
\node[right =4 of x1](y){$y(\cdot;\p,I)$};
\draw[-Latex] (p) -- node [above,loose]{$X_\Pi(\p,I)$} (x1);
\draw[-Latex] (pb) -- node [below,loose]{$X_\Pi(\bar\p,I)$} (x1);
\draw[-Latex] (x1) -- node [above,loose]{$Y_\Sigma(\x(\cdot;\p,I))$} (y);
\node[oval,fit=(y)]{};
\end{tikzpicture}
\end{document}


As for your comment: you can easily adjust the "tightness" of the ovals by decreasing inner sep (perhaps even to negative values, if needed). And for the all but the first oval, you do not need to use fit at all.

\documentclass[border=3.14mm,tikz]{standalone}
\usepackage{mathrsfs}
\usetikzlibrary{positioning,calc,arrows.meta,shapes.geometric,fit}
\begin{document}
\begin{tikzpicture}[loose/.style={inner sep=.7em},
oval/.style={ellipse,draw}]
\newcommand{\p}{\mathbf{p}}
\newcommand{\x}{\mathbf{x}}
\node(p){$\p$};
\node[below=1 of p](pb){$\bar \p$};
\node[oval,inner sep=-2pt,fit=(p) (pb)]{};
\node[right=4 of $(p)!0.5!(pb)$,oval](x1){$\x(\cdot;\p,I)$};
\node[right =4 of x1,oval](y){$y(\cdot;\p,I)$};
\draw[-Latex] (p) -- node [above,loose]{$X_\Pi(\p,I)$} (x1);
\draw[-Latex] (pb) -- node [below,loose]{$X_\Pi(\bar\p,I)$} (x1);
\draw[-Latex] (x1) -- node [above,loose]{$Y_\Sigma(\x(\cdot;\p,I))$} (y);
\end{tikzpicture}
\end{document}


• that's close but I don't want the nodes that I had commented out. – Abijah Aug 3 '18 at 21:13
• @Abijah Better now? – user121799 Aug 3 '18 at 21:17
• Nearly perfect, is there anyway the ovals could be closer in shape to those in the other image? – Abijah Aug 3 '18 at 21:42
• @Abijah Just set oval/.style={ellipse,draw,inner sep=-2pt} for instance. – user121799 Aug 3 '18 at 22:01
• i try to reproduce your second image (as i understood your question, you looking for it).
• for node placement i use matrix. by this the size of ellipses can be easy make the same height
• for "ovals" i use the ellipse shape

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta, calc, fit, matrix, positioning, shapes.geometric}

\begin{document}
\begin{tikzpicture}[
arr/.style = {-Stealth, shorten >=2pt},
EL/.style = {%Edge Label
inner sep=2pt, font=\small, sloped},
oval/.style = {ellipse, draw, inner xsep=#1}
]
\newcommand{\p}{\mathbf{p}}
\newcommand{\x}{\mathbf{x}}
\matrix (m) [matrix of math nodes,
nodes in empty cells,
nodes = {minimum height=3ex, inner sep=1pt, anchor=center},
column sep =6em,
row sep=1ex]
{
\p  &                           &                           \\
& \x(\cdot;\p,I)            &                           \\
\p  &                           &                           \\
&                           & y(\cdot;\p,I)             \\
& \x(\cdot;\tilde{\p},I)    &                           \\
\p  &                           &                           \\
};
%
\node[oval= 4pt, fit=(m-1-1) (m-6-1), label=$\Omega$] {};
\node[oval=-2pt, fit=(m-1-2) (m-2-2) (m-6-2), label=$\mathcal{F}$] {};
\node[oval=-2pt, fit=(m-1-3) (m-4-3) (m-6-3), label=$\mathcal{G}_\Sigma$] {};
%
\draw[arr] (m-1-1) -- node[EL, above] {$X_\Pi(\p,I)$}         (m-2-2.west);
\draw[arr] (m-3-1) -- node[EL, below] {$X_\Pi(\tilde{\p},I)$} (m-2-2.west);
\draw[arr] (m-6-1) -- node[EL, below] {$X_\Pi(\tilde{\p},I)$} (m-5-2.west);
%
\draw[arr] (m-2-2) -- node[EL, above] {$Y_\Sigma(\p,I)$}         (m-4-3.west);
\draw[arr] (m-5-2) -- node[EL, below] {$Y_\Sigma(\tilde{\p},I)$} (m-4-3.west);
\end{tikzpicture}
\end{document}


• – user121799 Aug 3 '18 at 22:07
• @marmot, thank you very much. to be honest, i'm lost in his/her contradictory asks: first show desired image (which we are both provided) than in comment say that this image is not what he/she wont. i will lest my answer as it is. also +1 for your answers. – Zarko Aug 3 '18 at 23:09
• @marmot was correct. If your interested in helping, I've now rewritten the question to make it less confusing. – Abijah Aug 8 '18 at 14:51
• @Abijah, than you already have answer for which you looking for. be so kind and accept it. i will no change nor upgrade my answer. – Zarko Aug 8 '18 at 14:57
• here are the final two lines of the question: "Could someone help me add ovals to this diagram? Particularly so each of the ovals is the same size and shape." Because the other answer doesn't give ovals the same size and shape it was not accepted. – Abijah Aug 8 '18 at 16:28

My housemate gave me a hand, here is his code.

\begin{tikzpicture}[loose/.style={inner sep=.7em}, oval/.style={ellipse,draw}]
\newcommand{\p}{\mathbf{p}}
\newcommand{\x}{\mathbf{x}}
\node(p){$\p$};
\node[below=1 of p](pb){$\bar \p$};
\node[right=4 of $(p)!0.5!(pb)$](x1){$\x(\cdot;\p,I)$};
\node[right =4 of x1](y){$y(\cdot;\p,I)$}; \def\ovalwidth{0.8}%Just used for the left one, adjust to make roughly match the others which are already wide
\def\ovalheight{0.4}%excess height, all will get the same height.
\coordinate(ovaltop) at ($(p.north)+(0,\ovalheight)$);
\coordinate(ovalbot) at ($(pb.south)-(0,\ovalheight)$); \node[oval,inner sep=2pt,fit={(ovaltop)($(pb)+(\ovalwidth,0)$)($(pb)-(\ovalwidth,0)$)(ovalbot)},label=$\Omega$]{};
\node[oval,inner
sep=2pt,fit={(x1)(x1|-ovaltop)(x1|-ovalbot)},label=$\mathscr{F}_\Pi(I)\subset\mathscr{F}_\Pi$]{};
\node[oval,inner
sep=2pt,fit={(y)(y|-ovaltop)(y|-ovalbot)},label=$\mathscr{G}_\Pi(I)\subset\mathscr{G}_\Sigma$]{};
\draw[-Latex] (p) -- node [above,loose]{$X_\Pi(\p,I)$} (x1); \draw[-Latex] (pb) -- node [below,loose]{$X_\Pi(\bar\p,I)$} (x1); \draw[-Latex] (x1) -- node [above,loose]{$Y_\Sigma(\x(\cdot;\p,I))$} (y); \end{tikzpicture}
`
• -1, It is not fair that you mark as the best answer to one of yours based on the answers of those who have helped you to achieve it. – J Leon V. Aug 29 '18 at 16:39
• No one here helped. The diagram produced here is what I wanted and is substantially different to what they produced- if you read the comments beneath their responses you will see that I repeatedly asked for it like this and did not get it. – Abijah Aug 29 '18 at 19:22
• @Abijah, your claim is not through. sorry! – Zarko Aug 30 '18 at 21:23
• please explain what marmot or I could have said to explain it more clearly to you? – Abijah Aug 30 '18 at 21:26