5

I ran across the problem of underfull \hbox when I want to typeset a long url(long enough to fill two lines) in the footnote. Here is my MWE:

\documentclass{article}
\usepackage{hyperref}
\usepackage{ragged2e}

\begin{document}

We use this dataset
\footnote{\url{http://archive.ics.uci.edu/ml/datasets/Parkinson+Speech+Dataset+with++Multiple+Types+of+Sound+Recordings\#}}
for experimentation.
\end{document} 

After searching the web, this post suggests using \RaggedRight from the ragged2e package. But I think the \RaggedRightdoes not "really" solve this problem, it just hides the "underfull \hbox" warning. Below is the produced footnote of the above MWE: enter image description here

After using the \RaggedRight command, i.e., change from

\footnote{\url{http://archive.ics.uci.edu/ml/datasets/Parkinson+Speech+Dataset+with++Multiple+Types+of+Sound+Recordings\#}}

in the MWE to

\footnote{\RaggedRight\url{http://archive.ics.uci.edu/ml/datasets/Parkinson+Speech+Dataset+with++Multiple+Types+of+Sound+Recordings\#}}

. The warning disappears. But the produced footnote is (in my opinion) the same as before, see the image below: enter image description here

My question is, how to "really" solve this problem? In my naive thought, why not LaTeX move some charcters from the second line, say the characters "+Multipl", to the empty space in the end of first line. After all, url are just a series of charcters, why not stuff the first line with some charcters from the second line to make full use of first line? Or there are some hidden facts which are very complicated?

Any answers or pointer to answers are appreciated!

4

Rather than breaking mid-word, you can re-introduce some stretch space around the break characters (. and / here) I use

\Urlmuskip=0mu  plus 10mu

which allows more than enough flexibility in this case.

enter image description here

\documentclass{article}
\usepackage{hyperref}

\Urlmuskip=0mu  plus 10mu
\begin{document}

We use this dataset
\footnote{\url{http://archive.ics.uci.edu/ml/datasets/Parkinson+Speech+Dataset+with++Multiple+Types+of+Sound+Recordings\#}}
for experimentation.

\vfill

\noindent X\dotfill X
\end{document} 
5

\url tries hard to break the url only at "sensible" places. But if you don't like this you can allow \url to break everywhere:

\documentclass{article}
\usepackage{hyperref}

\makeatletter
\g@addto@macro{\UrlBreaks}{%
\do\/\do\a\do\b\do\c\do\d\do\e\do\f%
\do\g\do\h\do\i\do\j\do\k\do\l\do\m%
\do\n\do\o\do\p\do\q\do\r\do\s\do\t%
\do\u\do\v\do\w\do\x\do\y\do\z%
\do\A\do\B\do\C\do\D\do\E\do\F\do\G%
\do\H\do\I\do\J\do\K\do\L\do\M\do\N%
\do\O\do\P\do\Q\do\R\do\S\do\T\do\U%
\do\V\do\W\do\X\do\Y\do\Z}
\makeatother
\begin{document}

We use this dataset
\footnote{\url{http://archive.ics.uci.edu/ml/datasets/Parkinson+Speech+Dataset+with++Multiple+Types+of+Sound+Recordings\#}}
for experimentation.
\end{document} 

enter image description here

Be aware that as there are no stretchable spaces the line is still a bit underfull.

  • might not microtype help by slightly deforming the characters in the string? (not saying that it's a good idea ...) – barbara beeton Nov 17 '16 at 15:11
  • 1
    @Ulrike Fischer, why are there still underfull warning when the first line is seemingly fully used? – jdhao Nov 17 '16 at 15:29
  • @barbarabeeton: Perhaps, but not by default (microtype imho doesn't expand typewriter fonts, beside this url uses math spacing). – Ulrike Fischer Nov 17 '16 at 15:34
  • @ the code in the preamble is a bit long (no offence), is there a more elegant way to do that? By the way, any pointer to how the calculation of badness works(the badness is still 10000, not changed) – jdhao Nov 17 '16 at 15:37
  • You can active font expansion for the typewriter if you want to get rid of the underfull hbox: \usepackage{microtype}\UseMicrotypeSet [expansion] {alltext}. – Ulrike Fischer Nov 17 '16 at 16:09
1

A solution that worked for me was to replace \url with \href. However, if your URL does not contain any breakable character (e.g. -), you will have to help it find by inserting some \hspace{0pt} (zero-width space) at strategic locations.

In your case, I added one after each '+'.

\footnote{\href{http://archive.ics.uci.edu/ml/datasets/Parkinson+Speech+Dataset+with+Multiple+Types+of+Sound+Recordings\#}{http://archive.ics.uci.edu/ml/datasets/Parkinson+\hspace{0pt}Speech+\hspace{0pt}Dataset+\hspace{0pt}with+\hspace{0pt}Multiple+\hspace{0pt}Types+\hspace{0pt}of+\hspace{0pt}Sound+\hspace{0pt}Recordings\#}}
  • The url can not be split into two lines if it is too long to fit in one line. Have you checked your answer? – jdhao Feb 2 '18 at 8:19
  • Thanks for the kind feedback. As mentioned above, I indeed checked it and it worked well on my own case. However I did notice that my URL happened to contains breakable chars (-) and that it would not work if an URL does not. In this case, one will have to insert some \hspace{0pt} at strategic locations in the text part. I updated my answer. – Quentin Roy Feb 2 '18 at 8:31
  • I think it is a bit awkward to manually adjust the url. If we have several url to process, it would be tedious and error-prone. – jdhao Feb 2 '18 at 8:37
  • If I may, we’re talking about word processing not programming. This is latex not C or python :) – Quentin Roy Jun 9 '18 at 22:02

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.