8
\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}

i want to reduce the spacing between terms and different colors for arrows.i'm using kile under ubuntu.is it necessary to include tiKZ ,if so explain me

David Carlisle
  • 757,742
user4852
  • 653

3 Answers3

14

I would recommend using tikz rather than xy. Here's how I would think of implementing this. (The following was adapted from this TeXample.net example, with an eye towards code abstraction; the picture in the original is also fancier.)

Preamble:

\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

Document body:

\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}

Result: equation with boxed and indicated terms

doncherry
  • 54,637
  • environment gather undefined – user4852 Apr 13 '11 at 16:23
  • Ah, sorry, you must also \usepackage{amsmath}. I'll add that to the pre-amble above. Note that gather is just one of my preferred choices of math environments; any other displayed math environment would do here, although the AMS ones are better as a rule. – Niel de Beaudrap Apr 13 '11 at 16:25
  • oh..again problem.arrows are not visible.i'm using kile under ubuntu – user4852 Apr 13 '11 at 16:37
  • This looks awesome ^^ I'll use sth like this in my presentation :D – dingo_d Apr 13 '11 at 17:04
  • 1
    @Niel: if instead of using the <pre> tag, you use the code environment provided by markdown (indent all your code by 4 extra spaces, or select them and hit the "code symbol" in the editor), you can benefit from syntax highlighting for your code example. – Willie Wong Apr 13 '11 at 18:32
  • @Willie: in the preview, the syntax hilighting doesn't seem to be for TeX or LaTeX. – Niel de Beaudrap Apr 13 '11 at 19:57
  • @user4852: this may not display correctly in DVI format, which is the one significant (?) drawback of TiKZ. I also am using Kile under Ubuntu; it displays properly in PDF format. – Niel de Beaudrap Apr 13 '11 at 19:58
  • @Niel: it is a known bug. See Geoff Dalgas's reply at this meta thread. Don't worry, the final output will be good. – Willie Wong Apr 13 '11 at 21:47
  • how to use tiKZ.i'm not using it.color of my arrows are not changing – user4852 Apr 14 '11 at 01:23
  • @user4852: are you putting a colour in the optional first argument to \indicate? In LaTeX, when a macro takes an argument in [square brackets], it usually denotes an "optional" argument — one which can be provided, or omitted. Take a look at the example I gave above, specifically at the commands being used at the end of each line in the itemize environment. (If you are using my example, then yes, you are using TiKZ: that's what the command \usepackage{tikz} in the pre-amble does.) – Niel de Beaudrap Apr 14 '11 at 06:17
  • problem is solved using texmaker – user4852 Apr 14 '11 at 07:09
  • 1
    @user4852: if you say so — the editor really shouldn't make any difference. – Niel de Beaudrap Apr 14 '11 at 07:38
7

An example with overlays

\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}

enter image description here

1

If you like to use Xy-pic, simply omit the "+" :

\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}

Indeed, the construction *{object} put the object without margin, the "+" add the margin. In fact, *+{object} is equivalent to {object} and even (if the object doesn't start with a macro) simply object .

For the color, simply use the @[color] modifier, for more about color, see xyref p.30.

Another solution is to define directly "longarrow", for example :

\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}
David Carlisle
  • 757,742
PHL
  • 7,555
  • color is not changing – user4852 Apr 14 '11 at 01:25
  • @user4852 short way : normally it does. Long way, if you want color you have to use the package color but the beamer class (at least in recent version) automatically load this package. – PHL Apr 14 '11 at 15:58