# URI with & in \href inside tabular inside a beamer frame

I have a strange effect, when I want to typeset a URI inside a tabular in a frame.

Example:

\documentclass[10pt]{beamer}
\usepackage{hyperref}
\begin{document}

\begin{frame}
\href{http://www.mysite.de/xxx}{page 1} --
\href{http://www.mysite.de/xxx&}{page 1}
\end{frame}

\begin{frame}
\begin{tabular}{l}
\href{http://www.mysite.de/xxx}{url without \&} %ok
\end{tabular}
\end{frame}

%Error
\begin{frame}%[fragile]
\begin{tabular}{l}
\href{http://www.mysite.de/xxx&}{url with \&}   %! Argument of \href@split has an extra }.
\end{tabular}
\end{frame}

\end{document}


When I translate the document, I get the error

! Argument of \href@split has an extra }.
<inserted text>
\par
l.21     \end{frame}


I have no problem with \href in a frame (see first frame), I have no problem with \href inside a tabular (see 2nd frame), but I have a problem if \href contains a & and it is part of a tabular.

The example works fine, if the frame gets a fragile flag. I understand, why I need the fragile flag, if I use verbatim text, but why is the fragile flag needed, if there is a combination of tabular and href-content?

Is there a way to avoid the fragile-flag in this situations?

-
You said it: the treatment of URLs by \href is very similar to verbatim mode. –  egreg Jul 9 '12 at 10:18

The solution is to "hide" the & from the tabular environment by closing the \href into brackets:

\documentclass[10pt]{beamer}
\begin{document}

\begin{frame}
\href{http://www.mysite.de/xxx}{page 1} --
\href{http://www.mysite.de/xxx&}{page 1}
\end{frame}

\begin{frame}
\begin{tabular}{l}
\href{http://www.mysite.de/xxx}{url without \&}
\end{tabular}
\end{frame}

%Error
\begin{frame}%[fragile]
\begin{tabular}{l}
{\href{http://www.mysite.de/xxx&}{url with \&}}
\end{tabular}
\end{frame}

\end{document}


Note: beamer loads hyperref as default, you do not need to load it yourself.

-