答案1
- 输出到
tikz
:
生成的代码简直糟透了。但它确实可以编译成所显示的内容(可能存在一些极端情况)。
\documentclass[10pt]{article}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\definecolor{zzttqq}{rgb}{0.6,0.2,0}
\definecolor{qqqqff}{rgb}{0,0,1}
\definecolor{cqcqcq}{rgb}{0.75,0.75,0.75}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\draw [color=cqcqcq,dash pattern=on 1pt off 1pt, xstep=1.0cm,ystep=1.0cm] (0,-10) grid (10,0);
\draw[->,color=black] (0,0) -- (10,0);
\foreach \x in {,1,2,3,4,5,6,7,8,9}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\draw[->,color=black] (0,-10) -- (0,0);
\foreach \y in {-10,-9,-8,-7,-6,-5,-4,-3,-2,-1}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
\draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};
\clip(0,-10) rectangle (10,0);
\fill[line width=1.2pt,color=zzttqq,fill=zzttqq,fill opacity=0.1] (9.2,-2.18) -- (2.56,-2.12) -- (5.08,-5.16) -- cycle;
\draw [line width=1.2pt,color=zzttqq] (9.2,-2.18)-- (2.56,-2.12);
\draw [line width=1.2pt,color=zzttqq] (2.56,-2.12)-- (5.08,-5.16);
\draw [line width=1.2pt,color=zzttqq] (5.08,-5.16)-- (9.2,-2.18);
\begin{scriptsize}
\fill [color=qqqqff] (9.2,-2.18) circle (1.5pt);
\draw[color=qqqqff] (9.36,-1.92) node {$A$};
\fill [color=qqqqff] (2.56,-2.12) circle (1.5pt);
\draw[color=qqqqff] (2.72,-1.86) node {$B$};
\fill [color=qqqqff] (5.08,-5.16) circle (1.5pt);
\draw[color=qqqqff] (5.24,-4.9) node {$C$};
\draw[color=zzttqq] (7.4,-3.78) node {$b$};
\end{scriptsize}
\end{tikzpicture}
\end{document}
- 添加一个节点和所需的方程。
\documentclass[10pt]{article}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\definecolor{zzttqq}{rgb}{0.6,0.2,0}
\definecolor{qqqqff}{rgb}{0,0,1}
\definecolor{cqcqcq}{rgb}{0.75,0.75,0.75}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\draw [color=cqcqcq,dash pattern=on 1pt off 1pt, xstep=1.0cm,ystep=1.0cm] (0,-10) grid (10,0);
\draw[->,color=black] (0,0) -- (10,0);
\foreach \x in {,1,2,3,4,5,6,7,8,9}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\draw[->,color=black] (0,-10) -- (0,0);
\foreach \y in {-10,-9,-8,-7,-6,-5,-4,-3,-2,-1}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
\draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};
\clip(0,-10) rectangle (10,0);
\fill[line width=1.2pt,color=zzttqq,fill=zzttqq,fill opacity=0.1] (9.2,-2.18) -- (2.56,-2.12) -- (5.08,-5.16) -- cycle;
\draw [line width=1.2pt,color=zzttqq] (9.2,-2.18)-- (2.56,-2.12);
\draw [line width=1.2pt,color=zzttqq] (2.56,-2.12)-- (5.08,-5.16);
\draw [line width=1.2pt,color=zzttqq] (5.08,-5.16)-- (9.2,-2.18);
\begin{scriptsize}
\fill [color=qqqqff] (9.2,-2.18) circle (1.5pt);
\draw[color=qqqqff] (9.36,-1.92) node {$A$};
\fill [color=qqqqff] (2.56,-2.12) circle (1.5pt);
\draw[color=qqqqff] (2.72,-1.86) node {$B$};
\fill [color=qqqqff] (5.08,-5.16) circle (1.5pt);
\draw[color=qqqqff] (5.24,-4.9) node {$C$};
\draw[color=zzttqq] (7.4,-3.78) node {$b$};
\end{scriptsize}
% adding some reference to some equation
\node at (8,-5){Applying equation \ref{eq-2}};
\end{tikzpicture}
According to the right Pythagorean theorem:
\begin{equation}\label{eq-1}
a^2 + b^2 = c^2
\end{equation}
According to the wrong Pythagorean theorem:
\begin{equation}\label{eq-2}
a + b = c
\end{equation}
\end{document}
结果:
编辑:
要求:写出方程式但不要显示它,但要保留引用。
答案:使用textpos
包并将你的方程式包装在textblock
环境中:
%\usepackage{textpos} <--- in the preambule
According to the wrong Pythagorean theorem:
\begin{textblock}{width}(X_offset, Y_offset)
\begin{equation}\label{eq-2}
a + b = c
\end{equation}
\end{textblock}
您可以使用(X_offset, Y_offset)
将方程式从纸上提炼出来,例如(10,10)
。
结果:
在 pdf 中找不到该方程式,但它写在 LaTeX 源中。
答案2
我对另一个答案有点困惑,但继续
在图像中嵌入方程式引用/标签,以便我可以引用图像外的方程式
是的,这是可能的,但不是那么简单。
编号的 displaymath 环境需要线宽,这在 TikZ 中可以通过设置轻松实现,text width
但您需要自行选择合理的文本宽度。这也会将方程编号放置在节点内。
aligned
我在下面的例子中添加了一个节点,其中\tagoutside
生成另一列,其中方程式编号设置为左对齐(如您的图片所示,但与amsmath
通常情况不同)。
和其中的测量值\rlap
确保方程编号实际上位于节点之外,但这有副作用,即方程编号也在 TikZ 图片的边界框之外。
可能存在更复杂的解决方案tikzmark
,但对于简单的方程(和简单的矩形节点)来说,这可能就足够了。
代码
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{shadows}
\makeatletter
\newcommand*\tagoutside[1]{
&\kern-\alignsep@
\rlap{% no math content → no mathrlap necessary
\pgfmathsetlength\pgfutil@tempdima
{\pgfkeysvalueof{/pgf/inner xsep}+(\pgfkeysvalueof{/pgf/outer xsep})}%
\kern\pgfutil@tempdima
\refstepcounter{equation}\label{#1}%
\quad\tagform@\theequation
}%
}
\makeatother
\begin{document}
Some formulas:
\begin{align}
c^2 &= a^2 + b^2 \label{tri} \\
E &= mc^2 \label{albert}
\end{align}
Now a tikzpicture (inside a float):
\begin{figure}
\centering
\begin{tikzpicture}
\node[text width=3cm, draw, drop shadow, fill=white] {
\vspace{-\topskip}
\begin{align}
c^2 &= a^2 + b^2 \label{tikz-tri} \\
E &= mc^2 \label{tikz-albert}
\end{align}
};
\node[draw, drop shadow, fill=white] at (4,0) {$
\begin{aligned}
c^2 &= a^2 + b^2 \tagoutside{tikzed-tri} \\
E &= mc^2 \tagoutside{tikzed-albert}
\end{aligned}$};
\end{tikzpicture}
\end{figure}
Now another set of formulas:
\begin{align}
c^2 &= a^2 + b^2 \label{tri*} \\
E &= mc^2 \label{albert*}
\end{align}
Equations
\eqref{tri} \eqref{albert}
\eqref{tikz-tri} \eqref{tikz-albert}
\eqref{tikzed-tri} \eqref{tikzed-albert}
\eqref{tri*} \eqref{albert*}
\end{document}