代码

代码

我想在 LaTeX 中实现类似以下内容的功能,也许在 tikz 中。如能得到任何帮助,我将不胜感激。

截屏

答案1

这是一个 tikz 解决方案:

\documentclass[border=10pt]{standalone}
\usepackage{tikz,amsmath}

\newcommand\tikzmark[2][]{
  \tikz[remember picture,inner sep=0,outer sep=0,baseline=(#1.base)]{\node(#1){$#2$};}
}

\newlength{\bubblesize}
\setlength{\bubblesize}{6pt}

\begin{document}

$ \dfrac{\tikzmark[topleft]{3}}{\tikzmark[bottomleft]{4}}   =
    \dfrac{\tikzmark[topright]{x}}{\tikzmark[bottomright]{10}} $

\begin{tikzpicture} [remember picture,overlay]
    \foreach \fracpart in {topleft,topright,bottomleft,bottomright}{
        \begin{scope}[shift=(\fracpart)]
            \coordinate (a\fracpart) at (60:\bubblesize);
            \coordinate (b\fracpart) at (240:\bubblesize);
            \coordinate (c\fracpart) at (120:\bubblesize);
            \coordinate (d\fracpart) at (300:\bubblesize);
        \end{scope}
    }   
    \draw [black!20] (abottomright) arc (60:-120:\bubblesize) -- (btopleft) arc (240:60:\bubblesize) -- cycle;
    \draw [black!20] (cbottomleft) arc (120:300:\bubblesize) -- (dtopright) arc (-60:120:\bubblesize) -- cycle;
\end{tikzpicture}

\end{document}

交叉相乘

答案2

此方法使用高亮而不是绘制边框(因为我不知道如何获得透明颜色double:/)

代码

\documentclass{article}
\usepackage{tikz,amsmath}

\newcommand\tikzmark[2][]{
  \tikz[remember picture,inner sep=0,outer sep=0,baseline=(#1.base)]{\node(#1){$#2$};}
}
\tikzset{
  crossmult/.style={double distance=9pt,line cap=round,opacity=.1,shorten >=3pt,shorten <=3pt,#1}
}

\begin{document}

\[
  \frac{\tikzmark[a]{3}}{\tikzmark[b]{4}}
  =
  \frac{\tikzmark[c]{x}}{\tikzmark[d]{10}}
\]

\tikz[remember picture,overlay]{
  \draw[crossmult=red](a.north west)--(d.south east);
  \draw[crossmult=green](b.south west)--(c.north east);
}

\end{document}

输出

在此处输入图片描述

答案3

更新它使用更少的控制点效果更好 在此处输入图片描述

\documentclass{article}

\usepackage{tikz}

\usetikzlibrary{hobby}


\begin{document}


\Large

\[
    \frac{\tikz[remember picture,inner sep=1pt, outer sep=0pt]{\node (A){$3$};}}
         {\tikz[remember picture,inner sep=1pt, outer sep=0pt]{\node (B){$4$};}}
          = 
    \frac{\tikz[remember picture,inner sep=1pt, outer sep=0pt]{\node (C){$x$};}}
         {\tikz[remember picture,inner sep=1pt, outer sep=0pt]{\node (D){$10$};}}
 \]


\begin{tikzpicture}[remember picture, overlay]
\draw[draw=red](A.north west) 
to[closed,curve through={ (A.south west) .. (D.south west) .. 
(D.south east)  .. (D.north east) .. (A.north east) 
}](A.north west);
\draw[draw=green](C.north east) 
to[closed,curve through={(C.south east) .. (B.south east) .. (B.south west) .. 
(B.north west) .. (C.north west)
}](C.north east);
\end{tikzpicture}
\end{document}

我担心我没有完全正确地得到控制点(这是从这个网站上的随机答案中窃取你不理解的代码的结果:-),但是像

在此处输入图片描述

更新后代码点的使用更加对称。

\documentclass{article}
\usepackage{amsmath,cancel}
\usepackage{tikz}
%\usetikzlibrary{fit,shapes.geometric}
%\usetikzlibrary{tikzmark}
\usetikzlibrary{shapes.geometric} % required for the ellipse shape
\usetikzlibrary{arrows, backgrounds, calc, hobby, positioning}


\makeatletter


\begin{document}






\Large

\[
    \frac{\tikz[remember picture,inner sep=0pt, outer sep=0pt]{\node (A){$3$};}}
        {\tikz[remember picture,inner sep=0pt, outer sep=0pt]{\node (B){$4$};}}
          = 
    \frac{\tikz[remember picture,inner sep=0pt, outer sep=0pt]{\node (C){$x$};}}
        {\tikz[remember picture,inner sep=0pt, outer sep=0pt]{\node (D){$10$};}}
 \]

\vspace*{-1.32cm}\hspace*{4.75cm}%I guess I shouldn't need this
\begin{tikzpicture}[]
\draw[draw=red](A.north) 
to[closed,curve through={(A.north west) .. (A.west) .. (A.south west)
.. (D.south west) .. 
(D.south)..(D.south east) ..(D.east) .. (D.north east) .. (A.north east) 
}](A.north);
\draw[draw=green](C.north) 
to[closed,curve through={(C.north east).. (C.east) .. (C.south east) 
.. (B.south east) .. (B.south) .. (B.south west) .. 
(B.west)..(B.north west)  .. (C.north west) 
}](C.north);

\end{tikzpicture}
\end{document}

答案4

以下需要运行两次。我知道这不是你真正想要的,但它可以有所帮助。我想......

在此处输入图片描述

\documentclass[dvipsnames]{article}
\usepackage{amsmath}
\usepackage{tikz}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node[inner xsep=0pt,outer sep=0pt] (#1) {};}
%-------------- Cross Multiply Commands ---------------------------------------------
\newcommand{\crossmultiplynd}[2]{%
    \tikz[remember picture, overlay]{
        \draw[OrangeRed,thick,<-,shorten <=0pt] 
            (#1.east) -- (#2.north west);}}
\newcommand{\crossmultiplydn}[2]{%
    \tikz[remember picture, overlay]{
        \draw[Cerulean,thick,->,shorten >=0pt] 
            (#1.north east) -- (#2.west);}}
%------------------------------------------------------------------------------------               
\begin{document}
\[
\dfrac{a \tikzmark{a}}{b\tikzmark{b}}=\dfrac{\tikzmark{c}c}{\tikzmark{d}d}  
\crossmultiplynd{a}{d}
\crossmultiplydn{b}{c}
\]
\end{document}

相关内容