![如何将参考书目条目中的长单词/数字保留在页边距内](https://linux22.com/image/460365/%E5%A6%82%E4%BD%95%E5%B0%86%E5%8F%82%E8%80%83%E4%B9%A6%E7%9B%AE%E6%9D%A1%E7%9B%AE%E4%B8%AD%E7%9A%84%E9%95%BF%E5%8D%95%E8%AF%8D%2F%E6%95%B0%E5%AD%97%E4%BF%9D%E7%95%99%E5%9C%A8%E9%A1%B5%E8%BE%B9%E8%B7%9D%E5%86%85.png)
我试图确保参考书目条目保持在页面边缘内。但令人恼火的是,我有时会收到这样的条目,其中 DOI 超出了边缘:
有人知道有什么好方法可以阻止这种情况发生吗?或者我的代码是否有问题(很有可能)?
这是我的代码(简化):
\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}
非常感谢
答案1
我建议你加载网址包也是如此。其目的是指示 LaTeX 允许在 URL 字符串和 URL 类对象(例如可能出现在书目条目中的 DOI 字符串)内的任意位置根据需要出现换行符。
\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}