[Tex/LaTex] How to remove this extra space before url in bibliography

bibliographiesnatbiburl

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

space before url

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}

Best Answer

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.

enter image description 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} 
Related Question