[Tex/LaTex] How to fit a tight ellipse around nodes

tikz-pgf

I have a set of two nodes and I would like to draw tight ellipses around them in my tikz picture. Note that this is part of a beamer presentation.

I have attached an image that illustrates the wanted effect.

enter image description here

Here is what I have so far:

\documentclass[10pt,aspectratio=1610]{beamer}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,backgrounds,fit,positioning}

\begin{document}

\tikzset{res/.style={ellipse,draw,minimum height=0.5cm,minimum width=0.8cm}}
\tikzset{literal/.style={rectangle,draw,minimum height=0.5cm,minimum width=0.8cm,text width = 1.2 cm, align = center}}

\begin{frame}[fragile]{Example}{}
\begin{tikzpicture}[node distance = 2 cm,auto, ]
\node[res,] (obs1) {\footnotesize :obs1} ;
\node[res, left = 1cm of obs1] (shop1) {\footnotesize :shop1} ;
\node[literal, left = 1cm of shop1] (shopName1) {\footnotesize ``Barnes \& Noble''} ;
\node[res, above of = shop1] (book1) {\footnotesize :book1} ;
\node[literal, left = 1cm of book1] (bookName1) {\footnotesize ``Dune''} ;
\node[res, below of = obs1] (obs2) {\footnotesize :obs2} ;
\node[res, left = 1cm of obs2] (shop2) {\footnotesize :shop2} ;
\node[literal, left = 1cm of shop2] (shopName2) {\footnotesize ``Amazon''} ;
\node[res, below of = shop2] (book2) {\footnotesize :book2} ;
\node[literal, left = 1cm of book2] (bookName2) {\footnotesize ``Dracula''} ;
\node[literal, below of = obs2] (measure2) {\footnotesize 12} ;
\node[literal, above of = obs1] (measure1) {\footnotesize 7} ;
\node[literal, right = 1cm of obs1] (monthName) {\footnotesize ``January''} ;
\node[literal, right = 1cm of measure1] (yearNum) {\footnotesize ``2016''} ;
\node[res, right = 1cm of monthName] (month) {\footnotesize :january2016} ;
\node[res, above of = month] (year) {\footnotesize :2016} ;
\node[res, below of = month] (day) {\footnotesize :date31012016} ;

\path[->,draw]
    (obs1) edge node[midway,above=-6pt,fill=white,inner sep=0pt] {\footnotesize :shop} (shop1)
    (obs2) edge node[midway,above=-6pt,fill=white,inner sep=0pt] {\footnotesize :shop} (shop2)

    (obs1) edge node[midway,above=-6pt,fill=white] {\footnotesize :book} (book1)
    (obs2) edge node[midway,above=-6pt,fill=white] {\footnotesize :book} (book2)

    (book1) edge node[midway,above=-6pt,fill=white,inner sep=0pt] {\footnotesize :name} (bookName1)
    (book2) edge node[midway,above=-6pt,fill=white,inner sep=0pt] {\footnotesize :name} (bookName2)

    (shop1) edge node[midway,above=-6pt,fill=white] (title1) {\footnotesize :title} (shopName1)
    (shop2) edge node[midway,above=-6pt,fill=white] (title2) {\footnotesize :title} (shopName2)

    (obs1) edge node[midway,above=-6pt,fill=white] {\footnotesize :price} (measure1)
    (obs2) edge node[midway,above=-6pt,fill=white] {\footnotesize :price} (measure2)

    (obs1) edge node[midway,above=-6pt,fill=white]  {\footnotesize :date} (day)
    (obs2) edge node[midway,above=-6pt,fill=white] {\footnotesize :date} (day)

    (day) edge node[midway,above=-6pt,fill=white] {\footnotesize skos:broader} (month)
    (month) edge node[midway,above=-6pt,fill=white] {\footnotesize skos:broader} (year)

    (month) edge node[midway,above=-6pt,fill=white,inner sep=0pt] {\footnotesize :month} (monthName)
    (year) edge node[midway,above=-6pt,fill=white] {\footnotesize :year} (yearNum)
    ;

\begin{pgfonlayer}{background}
  \node[fit=(shopName1)(shop1), fill=violet!30,ellipse] {};
  \node[fit=(shopName2)(shop2), fill=violet!30,ellipse] {};
  \node[fit=(bookName2)(book2), fill=violet!30,ellipse] {};
  \node[fit=(bookName1)(book1), fill=violet!30,ellipse] {};
  \node[fit=(measure1)(obs1), fill=blue!30,ellipse] {};
  \node[fit=(measure2)(obs2), fill=blue!30,ellipse] {};
  \node[fit=(year)(yearNum), fill=green!30,ellipse] {};
  \node[fit=(month)(monthName), fill=green!30,ellipse] {};
\end{pgfonlayer}
\end{tikzpicture}
\end{frame}
\end{document}

Here is the result that it produce

enter image description here

Note how the ellipses do not fit the nodes but cover much more.
How can I create a tight ellipse around a pair of nodes?

