![TikZ 在数学环境中的问题](https://linux22.com/image/445635/TikZ%20%E5%9C%A8%E6%95%B0%E5%AD%A6%E7%8E%AF%E5%A2%83%E4%B8%AD%E7%9A%84%E9%97%AE%E9%A2%98.png)
我尝试添加一些 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