我正在尝试使用 tikz 来标记方程的变量。我知道一个类似的问题(分项方程) 但答案使用 itemize 来标记变量。我想做一些类似于附图所示的事情,当然,我希望它看起来不错 :) 有什么建议吗?
谢谢,
答案1
另一个解决方案是使用matrix
。这样,您可以轻松地按顺序排列方程式,然后,如果您将 的单元格定义为matrix
,node
则可以使用positioning
库来相对于这些 来定位标签node
。
(请注意,shorten >=
此代码中使用了选项来使箭头看起来更好一些,这样它们就不会立即与各个字符的线条擦碰。您可以根据需要进行修改。)
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\matrix[name=M1, matrix of nodes, inner sep=0pt, column sep=0pt]{
\node (Y1) {Y}; & \node (equals) {=}; & \node (Y2) {Y}; & ( & \node (X) {X,}; & \node (Z) {Z,}; & \node (W) {W;}; & \node (A) {A}; & ) \\
};
\node (Output) [left=2.5em of Y1] {Output};
\node (VariableZ) [above=2.5em of Z] {Variable Z};
\node (VariableW) [below=2.5em of W] {Variable W};
\node (VariableX) [left=2em of VariableZ] {Variable X};
\node (ParameterA) [right=2em of VariableZ] {Parameter A};
\draw[->] (Output) -- (Y1);
\draw[->, shorten >=0.1em] (VariableZ) -- (Z);
\draw[->, shorten >=0.2em] (VariableX) -- (X.north);
\draw[->, shorten >=0.1em] (ParameterA) -- (A.north);
\draw[->] (VariableW) -- (W);
\end{tikzpicture}
\end{document}
答案2
以下是基于经过实践检验的tikzmark
想法的一些入门知识 - 你会看到它被用在本网站的许多答案中,最初发表于在正文旁边添加大括号
% arara: pdflatex
% !arara: indent: {overwrite: on}
\documentclass{article}
\usepackage{amsmath} % loaded automatically by beamer
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{>=stealth}
\newcommand{\tikzmark}[3][]{\tikz[overlay,remember picture,baseline] \node [anchor=base,#1](#2) {#3};}
\begin{document}
\begin{equation*}
\mathcal{A} = (\,\tikzmark{identity}{\texttt{I}} -\tikzmark[red]{G}{\texttt{G}}\,\,\,
\tikzmark[blue]{L}{\texttt{L}} - \tikzmark[purple]{C}{\texttt{C }}\,)
\end{equation*}
\begin{tikzpicture}[overlay, remember picture,node distance =1.5cm]
\node (identitydescr) [below left=of identity ]{words};
\draw[,->,thick] (identitydescr) to [in=-90,out=90] (identity);
\node[red] (Gdescr) [below =of G]{other words};
\draw[red,->,thick] (Gdescr) to [in=-90,out=90] (G);
\node[blue,xshift=1cm] (Ldescr) [above right =of L]{some words};
\draw[blue,->,thick] (Ldescr) to [in=45,out=-90] (L.north);
\node[purple] (Cdescr) [below right =of C]{more words};
\draw[purple,->,thick] (Cdescr) to [in=-90,out=90] (C.south);
\end{tikzpicture}
\end{document}