向方程的每个项添加箭头

向方程的每个项添加箭头
\documentclass{beamer}
\usepackage[all]{xy}
\begin{document}
\section{Introduction}
\xymatrix{
&*+{\sum_{i=n}^m {i^2}} &*+{+}&*+{p} \\
& {\bullet} & D \ar[ul] && f \ar[ul]
}
\end{document}

我想减少术语之间的间距和箭头的不同颜色。我在 ubuntu 下使用 kile。是否有必要包含 tiKZ ,如果需要,请解释一下

答案1

我建议使用tikz而不是xy。以下是我考虑如何实现这一点。(以下内容改编自TeXample.net例如,着眼于代码抽象;原文中的图片也更精美。)

前言:

\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows}

% Define how TiKZ will draw the nodes
\tikzset{mathterm/.style={draw=black,fill=white,rectangle,anchor=base}}
\tikzstyle{every picture}+=[remember picture]
\everymath{\displaystyle}

\makeatletter

% Designate a term in a math environment to point to
% Syntax: \mathterm[node label]{some math}
\newcommand\mathterm[2][]{%
   \tikz [baseline] { \node [mathterm] (#1) {$#2$}; }}

% A command to draw an arrow from the current position to a labelled math term
% Default color=black, default arrow head=stealth
% Syntax: \indicate[color]{term to point to}[path options]
\newcommand\indicate[2][black]{%
   \tikz [baseline] \node [inner sep=0pt,anchor=base] (i#2) {\vphantom|};
   \@ifnextchar[{\@indicateopts{#1}{#2}}{\@indicatenoopts{#1}{#2}}}
\def\@indicatenoopts#1#2{%
   {\color{#1} \tikz[overlay] \path[line width=1pt,draw=#1,-stealth] (i#2) edge (#2);}}
\def\@indicateopts#1#2[#3]{%
   {\color{#1} \tikz[overlay] \path[line width=1pt,draw=#1,-stealth] (i#2) [#3] edge (#2);}}

\makeatother

文件正文:

\begin{gather}
   \mathterm[t1]{   \sum_{i=n}^m {i^2}   }   +
   \mathterm[t2]{   \int_0^t \mathrm d\:\!\tau   }   +
   \Gamma\bigl(n + \tfrac{1}{2}\bigr)   + 
   \mathterm[t3]{   \tfrac{1}{2}m\|\mathbf v\|^2   }
\end{gather}


\begin{itemize}
   \item  Power series \indicate[red]{t1}[out=0,in=-75]
   \item  Definite integral \indicate[blue]{t2}[out=0,in=-90]
   \item  Non-relativistic kinetic energy \indicate{t3}[out=0,in=-90]
\end{itemize}

结果: 带有方框和指示项的方程

答案2

覆盖示例

\documentclass{beamer}
\usepackage{amsmath}
\usepackage{pst-node}
\psset{arrowscale=2,arrows=->}
\def\VPh{\vphantom{\displaystyle\sum_{i=n}^m {i^2}}}
\def\psBox#1#2{\psframebox[fillcolor=#1,fillstyle=solid]{\VPh\displaystyle#2}}

\begin{document}

\begin{frame}{Foo}{bar}
\[
   \only<1->{\rnode{t1}{\psBox{green!30}{\sum_{i=n}^m {i^2}}} +} 
   \only<2->{\rnode{t2}{\psBox{blue!30}{\int_0^t \mathrm d\:\!\tau}} + 
             \Gamma\bigl(n +\frac{1}{2}\bigr)+ }
   \only<3->{\rnode{t3}{\psBox{red!30}{\frac{1}{2}m\|\mathbf v\|^2}}}
\]

\begin{itemize}[<+->]
   \item  Power \rnode[rc]{T1}{series} \nccurve[angleB=-75]{T1}{t1}
   \item  Definite \rnode[rc]{T2}{integral}\nccurve[angleB=-90]{T2}{t2} 
   \item  Non-relativistic kinetic \rnode[rc]{T3}{energy}\nccurve[angleB=-90]{T3}{t3}
\end{itemize}
\end{frame}

\end{document}

在此处输入图片描述

答案3

如果您喜欢使用 Xy-pic,只需省略“+”:

\documentclass{beamer}
\usepackage[all]{xy}
\begin{document}
\section{Introduction}
\xymatrix{
& *{\sum_{i=n}^m {i^2}} & + & *{p} \\
& {\bullet} & D \ar@[red][ul] && f \ar@[blue][ul]
}
\end{document}

确实,构造*{object}将对象置于无边距状态,“+”添加边距。事实上,*+{object}相当于{object}和 甚至(如果对象不以宏开头)object

对于颜色,只需使用@[color]修饰符,有关颜色的更多信息,请参阅参考文献第 30 页。

另一种解决方案是直接定义“longarrow”,例如:

\documentclass{beamer}
\usepackage[all]{xy}
\newdir{l}{!/1.5ex/@{-}*:(1,0)@^{>}*:(1,0)@_{>}}
\newdir{m}{!/0.5ex/@{-}*@{-}}
\def\longar@[#1][#2]{\ar@[#1]@{-l}[#2] \ar@[#1]@{m-m}[#2]}
\begin{document}
\section{Introduction}
\xymatrix{
&{\sum_{i=n}^m {i^2}} &+&p \\
& {\bullet} & D \longar@[red][ul] && f \longar@[blue][ul]
}
\end{document}

相关内容