表格中的 URL 中断

表格中的 URL 中断

如何hyperref在环境中破坏 URL tabular。请考虑以下示例:

\documentclass{article}

\usepackage[colorlinks=true,linkcolor=black,anchorcolor=black,citecolor=black,menucolor=black,runcolor=black,urlcolor=black,bookmarks=true]{hyperref}
\usepackage{breakurl}

\begin{document}

\url{http://www.avery/long/url?zz/very/very/long/this/should/break/very/long/long.html}

\begin{tabular}{l l}
   A long url &
\url{http://www.avery/long/url?zz/very/very/long/this/should/break/very/long/long.html}

\end{tabular}


\end{document}

第一个中断了,第二个没有。输出如下:

网址

我在用pdflatex

答案1

使用p{10.0cm}需要长度的列规范。这使得列可以有换行符:

在此处输入图片描述

\documentclass{article}

\usepackage[colorlinks=true,linkcolor=black,anchorcolor=black,citecolor=black,menucolor=black,runcolor=black,urlcolor=black,bookmarks=true]{hyperref}
\usepackage{breakurl}

\begin{document}
\noindent
\url{http://www.avery/long/url?zz/very/very/long/this/should/break/very/long/long.html}

\noindent
\begin{tabular}{l p{10.0cm}}
   A long url &
\url{http://www.avery/long/url?zz/very/very/long/this/should/break/very/long/long.html}
\end{tabular}
\end{document}

答案2

l规范无法控制列宽,因此无法正确拆分 URL。可以使用p{<len>}列规范(其中<len>是已知的 TeX 长度)修复列,或者使用tabularx包裹将表格宽度固定为某个最大值:

带有 URL 的 Tabularx

\documentclass{article}
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\usepackage[colorlinks=true,linkcolor=black,anchorcolor=black,citecolor=black,menucolor=black,runcolor=black,urlcolor=black,bookmarks=true]{hyperref}% http://ctan.org/pkg/hyperref
%\usepackage{breakurl}% http://ctan.org/pkg/breakurl

\begin{document}

\noindent\url{http://www.avery/long/url?zz/very/very/long/this/should/break/very/long/long.html}

\noindent\begin{tabularx}{\textwidth}{l X}
   A long url & \url{http://www.avery/long/url?zz/very/very/long/this/should/break/very/long/long.html}
\end{tabularx}

\end{document}​

hyperref加载url包裹默认情况下,它可以很好地分解 URL。

相关内容