Best Answer

If Jake's answer doesn't like or doesn't work for you, may be you could consider other shapes like rounded rectangle or just a rectangle with rounded corners.

enter image description here

Following code uses rounded rectangles for horizontal associations. As I could not manage to build a vertical rounded rectangle and cylinders doesn't fit very well, two rectangles with rounded corners are used for vertical associations.

\documentclass[10pt,aspectratio=1610]{beamer}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,backgrounds,fit,positioning}

\begin{document}

\tikzset{res/.style={ellipse,draw,minimum height=0.5cm,minimum width=0.8cm}}
\tikzset{literal/.style={rectangle,draw,minimum height=0.5cm,minimum width=0.8cm,text width = 1.2 cm, align = center}}
\tikzset{hfit/.style={rounded rectangle, inner xsep=0pt, fill=#1!30},
           vfit/.style={rounded corners, fill=#1!30}}

\begin{frame}[fragile]{Example}{}
\begin{tikzpicture}[node distance = 2 cm,auto, ]
\node[res,] (obs1) {\footnotesize :obs1} ;
\node[res, left = 1cm of obs1] (shop1) {\footnotesize :shop1} ;
\node[literal, left = 1cm of shop1] (shopName1) {\footnotesize ``Barnes \& Noble''} ;
\node[res, above of = shop1] (book1) {\footnotesize :book1} ;
\node[literal, left = 1cm of book1] (bookName1) {\footnotesize ``Dune''} ;
\node[res, below of = obs1] (obs2) {\footnotesize :obs2} ;
\node[res, left = 1cm of obs2] (shop2) {\footnotesize :shop2} ;
\node[literal, left = 1cm of shop2] (shopName2) {\footnotesize ``Amazon''} ;
\node[res, below of = shop2] (book2) {\footnotesize :book2} ;
\node[literal, left = 1cm of book2] (bookName2) {\footnotesize ``Dracula''} ;
\node[literal, below of = obs2] (measure2) {\footnotesize 12} ;
\node[literal, above of = obs1] (measure1) {\footnotesize 7} ;
\node[literal, right = 1cm of obs1] (monthName) {\footnotesize ``January''} ;
\node[literal, right = 1cm of measure1] (yearNum) {\footnotesize ``2016''} ;
\node[res, right = 1cm of monthName] (month) {\footnotesize :january2016} ;
\node[res, above of = month] (year) {\footnotesize :2016} ;
\node[res, below of = month] (day) {\footnotesize :date31012016} ;


\path[->,draw]
    (obs1) edge node[midway,above=-6pt,fill=white,inner sep=0pt] {\footnotesize :shop} (shop1)
    (obs2) edge node[midway,above=-6pt,fill=white,inner sep=0pt] {\footnotesize :shop} (shop2)

    (obs1) edge node[midway,above=-6pt,fill=white] {\footnotesize :book} (book1)
    (obs2) edge node[midway,above=-6pt,fill=white] {\footnotesize :book} (book2)

    (book1) edge node[midway,above=-6pt,fill=white,inner sep=0pt] {\footnotesize :name} (bookName1)
    (book2) edge node[midway,above=-6pt,fill=white,inner sep=0pt] {\footnotesize :name} (bookName2)

    (shop1) edge node[midway,above=-6pt,fill=white] (title1) {\footnotesize :title} (shopName1)
    (shop2) edge node[midway,above=-6pt,fill=white] (title2) {\footnotesize :title} (shopName2)

    (obs1) edge node[midway,above=-6pt,fill=white] {\footnotesize :price} (measure1)
    (obs2) edge node[midway,above=-6pt,fill=white] {\footnotesize :price} (measure2)

    (obs1) edge node[midway,above=-6pt,fill=white]  {\footnotesize :date} (day)
    (obs2) edge node[midway,above=-6pt,fill=white] {\footnotesize :date} (day)

    (day) edge node[midway,above=-6pt,fill=white] {\footnotesize skos:broader} (month)
    (month) edge node[midway,above=-6pt,fill=white] {\footnotesize skos:broader} (year)

    (month) edge node[midway,above=-6pt,fill=white,inner sep=0pt] {\footnotesize :month} (monthName)
    (year) edge node[midway,above=-6pt,fill=white] {\footnotesize :year} (yearNum)
    ;

\begin{pgfonlayer}{background}
  \node[fit=(shopName1)(shop1), hfit=violet] {};
  \node[fit=(shopName2)(shop2), hfit=violet] {};
  \node[fit=(bookName2)(book2), hfit=violet] {};
  \node[fit=(bookName1)(book1), hfit=violet] {};
  \node[fit=(measure1)(obs1), vfit=blue] {};
  \node[fit=(measure2)(obs2), vfit=blue] {};
  \node[fit=(year)(yearNum), hfit=green] {};
  \node[fit=(month)(monthName), hfit=green] {};
\end{pgfonlayer}
\end{tikzpicture}
\end{frame}
\end{document}