长 href 在文本和引用中都超出了页面范围,我该如何防止这种情况?

长 href 在文本和引用中都超出了页面范围,我该如何防止这种情况?

我有很长的 URL,但似乎在文本和引用中都被截断了。

\documentclass{article}

\usepackage[english]{babel}

\usepackage[letterpaper,top=2cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}

\usepackage[colorlinks=true, allcolors=blue]{hyperref}

\begin{document}

url with no hyphens that is long and already starts halfway across the page \href{http://sadlkjfdlkabfskalbjflskdbgfksldabvladbcviuldasbcalsuncilsalxbvucx.com/}{http://sadlkjfdlkabfskalbjflskdbgfksldabvladbcviuldasbcalsuncilsalxbvucx.com/}

random citation \cite{zotero-180}

\bibliographystyle{naturemag}

\bibliographystyle{alpha}
\bibliography{sample}

\end{document}

我的围兜文件:

@misc{zotero-180,
  title = {{{this long citation also appears in bib gets cut}}},
  file = {C\:\\Users\\myfile.html},
  howpublished = {http://sadlkjfdlkabfskalbjflskdbgfksldabvladbcviuldasbcalsuncilsalxbvucx.com/}
}

答案1

好吧,您可以简单地xurl像这样加载包:

\begin{filecontents*}{\jobname.bib}
@misc{zotero-180,
  title = {{{this long citation also appears in bib gets cut}}},
  file = {C\:\\Users\\myfile.html},
  howpublished = {\url{http://sadlkjfdlkabfskalbjflskdbgfksldabvladbcviuldasbcalsuncilsalxbvucx.com/}},
}
\end{filecontents*}


\documentclass{article}

\usepackage[english]{babel}
\usepackage[letterpaper,top=2cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}

\usepackage{xurl} % <===================================================
\usepackage[colorlinks=true, allcolors=blue]{hyperref}

\begin{document}

url with no hyphens that is long and already starts halfway across the page 
\url{http://sadlkjfdlkabfskalbjflskdbgfksldabvladbcviuldasbcalsuncilsalxbvucx.com/} % <===============

random citation \cite{zotero-180}

%\bibliographystyle{naturemag} % <======================================

\bibliographystyle{alpha}
\bibliography{\jobname}

\end{document}

请看一下,我使用的是\url您以前使用的\href{}{}方法xurl

得到的pdf是:

在此处输入图片描述

相关内容