2

I'm trying to get a leftrightarrow under a chunk of text with text centered under each arrow so it would look something like this

v = (0 1 ... 1 0 ... 0)
       <-----> <----->
          n       p

I've tried

\begin{array}{lccr}
v = (0 & \underleftrightarrow{1 \cdots 1} & \underleftrightarrow{0 \cdots 0} &) \\
       & p & n &
\end{array}

But I find there is not enough vertical space between 1 ... 1 and the arrow, but there is too much space between the arrow and p. Also, the horizontal spacing is uneven.


The spacing here is rather better

\begin{align*}
v = (0\ & 1 \cdots 1\ 0 \cdots 0) \\
& \overleftrightarrow{\phantom{1 \cdots 1}}\ \overleftrightarrow{\phantom{0 \cdots 0}} 
\end{align*}

but then I don't know how to attach text under the arrows.


Writing text over a \leftrightarrow doesn't cut it for me, since I want the v = etc to be aligned to the rest of the line with the arrow underneath.

2 Answers 2

3

Here I create \myarrow in the syntax of \xleftrightarrow, execpt using stacks to accomplish it. (currently only works in \displaystyle, if that is OK)

\documentclass{article}
\usepackage{stackengine,mathtools}
\newcommand\myarrow[2][]{%
  \setstackEOL{\\}%
  \setstackgap{L}{.7\baselineskip}%
  \setbox0=\hbox{$\displaystyle #1$}%
  \setbox2=\hbox{$\displaystyle #2$}%
  \ensurestackMath{%
    \Longunderstack{#2 \\ \xleftrightarrow[\rule{\wd2}{0pt}]{\rule{\wd0}{0pt}} \\ #1}%
  }%
}

\begin{document}
\[
v = \{ 0 \myarrow[n]{1 \dots 1} \myarrow[p]{0 \dots 0}\}
\]
\end{document}

enter image description here

If one wants less overhang of the arrows...

\documentclass{article}
\usepackage{stackengine,mathtools}
\newcommand\myarrow[2][]{%
  \setstackEOL{\\}%
  \setstackgap{L}{.7\baselineskip}%
  \setbox0=\hbox{$\displaystyle #1$}%
  \setbox2=\hbox{$\displaystyle #2$}%
  \ensurestackMath{%
    \Longunderstack{#2 \\ \xleftrightarrow[\rule{\dimexpr\wd2-4pt}{0pt}]{%
                                           \rule{\dimexpr\wd0-4pt}{0pt}} \\ #1}%
  }%
}

\begin{document}
\[
v = \{ 0 \myarrow[n]{1 \dots 1} \myarrow[p]{0 \dots 0}\}
\]
\end{document}

enter image description here

0

Easy to do with pstricks. For pdflatex, don't forget to --enable-write 18\ (MiKTeX) or to -shell-escape (TeX Live, MacTeX).

\documentclass{article}
\usepackage{pst-node, auto-pst-pdf}

\begin{document}

  \begin{postscript}
\[ v = (0\ &\pnode(0, -1ex){a}{1} \cdots 1 \pnode(0, -1ex){b}\ \pnode (0, -1ex){c}0\cdots 0\pnode(0, -1ex){d})
\everypsbox{\scriptstyle}
\psset{linewidth=0.4pt, arrows=<->, arrowinset=0.2, shortput=nab, labelsep = 0.5ex}
\ncline{a}{b}_{n}
\ncline{c}{d}_{p}
 \] 
 \end{postscript}

\end{document} 

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .