2

I want to cite and format the bibliographic references according to APA style. So I tried:

    \documentclass[12pt,a4paper,twoside]{article}
    \usepackage{amsmath}
    \usepackage{setspace}
    \usepackage{apacite}
    \begin{document}
    \title{blabla}
        \author{blabla}
        \date{\today}
        \maketitle
    \cite{delistraty_2014}

    \bibliographystyle{apacite}
    \bibliography{ref.bib}
    \end{document}

But the output of the reference list seems weird Spaces are totally wrong, and the hyperlink of the website has a strange font.

So what can I do to solve it out?

Mico
  • 506,678
  • Welcome to TeX.SE. You need to load the url package and/or the hyperref package in order to enable line breaks in long URL strings. – Mico Feb 26 '18 at 08:56

2 Answers2

2

To typeset long URL strings, it's a good idea to load the url package and/or the hyperref package. That way, LaTeX is much more likely to "find" permissible line break opportunities.

enter image description here

\RequirePackage{filecontents}
\begin{filecontents}{ref.bib}
@misc{delistraty_2014,
  author = "Cody C. Delistraty",
  title  = "The Beauty-Happiness Connection",
  year   = 2014,
  month  = "Aug.",
  howpublished = "Atlantic Media Co.", 
  url    = "https://www.theatlantic.com/health/archive/2014/08/the-beautyhappiness-connection/375678/",
}
\end{filecontents}

\documentclass[12pt,a4paper,twoside]{article}
\usepackage{apacite}
\bibliographystyle{apacite}
\usepackage[hyphens,spaces,obeyspaces]{url}

\begin{document}
\cite{delistraty_2014}
\bibliography{ref}
\end{document} 
Mico
  • 506,678
  • If you want the URL string to use the main text font instead of a monospaced font, just issue the directive \urlstyle{same} after loading the url package. – Mico Feb 26 '18 at 09:27
  • Yes, it works. Thanks very much! Another problem is what if I want the url in the reference to be a hyperlink? What should I do, instead of "\cite{xxxxx}"? – user155860 Feb 26 '18 at 15:36
  • @user155860 - If you want to enable hyperlinking of URL strings, you must load the hyperref package. – Mico Feb 26 '18 at 15:43
  • However, if I use "hyperref" package, I can't use \cite{xxx} command. So what should I do? – user155860 Mar 04 '18 at 08:57
  • @user155860 - This is very strange. Please tell us how you load the hyperref package. In particular, do you load it after the url package? If not, you need to change that. Also, try loading the apacite package with the option natbibapa. – Mico Mar 04 '18 at 09:20
  • 1
    Yes,hyperref going after url solves the problem. Thank you! – user155860 Mar 05 '18 at 09:16
1

Loading the xurl-package should solve the problem:

\RequirePackage{filecontents}
\begin{filecontents}{ref.bib}
@misc{delistraty_2014,
  author = "Cody C. Delistraty",
  title  = "The Beauty-Happiness Connection",
  year   = 2014,
  month  = "Aug.",
  howpublished = "Atlantic Media Co.", 
  url    = "https://www.theatlantic.com/health/archive/2014/08/the-beautyhappiness-connection/375678/",
}
\end{filecontents}
\documentclass[12pt,a4paper,twoside]{article}
\usepackage{amsmath}
\usepackage{setspace}
\usepackage{apacite}
\usepackage{xurl}
\begin{document}
\title{blabla}
    \author{blabla}
    \date{\today}
    \maketitle
\cite{delistraty_2014}

\bibliographystyle{apacite}
\bibliography{ref.bib}
\end{document}

The compilde document

mittens
  • 97
  • 1
    Welcome to TeX.SE! You could improve your answer if you try it out and share your MWE and your result which shows that your recommendation really solves the problem. – Οὖτις Mar 04 '23 at 14:49
  • 1
    Thankx a bunch @Οὖτις, just did that – mittens Mar 04 '23 at 15:12