# How to remove this extra space before url in bibliography?

How do I remove this space please? I'm using the natbib package

Code from ref.bib

@article{stats2017,
title={Digest of Education Statistics 2017},
author={\text{Statistics Mauritius}},
year={2017},
url={\url{http://statsmauritius.govmu.org/English/Publications/Pages/Edu_Stats_Yr2017.aspx}}
}


bibliography style

%\printbibliography
\setcitestyle{numbers} % set the citation style to numbers''.
\bibliographystyle{agsm}
\bibliography{ref.bib}

• The space printed there will also depend on the bibliography style (\bibliographystyle) your are using, so in order to help, you we would need to know about it. Please consider adding a complete example document (tex.meta.stackexchange.com/q/228/35864, tex.meta.stackexchange.com/q/4407/35864) to tell us what you are doing. But URL breaking is a bit tricky and it certainly looks as though this URL is hard to fit into the available space if you only allow the standard break points. – moewe Mar 31 '19 at 12:13
• you need to either add more break points for the url, or typeset the bibliography in \raggedright – Ulrike Fischer Mar 31 '19 at 12:16
• It (probably) won't help with your issue, but the author should be given as author={{Statistics Mauritius}},, there is no need for \text, but you do want to pairs of curly braces (tex.stackexchange.com/q/10808/35864). Usually you don't have to include the \url{...} macro in the url field, so url={http://statsmauritius.govmu.org/English/Publications/Pages/Edu_Stats_Yr2017.aspx}, should be enough. It could be that your style/bibliography package does not apply \url by default, but that can be changed (tex.stackexchange.com/q/9445/35864) – moewe Mar 31 '19 at 12:16
• Hi Moewe. I have added the bibligraphy style. in the main post. With the '\text', it was not displaying properly. As for the '\url' braces, i added it based on recommendation from earlier question. The url was not printing properly and overflowing the page. – Nadeem Muhammad Mar 31 '19 at 13:34
• Some url are showing correctly with no whitespace before them. There is an example in the image above. the first one is ok. the second one has white space before. – Nadeem Muhammad Mar 31 '19 at 13:35

The easiest solution, assuming your TeX distribution is reasonably up to date, consists of loading the xurl package; it allows arbritary line breaks in URL strings. Should your TeX distribution lack the xurl package, I suggest you (a) load the url package with the options spaces and hyphens and (b) switch to \raggedright right before \bibliography{ref}.

Whatever else you do, please encase the author field in an extra pair of curly braces. Doing so informs BibTeX that it's dealing with a "corporate" author and not with a person whose first name is "Statistics" and whose surname is "Mauritius". And do get rid of the \text wrapper too, as it is not appropriate here.

\RequirePackage{filecontents}
\begin{filecontents}{ref.bib}
@article{stats2017,
title  = "{Digest of Education Statistics 2017}",
author = "{Statistics Mauritius}",
year   = 2017,
url    = "http://statsmauritius.govmu.org/English/Publications/Pages/Edu_Stats_Yr2017.aspx",
}
\end{filecontents}

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[numbers,round]{natbib}
\bibliographystyle{agsm}
\renewcommand\harvardurl[1]{\textbf{URL}: \url{#1}} % optional
\usepackage{xurl} % allow line breaks anywhere in URL string

\begin{document}
\cite{stats2017}
\bibliography{ref}  % not "\bibliography{ref.bib}"
\end{document}

• Thanks for the suggestions. I cannot seem to be able to use the 'xurl' as i'm using overleaf. I tried the second option, it worked but the ref does not look so good when its reggedright. – Nadeem Muhammad Apr 1 '19 at 10:10