1

I'm trying to make sure that bibliography entries stay within the margins of the page. But annoyingly, I get entries like this sometimes, where the DOI runs off the margin:

bibliography

Does anyone know a good way to stop this happening? Or whether there is something wrong with my code (quite possibly) ?

This is my code (simplified) :

\documentclass[12pt]{book}
\usepackage[a4paper, tmargin={1.75in}, bmargin={1.5in}, lmargin={1.25in}, rmargin={1.25in}]{geometry}
\usepackage{setspace}
\onehalfspacing

\usepackage{hyperref} \hypersetup{ colorlinks, citecolor=black, filecolor=black, linkcolor=black, urlcolor=black }

\usepackage{changepage}

\usepackage{caption} \captionsetup{format=hang, justification=raggedright, singlelinecheck=false}

\renewcommand{\footnotesize}{\fontsize{12pt}{12pt}\selectfont}

\usepackage{booktabs}

\usepackage[ backend=biber, style=authoryear, ]{biblatex} \addbibresource{references.bib}

\usepackage[utf8]{inputenc} \usepackage{pdflscape} % \usepackage{showframe} \usepackage{adjustbox} \usepackage{graphicx} \usepackage{tabularx}

\usepackage[labelfont=bf]{caption}

\begin{document}

\printbibliography[heading=none]

\end{document}

Many thanks

Mico
  • 506,678
  • Welcome to TeX.SE. – Mico Jan 28 '23 at 15:18
  • 1
    Your sample code doesn't contain a single \cite directive or bib entry -- and hence cannot be used to replicate the problem you say you're experiencing. Please edit your query and post the bibtex code for the entry authored by Stedman. – Mico Jan 28 '23 at 15:22
  • 1
    Off-topic: I can't help but remark that the instruction \renewcommand{\footnotesize}{\fontsize{12pt}{12pt}\selectfont} looks, to put it delicately, a tad unusual. What's the purpose of eliminating all "leading" between lines? If what you mainly want to achieve is to keep footnote material from being rendered at a size that's about 20% smaller than the regular document font size, running \renewcommand{\footnotesize}{\normalsize} should do the trick. – Mico Jan 28 '23 at 15:26
  • 2
    See also https://tex.stackexchange.com/q/442308/35864 for more general hints on line breaking in the bibliography. – moewe Jan 28 '23 at 16:33
  • 1
    @Mico Thanks for that suggestion - I'm new to latex, so really have no idea what I'm doing right now – Reuben Long Jan 29 '23 at 12:11
  • @moewe -- Great answer of yours in the link you provided. Regarding the passage "If you don't want to play around with the values of biburlnumpenalty etc. yourself and just want all URLs to break everywhere, you can load the xurl package": I'd give this passage a lot more visual prominence, in part because I doubt that many people have either the patience or the stomach to play around with biburlnumpenalty and friends. If you can make this adjustment, I'd be happy to close the present query as a duplicate. :-) – Mico Jan 29 '23 at 13:09

1 Answers1

1

I suggest you load the xurl package as well. Its purpose is to instruct LaTeX to allow line breaks to occur as needed at arbitrary locations inside URL strings and URL-like objects such as DOI strings that may occur in bibliographic entries.

enter image description here

\documentclass[12pt]{book}
\begin{filecontents}[overwrite]{references.bib}
@article{stedman,
   author   = "Richard C. Stedman",
   journal  = "Environment and behavior",
   title    = "Toward a Social Psychology of Place: 
               Predicting Behavior from Place-Based
               Cognitions, Attidude, and Identity",
   year     = 2002,
   month    = sep,
   volume   = 34,
   number   = 5,
   pages    = "561--581",
   issn     = "0013-9165",
   doi      = "10.1177/0013916502034005001",
}  
\end{filecontents}

\usepackage[a4paper, tmargin=1.75in, bmargin=1.5in, lmargin=1.25in, rmargin=1.25in]% {geometry}

\usepackage[onehalfspacing]{setspace}

\usepackage{hyperref} \hypersetup{colorlinks,allcolors=black}

\usepackage{changepage}

\usepackage{caption} \captionsetup{labelfont=bf, format=hang, justification=raggedright, singlelinecheck=false} % \usepackage[labelfont=bf]{caption}

%%\renewcommand{\footnotesize}{\fontsize{12pt}{12pt}\selectfont} % huh?? \renewcommand{\footnotesize}{\normalsize}

\usepackage{booktabs}

\usepackage[backend=biber,style=authoryear]{biblatex} \addbibresource{references.bib}

%\usepackage[utf8]{inputenc} % that's the default nowadays \usepackage{pdflscape} % \usepackage{showframe} \usepackage{adjustbox} \usepackage{graphicx} \usepackage{tabularx}

\usepackage{xurl} % <-- new

\begin{document} \renewcommand\familydefault\sfdefault\selectfont % mimic OP's screenshot \nocite{*} \printbibliography[heading=none] \end{document}

Mico
  • 506,678