TikZ 在数学环境中的问题

TikZ 在数学环境中的问题

我尝试添加一些 TikZ 图片作为数学符号来表示一些结方程。因此,我创建了几个命令来快速创建这些图像。

\newcommand{\KA}[1]{
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
\draw [line width=1.5]    (100.4,110.6) .. controls (119.4,71.1) and (119.4,71.1) .. (99.9,30.6) ;
\draw [line width=1.5]    (150.9,110.1) .. controls (131.9,70.1) and (130.9,70.1) .. (150.4,30.1) ;
\end{tikzpicture}
}

\newcommand{\KB}[1]{
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
\draw [line width=1.5]    (207.02,45.05) .. controls (246.62,63.85) and (246.62,63.85) .. (287.02,44.15) ;
\draw [line width=1.5]    (207.78,95.55) .. controls (247.68,76.35) and (247.68,75.35) .. (287.78,94.65) ;

\end{tikzpicture}
}

然后,我尝试在文档中使用它。在常规环境中,这没问题。然而,在数学模式中,我需要它,它抛出一个错误。对于一些简单的事情,例如:

$$
\KA + \KB
$$

,我收到错误:在此处输入图片描述

然后,我尝试在每个命令周围使用 \mathord{}。但仍然出现错误。

以下是 MWE:

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

\newcommand{\KA}[1]{
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
\draw [line width=1.5]    (100.4,110.6) .. controls (119.4,71.1) and (119.4,71.1) .. (99.9,30.6) ;
\draw [line width=1.5]    (150.9,110.1) .. controls (131.9,70.1) and (130.9,70.1) .. (150.4,30.1) ;
\end{tikzpicture}
}

\newcommand{\KB}[1]{
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
\draw [line width=1.5]    (207.02,45.05) .. controls (246.62,63.85) and (246.62,63.85) .. (287.02,44.15) ;
\draw [line width=1.5]    (207.78,95.55) .. controls (247.68,76.35) and (247.68,75.35) .. (287.78,94.65) ;
\end{tikzpicture}
}

\begin{document}
    $$\KA+\KB$$
\end{document}

答案1

我认为这是在方程中添加 tikz 图(也许是复制)。这可以通过修改newcommand以适合方程来实现。

参考:TikZ 图形在方程内?

tikzpicture您可以只使用命令,而不必使用环境\tikz

\documentclass{article}
\usepackage{tikz}
\usepackage{adjustbox}

\newcommand{\KA}{\raisebox{-0.3mm}{
\tikz[x=0.075pt,y=0.075pt,yscale=-1,xscale=1]{
\draw [line width=0.3]    (100.4,110.6) .. controls (119.4,71.1) and (119.4,71.1) .. (99.9,30.6) ;
\draw [line width=0.3]    (150.9,110.1) .. controls (131.9,70.1) and (130.9,70.1) .. (150.4,30.1);}}
}

\newcommand{\KB}{
\tikz[x=0.075pt,y=0.075pt,yscale=-1,xscale=1]{
\draw [line width=0.3]    (207.02,45.05) .. controls (246.62,63.85) and (246.62,63.85) .. (287.02,44.15) ;
\draw [line width=0.3]    (207.78,95.55) .. controls (247.68,76.35) and (247.68,75.35) .. (287.78,94.65) ;}
}

\begin{document}
    % make it larger to see (x10)
    \scalebox{10}{
        $$\KA+\KB$$
    }
\end{document}

到目前为止,没有产生任何错误,但应该调整图的大小。我做了一些更改,现在它看起来像: 结果

编辑

作为桑迪G指出,使用没有问题。在数学方程中tikzpicture使用简单命令只是我的习惯。\tikz

相关内容