我想要制作类似下面的东西(我是在 photoshop 中制作的)。
基本上,我想为我的学生出一些问题,但不要在方框里写数字。我不介意在十的组成中没有圆圈。我曾考虑使用节点,但这样等式的格式就很难处理了。
编辑:这是我根据 gernot 的回答得出的版本
\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}
虽然此代码适用于放大的代码:
\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}
显然,扩大后的图破坏了部分位置的属性。(见下图)
答案1
这是一个 tikz 解决方案,但有一点小缺陷:由于我使用了库,所以圆圈只是水平和垂直的椭圆节点fit
。对于倾斜的椭圆,必须付出额外的努力。
\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}
编辑:由于多种原因,扩展很棘手。
像在中一样,具有明确尺寸的定位节点
above right=5mm and 5mm of n7
不会缩放。变换节点不会缩放节点位置,但会变换画布。如您所见,等式中的框的线条变得比其他框更粗。
以下是一些可行的可能性。
使用 定位节点
at ($(n7)+(-0.7,0.7)$)
,不指定具体尺寸,并使用 tikz 选项scale
。这将仅缩放距离,而不会缩放字符或线宽。使用 缩放整个图片
\scalebox
。这会缩放所有内容,包括字符和线宽。
\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}