禁忌环境中的链接颜色被破坏

禁忌环境中的链接颜色被破坏

我有一个用环境构建的表格tabu,它不能显示其包含的 URL 的正确颜色,即使链接本身有效(即它在浏览器中打开网页)。

但是,从下面的示例中可以看出,链接在tabularlongtable环境中显示正确。

\documentclass{article}

\usepackage{longtable,tabu,tabularx}
\usepackage[colorlinks=true,urlcolor={[rgb]{.5,.5,.5}}]{hyperref}

\begin{document}
This link has the correct color: \href{http://tex.stackexchange.com}{http://tex.stackexchange.com}.

\begin{tabular}{|r|l|}
  an url in tabular & \href{http://tex.stackexchange.com}{http://tex.stackexchange.com}
\end{tabular}

\begin{tabu} spread 0pt {|r|l|}
  an url in tabu & \href{http://tex.stackexchange.com}{http://tex.stackexchange.com}
\end{tabu}

\begin{longtable}{|r|l|}
  an url in longtable & \href{http://tex.stackexchange.com}{http://tex.stackexchange.com}
\end{longtable}

\begin{longtabu} spread 0pt {|r|l|}
  an url in longtabu & \href{http://tex.stackexchange.com}{http://tex.stackexchange.com}
\end{longtabu}
\end{document}

在此处输入图片描述

那么,有没有办法让颜色在里面起作用tabu,还是我必须切换到其他环境?

答案1

我并不建议使用tabu。不过,解决方案很简单:通过名称定义颜色。

\documentclass{article}

\usepackage{longtable,tabu,tabularx}
\usepackage{xcolor}
\usepackage[colorlinks=true,urlcolor=myurlcolor]{hyperref}

\definecolor{myurlcolor}{rgb}{.8,.1,.1}

\begin{document}
This link has the correct color: \href{http://tex.stackexchange.com}{http://tex.stackexchange.com}.

\begin{tabular}{|r|l|}
  an url in tabular & \href{http://tex.stackexchange.com}{http://tex.stackexchange.com}
\end{tabular}

\begin{tabu} spread 0pt {|r|l|}
  an url in tabu & \href{http://tex.stackexchange.com}{http://tex.stackexchange.com}
\end{tabu}

\begin{longtable}{|r|l|}
  an url in longtable & \href{http://tex.stackexchange.com}{http://tex.stackexchange.com}
\end{longtable}

\begin{longtabu} spread 0pt {|r|l|}
  an url in longtabu & \href{http://tex.stackexchange.com}{http://tex.stackexchange.com}
\end{longtabu}
\end{document}

在此处输入图片描述

相关内容