1

I want to make something like the following (I made it in photoshop).

image1

Basically I want to make questions for my students to do but without the numbers in the boxes. I don't mind if there is no circling in the making of ten. I was thinking of using nodes but then the formatting of the equation will be hard to deal with.

Edit: This is my version following gernot's answer

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,fit}
\newcommand\tikznode[3][]%
   {\tikz[baseline=(#2.base)]
      \node[minimum size=0pt,inner sep=0pt,#1](#2){#3};%
   }

    \tikzset
   {boxed/.style={draw,minimum size=0pt,inner sep=2pt},
    shrt/.style={shorten >=3pt, shorten <=3pt},
    x-/.style={xshift=-2pt},
    x+/.style={xshift=2pt}
   }
\begin{document}
\begin{tikzpicture}[remember picture]
\node{$\tikznode{n9}{9}+\tikznode{n7}{7}=\tikznode[boxed]{n16}{16}$};
\node[boxed,above left=2mm and 2mm of n7] (n1) {1};
\node[boxed,above right=2mm and 2mm of n7] (n6) {6};
\node[boxed,above=10mm of n7] (n10) {10};
\draw[shrt] (n1) -- (n7);
\draw[shrt] (n6) -- (n7);
\draw[shrt] (n10) -- (n6);
\node[ellipse,draw,fit=(n1) (n9),inner sep=1pt] (n1n9) {};
\draw[shrt] ([x-]n10.south) -- ([x-]n1n9.north);
\draw[shrt] ([x+]n10.south) -- ([x+]n1n9.north);
\end{tikzpicture}
\end{document}

While this code is for the enlarged one:

\begin{tikzpicture}[remember picture, scale=2, every node/.style={transform shape}]
\node{$\tikznode{n9}{9}+\tikznode{n7}{7}=\tikznode[boxed]{n16}{\phantom{10}}$};
\node[boxed,above left=3mm and 3mm of n7] (n1) {\phantom{10}};
\node[boxed,above right=3mm and 3mm of n7] (n6) {\phantom{10}};
\node[boxed,above=10mm of n7] (n10) {\phantom{10}};
\draw[shrt] (n1) -- (n7);
\draw[shrt] (n6) -- (n7);
\draw[shrt] (n10) -- (n6);
\node[ellipse,scale=0.5, draw,fit=(n1) (n9),inner sep=1pt] (n1n9) {};
\draw[shrt] ([x-]n10.south) -- ([x-]n1n9.north);
\draw[shrt] ([x+]n10.south) -- ([x+]n1n9.north);
\end{tikzpicture}

Clearly the enlarged one breaks some of the properties of the positions. (See image below)

image2

1 Answers1

7

Here is a tikz solution, with a small deficiency: The circles are just horizontal and vertical elliptic nodes, since I use the fit library. For tilted ellipses one has to invest extra effort.

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,fit}
\newcommand\tikznode[3][]%
   {\tikz[baseline=(#2.base)]
      \node[minimum size=0pt,inner sep=0pt,#1](#2){#3};%
   }
\tikzset
   {boxed/.style={draw,minimum size=0pt,inner sep=1pt},
    shrt/.style={shorten >=1pt, shorten <=1pt},
    x-/.style={xshift=-0.5pt},
    x+/.style={xshift=0.5pt}
   }
\begin{document}
\begin{tikzpicture}[remember picture]
\node{$\tikznode{n9}{9}+\tikznode{n7}{7}=\tikznode[boxed]{n16}{16}$};
\node[boxed,above left=5mm and 5mm of n7] (n1) {1};
\node[boxed,above right=5mm and 5mm of n7] (n6) {6};
\node[boxed,above=5mm of n1] (n10) {10};
\draw[shrt] (n1) -- (n7);
\draw[shrt] (n6) -- (n7);
\draw[shrt] (n10) -- (n6);
\node[ellipse,draw,fit=(n1) (n9),inner sep=1pt] (n1n9) {};
\draw[shrt] ([x-]n10.south) -- ([x-]n1n9.north);
\draw[shrt] ([x+]n10.south) -- ([x+]n1n9.north);
\end{tikzpicture}
\end{document}

Edit: Scaling is tricky for several reasons.

  • Positioning nodes with explicit dimensions like in above right=5mm and 5mm of n7 does not scale.

  • Transforming the node does not scale the node positions, but transforms the canvas. As you can see, the lines of the box in the equation becomes thicker than the other boxes.

Here are some possibilities that work.

  • Position nodes using at ($(n7)+(-0.7,0.7)$), without explicit dimensions, and use the tikz option scale. This will scale only distances, but not characters or line widths.

  • Scale the whole picture with \scalebox. This scales everything, including characters and line widths.

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,fit,calc}
\newcommand\tikznode[3][]%
   {\tikz[baseline=(#2.base)]
      \node[minimum size=0pt,inner sep=0pt,#1](#2){#3};%
   }
\tikzset
   {boxed/.style={draw,minimum size=0pt,inner sep=1pt},
    shrt/.style={shorten >=1pt, shorten <=1pt},
    x-/.style={xshift=-0.5pt},
    x+/.style={xshift=0.5pt}
   }
\begin{document}
\scalebox{2}{%
\begin{tikzpicture}[remember picture]
\node{$\tikznode{n9}{9}+\tikznode{n7}{7}=\tikznode[boxed]{n16}{16}$};
\node[boxed,above left=5mm and 5mm of n7] (n1) {1};
\node[boxed,above right=5mm and 5mm of n7] (n6) {6};
\node[boxed,above=5mm of n1] (n10) {10};
\draw[shrt] (n1) -- (n7);
\draw[shrt] (n6) -- (n7);
\draw[shrt] (n10) -- (n6);
\node[ellipse,draw,fit=(n1) (n9),inner sep=1pt] (n1n9) {};
\draw[shrt] ([x-]n10.south) -- ([x-]n1n9.north);
\draw[shrt] ([x+]n10.south) -- ([x+]n1n9.north);
\end{tikzpicture}%
}
\qquad
\begin{tikzpicture}[remember picture,scale=2]
\node{$\tikznode{n9}{9}+\tikznode{n7}{7}=\tikznode[boxed]{n16}{16}$};
\node[boxed] (n1) at ($(n7)+(-0.7,0.7)$) {1};
\node[boxed] (n6) at ($(n7)+( 0.7,0.7)$) {6};
\node[boxed] (n10) at ($(n1)+(0,0.8)$) {10};
\draw[shrt] (n1) -- (n7);
\draw[shrt] (n6) -- (n7);
\draw[shrt] (n10) -- (n6);
\node[ellipse,draw,fit=(n1) (n9),inner sep=1pt] (n1n9) {};
\draw[shrt] ([x-]n10.south) -- ([x-]n1n9.north);
\draw[shrt] ([x+]n10.south) -- ([x+]n1n9.north);
\end{tikzpicture}
\end{document}
gernot
  • 49,614