[Tex/LaTex] Space between words in bibliography

bibtexelsarticle

tex code as below.

\documentclass[a4paper,11pt,number]{elsarticle} 
\usepackage{times}%Use Times New Roman Font 
\usepackage[hyphens]{url} %To recognize URLs 
\begin{document} 
\title{Integrated Model for Power Interruption Contracts} 
\author{Lakshmi Palaparambil Dinesh} 
\begingroup %\raggedright 
\bibliography{reference_PowerInterruption} 
%\bibliographystyle{apalike} 
\bibliographystyle{elsarticle-num} 
\endgroup 
\end{document}

I see spaces between words or parts of the url with some white spaces after using hyphens with the url package. How to remove the remaning additional white spaces?

enter image description here

Best Answer

Because you gave us no bib file I created one for testing.

Please see the following MWE (package filecontents is only used to have bib file and tex code together in one compilable MWE):

\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@Book{Goossens,
  author    = {Goossens, Michel and Mittelbach, Frank and 
               Samarin, Alexander},
  title     = {The LaTeX Companion},
  edition   = {1},
  publisher = {Addison-Wesley},
  location  = {Reading, Mass.},
  year      = {1994},
}
@Book{adams,
  title     = {The Restaurant at the End of the Universe},
  author    = {Douglas Adams},
  series    = {The Hitchhiker's Guide to the Galaxy},
  publisher = {Pan Macmillan},
  year      = {1980},
}
@article{feynman,
  title     = {Very High-Energy Collisions of Hadrons},
  author    = {Richard P. Feynman},
  journal   = {Phys. Rev. Lett.},
  volume    = {23},
  issue     = {24},
  pages     = {1415--1417},
  year      = {1969},
  month     = {Dec},
  doi       = {10.1103/PhysRevLett.23.1415},
  url       = {http://link.aps.org/doi/10.1103/PhysRevLett.23.1415},
  publisher = {American Physical Society},
}
@article{einstein,
  author  = {Albert Einstein},
  title   = {{Zur Elektrodynamik bewegter K{\"o}rper}. ({German})
             [{On} the electrodynamics of moving bodies]},
  journal = {Annalen der Physik},
  volume  = {322},
  number  = {10},
  pages   = {891--921},
  year    = {1905},
  DOI     = {http://dx.doi.org/10.1002/andp.19053221004},
}
@Article{Schamb2010,
  Title      = {Properties of the Distant Kuiper Belt: Results from the
                Palomar Distant Solar System Survey},
  Author     = {(Megan E.) Schwamb and (Michael E.) Brown and
                (David L.) Rabinowitz and Darin Ragozzine},
  Journal    = {The Astrophysical Journal},
  Year       = {2010},
  Month      = {September},
  Number     = {2},
  Pages      = {17},
  Volume     = {720},
  Doi        = {10.1088/0004-637X/720/2/1691},
  Timestamp  = {2014.09.21},
  Url        = {http://m.iopscience.iop.org/0004-637X/720/2/1691/pdf/0004-637X\_720\_2\_1691.pdf}
}
\end{filecontents*}


\documentclass[a4paper,11pt,number]{elsarticle} 

\usepackage{showframe}    % to visualise the typing area and margins
\usepackage{times}        % Use Times New Roman Font 
\usepackage[hyphens]{url} % To recognize URLs 
\usepackage{ragged2e}     % command \RaggedRight

\begin{document}

\title{Integrated Model for Power Interruption Contracts} 
\author{Lakshmi Palaparambil Dinesh} 

This is text with \cite{Goossens, einstein} and \cite{adams}.
\nocite{*} % to test all bib entrys

{
%\RaggedRight % <===================================================
\bibliographystyle{elsarticle-num} % apalike
\bibliography{\jobname} 
}

\end{document}

you get the following result:

resulting pdf

I marked the resulting white space you do not want with red rules ... The most elegant way I knew to get rid of them is to use package ragged2e, which gives you command \RaggdRight to get left justified text with better hyphenation! Please uncomment \RaggdRight in the MWE (see marking <=======) and recompile.

The result you get is now:

enter image description here

The red arrows marks the layout changings. For me that solution is much more better than the first ...

Related Question