On way to do this with TikZ is the following:
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
a
% `inner sep=0` removes unwanted padding in the nodes;
% `baseline, anchor=base` alignes the baseline of the text in the nodes
% with the baseline of the sourrounding text;
% `>=latex` selects the arrow style (see the TikZ manual for which
% arrows are available.
\begin{tikzpicture}[inner sep=0cm,baseline,anchor=base,>=latex]
% the first node, named 'left-node'
\node (left-node) {$(\forall x \in X)$};
% add a second node to the right of left-node
\node [right=0cm of left-node] (right-node) {$(\forall y \in Y)$};
% draw the connecting line between the north sides of the two nodes,
% 1.5ex above the nodes.
\draw[<->,red] (left-node.north) |- +(0,1.5ex) -| (right-node.north);
% alternatively, draw a line between the north sides of the two nodes, with
% starting angle 30° and ending at 150°.
%\draw[<->,red] (left-node.north) to[out=30,in=150] (right-node.north);
\end{tikzpicture}
b
\end{document}
Which gives or , depending on which of the lines starting with \draw
you uncomment. Depending on where you want to use this, you might want to add \displaystyle
in the math in the two nodes.
There seems to be interest in doing something like pst-node
in TikZ. A first approximation would be (the following examples need to be compiled two times)
\newcommand\tikzmark[1]{\tikz[remember picture,overlay,baseline=-1ex] \node (#1) {};}
\[(\forall x\tikzmark{a}\in X)(\forall y\tikzmark{b}\in Y)\]
\tikz[remember picture,overlay] \draw[<->,red] (a.north) |- +(0,1.5ex) -| (b.north);
This is however not quite what one wants, in this case, as the mark is not in the middle:
Adding a second parameter to \tikzmark
is not quite trivial as just putting the content into a node destroys all context (mathmode, spacing, etc.). I can't quite follow what pst-node
does in \rnode
(but judging from the result some space gets lost). If the usage is limited to simple cases, the following should work reasonably well (if necessary add \displaystyle
):
\newcommand\tikzmark[2]{\tikz[remember picture,baseline,anchor=base] \node (#1) {$#2$};}
\[(\forall x\tikzmark{a}{\in} X)(\forall y\tikzmark{b}{\in} Y)\]
\tikz[remember picture,overlay] \draw[<->,red] (a.north) |- +(0,1.5ex) -| (b.north);
There is one more problem: overlayed pictures do not take any space, so the line and arrows might collide with text on the preceding line. I don't know how to fix this without manually adding some space.
With my first example, you can also do more fancy things, like
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning,decorations.pathreplacing,calc}
\begin{document}
\[
\begin{tikzpicture}[inner sep=0cm,baseline,anchor=base,>=latex,decoration=brace]
\node (left-node) {$(\forall x \in X)$};
\node [right=0cm of left-node] (right-node) {$(\forall y \in Y)$};
\draw[decorate,red] ($(left-node.north west)+(0.3ex,0.2ex)$) -- ($(left-node.north east)+(-0.3ex,0.2ex)$);
\draw[decorate,red] ($(right-node.north west)+(0.3ex,0.2ex)$) -- ($(right-node.north east)+(-0.3ex,0.2ex)$);
\draw[<->,red,transform canvas={yshift=1.2ex}] (left-node.north) to[out=30,in=150] (right-node.north);
\end{tikzpicture}
\]
\end{document}
Best Answer
I'd typeset
\xrightarrow
, back up a little and add\rightarrow
: