我是 LaTeX 的新手,我尝试使用tikz
库在方程中绘制交集与并集,如下图所示,但遗憾的是我找不到任何解决方案。
我的代码的当前状态:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (-1,3) node[anchor=north west] {$IoU = \frac{\text{area of overlap}}{\text{area of union}}=$}
$\frac{
\draw[blue, very thick] (0,0) rectangle (2,2);
\draw[blue, very thick] (0.5,-0.5) rectangle (2.5,1.5);
}{
\filldraw[color=blue!60, fill=blue!5, very thick] (0,0) rectangle (2,2);
\filldraw[color=blue!60, fill=blue!5, very thick] (0.5,-0.5) rectangle (2.5,1.5);
}$
\end{tikzpicture}
\end{document}
任何帮助都将非常感激!
答案1
使用两个单独的 tikz 图片作为分子和分母。请注意,在下面的代码中,我使用了简写tikz{...}
而不是 ,\begin{tikzpicture} ... \end{tikzpicture}
以使代码更易于阅读(在我看来)。
对于分母,对两个矩形使用单个\fill
命令。对于分子,我们希望奇偶填充,因此首先用浅蓝色填充整个图形,然后用even odd rule
白色填充外部部分。
\documentclass{article}
\usepackage{tikz,amsmath}
\begin{document}
$IoU = \frac{\text{area of overlap}}{\text{area of union}}=
\frac{
\tikz{\fill[draw=blue, very thick, fill=blue!5] (0,0) rectangle (2,2) (0.5,-0.5) rectangle (2.5,1.5);
\fill[draw=blue, very thick, fill=white, even odd rule] (0,0) rectangle (2,2) (0.5,-0.5) rectangle (2.5,1.5);}}
{\tikz{\fill[draw=blue, fill=blue!5, very thick] (0,0) rectangle (2,2) (0.5,-0.5) rectangle (2.5,1.5);}}$
\end{document}