4

My references section sometimes shows a lot of whitespace between words that I would like to remove.

For example, in the following screenshot, I would like to remove the extra spaces within the text "Describing a link":

enter image description here

I know that I can use mbox (for example, \mbox{Describing a link}), but I'd like to apply some option to avoid this globally.

Update: The main answer worked for \url, but now I get the same issue when using \href:

\bibitem{Reference2} Some Name, \href{mailto:testlongname@example.com}{testlongname@example.com}

enter image description here

Here is the full example document:

\documentclass[12pt, a4paper, twocolumn]{article}

\usepackage{xurl} % Added based on the initial answer
\usepackage{hyperref}
\hypersetup{colorlinks = true, urlcolor = blue, linkcolor = blue, citecolor = blue}

\usepackage[super,comma,sort&compress]{natbib}

\usepackage{abstract}
\renewcommand{\abstractnamefont}{\normalfont\bfseries}
\renewcommand{\abstracttextfont}{\normalfont\small\itshape}

\title{Test Article}
\author{Test Author}

\begin{document}

\twocolumn[
  \begin{@twocolumnfalse}
    \maketitle
    \begin{abstract}
\noindent
Test abstract.
      \newline\newline
    \end{abstract}
  \end{@twocolumnfalse}
]

\section{Section1}

Lorem ipsum dolor sit amet\cite{Reference1}, consectetur adipiscing elit. Fusce maximus nisi ligula. Morbi laoreet ex ligula, vitae lobortis purus mattis vel. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec ac metus ut turpis mollis placerat et nec enim. Duis tristique nibh maximus faucibus facilisis. Praesent in consequat leo. Maecenas condimentum ex rhoncus, elementum diam vel, malesuada ante. Fusce pulvinar, mauris pretium placerat venenatis, lectus ex tempus lacus, id suscipit libero lorem eu augue. Interdum et malesuada fames ac ante ipsum primis in faucibus.

\section{Section2}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce maximus nisi ligula. Morbi laoreet ex ligula, vitae lobortis purus mattis vel. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec ac metus ut turpis mollis placerat et nec enim. Duis tristique nibh maximus faucibus facilisis. Praesent in consequat leo. Maecenas condimentum ex rhoncus, elementum diam vel, malesuada ante. Fusce pulvinar, mauris pretium placerat venenatis, lectus ex tempus lacus, id suscipit libero lorem eu augue. Interdum et malesuada fames ac ante ipsum primis in faucibus.

\begin{thebibliography}{99}
\bibitem{Reference1} Describing a link, \url{https://example.com/this_is_a_really_long_link_that_wraps_many_lines}
\bibitem{Reference2} Some Name, \href{mailto:testlongname@example.com}{testlongname@example.com}
\end{thebibliography}

\end{document}
  • 1
    Well, packages url and xurl are prepared to work with command \url but not with \href{}{}. Because the second parameter of \href is set as normal text you can try \href{mailto:testlongname@example.com}{testlongname@example. com} (I added an blank in the second parameter to allow there a break) ... But you need to this manually for each issue ... – Mensch Jan 4 at 2:52
7

In your case you can simply add \usepackage{xurl} in your preamble. Be sure to call xurl before package hyperref (if you omit that, hyperref itself calls package url with the result you got ...)!

With the following code

\documentclass[12pt, a4paper, twocolumn]{article}

\usepackage{xurl} % <===================================================
\usepackage{hyperref}
\hypersetup{colorlinks = true, urlcolor = blue, linkcolor = blue, citecolor = blue}

\usepackage[super,comma,sort&compress]{natbib}

\usepackage{abstract}
\renewcommand{\abstractnamefont}{\normalfont\bfseries}
\renewcommand{\abstracttextfont}{\normalfont\small\itshape}

\title{Test Article}
\author{Test Author}

\begin{document}

\twocolumn[
  \begin{@twocolumnfalse}
    \maketitle
    \begin{abstract}
\noindent
Test abstract.
      \newline\newline
    \end{abstract}
  \end{@twocolumnfalse}
]

\section{Section1}

Lorem ipsum dolor sit amet\cite{Reference1}, consectetur adipiscing elit. Fusce maximus nisi ligula. Morbi laoreet ex ligula, vitae lobortis purus mattis vel. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec ac metus ut turpis mollis placerat et nec enim. Duis tristique nibh maximus faucibus facilisis. Praesent in consequat leo. Maecenas condimentum ex rhoncus, elementum diam vel, malesuada ante. Fusce pulvinar, mauris pretium placerat venenatis, lectus ex tempus lacus, id suscipit libero lorem eu augue. Interdum et malesuada fames ac ante ipsum primis in faucibus.

\section{Section2}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce maximus nisi ligula. Morbi laoreet ex ligula, vitae lobortis purus mattis vel. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec ac metus ut turpis mollis placerat et nec enim. Duis tristique nibh maximus faucibus facilisis. Praesent in consequat leo. Maecenas condimentum ex rhoncus, elementum diam vel, malesuada ante. Fusce pulvinar, mauris pretium placerat venenatis, lectus ex tempus lacus, id suscipit libero lorem eu augue. Interdum et malesuada fames ac ante ipsum primis in faucibus.

\begin{thebibliography}{99}
\bibitem{Reference1} Describing a link, \url{https://example.com/this_is_a_really_long_link_that_wraps_many_lines}
\end{thebibliography}

\end{document}

you get the result:

enter image description here

  • Update: The main answer worked for \url, but now I get the same issue when using \href. I updated the question and example document to show the new issue. – freeradical Jan 4 at 0:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.