3

I'm currently confronted with some problems regarding linebreaks inside citations. I'm using biblatex with a biber backend.

config:

\usepackage[hidelinks,breaklinks]{hyperref} 
\usepackage{csquotes}
\usepackage[backend=biber, 
style=alphabetic,
natbib=true, 
hyperref=true, 
]{biblatex}

Most of the time when I create a citation like this \cite[354]{reference1} and it comes to the end of a line a linebreak is inserted just fine:

how it should be

However, sometimes the linebreak fails. Command is \cite[270]{reference2}:

how it is sometimes

It doesn't seem to be related to the position of the citation within the sentence. I've already seen some similar questions but I could not figure out a working solution. Am I missing something?


MWE:

\documentclass[parskip=half,12pt]{scrreprt}
\usepackage[a4paper, margin=2.54cm, marginparwidth=2.0cm, footskip=1.0cm]{geometry}
\usepackage{mathptmx}
\usepackage{filecontents}
\begin{filecontents}{abc.bib}
    @book{xyz,
        title={Iasd},
        author={Kersten, X. and Bjhsdfojgf, A.D. and HBjdsf, J. and Sjkvhds, K.W.},
        year={2013},
    }
\end{filecontents}
\usepackage[backend=biber, 
style=alphabetic,
natbib=true, 
hyperref=true, 
]{biblatex}
\addbibresource{abc.bib}
\begin{document}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed dm nonumlllllllllllll \cite[270]{xyz}. invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebu. clita kasd gubergren, no sea takimata 

Pino dfgdfgfdgfgfgfgf sdsdsds den dfgdfgfgfgfgfg eines Datensatzes irreversibel \cite[270]{xyz}. invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebu. clita kasd gubergren, no sea takimata 
\end{document}

Result:

enter image description here

This one could be solved using margin=2.57cm but that would cause other linebreaks of the document to fail. Apart from that I would like to obtain my document settings because they come from a unified template. Is there a cleaner solution?

  • 4
    That is simply the line breaking algorithm. You cannot break between "S." and "207", and breaking before the page might leave too much space. Can you provide a full MWE that reproduces the issue (with as few lines of code as possible). – moewe Sep 1 '15 at 15:29
  • Thank you for your comments. It wasn't easy but I finally managed to create an MWE. – hurb Sep 2 '15 at 9:12
  • 1
    Thank you very much for the MWE! Line breaking is a very sensitive and complex issue. Since LaTeX is very clever and tries very hard, sometimes it is just better to re-word sentences or rearrange what you have written a bit. The first try is probably often the microtype package which can help in many (but unfortunately not all) cases - in your MWE it helps. Then you could try \emergencystretch (see here and here) - maybe even only locally.... – moewe Sep 2 '15 at 9:35
  • Thanks a lot @moewe! The microtype package removed all ugly linebreaks but your other suggestions work as well. Can't decide for one solution yet but the problem is fixed. If you like, sum it up in an answer. It might be accepted ;) – hurb Sep 2 '15 at 10:12
  • Done! Note that I had to retract the idea with a negative \penalty in \postnotedelim. The required penalty was so negative, it forced line breaks virtually everywhere, which rendered this approach quite useless, obviously. – moewe Sep 2 '15 at 10:29
1

Line breaks are a very delicate, fragile and complex matter. If you have problems with your line breaking I would suggest trying the following solutions in the order listed here.

The package microtype can often help with line breaks and other micro-typographic features. It cannot help with all problems, the issue in the MWE it is well able to resolve.

\documentclass[parskip=half,12pt]{scrreprt}
\usepackage[a4paper, margin=2.54cm, marginparwidth=2.0cm, footskip=1.0cm]{geometry}
\usepackage{mathptmx}
\usepackage{microtype}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
    @book{xyz,
        title={Iasd},
        author={Kersten, X. and Bjhsdfojgf, A.D. and HBjdsf, J. and Sjkvhds, K.W.},
        year={2013},
    }
\end{filecontents*}
\usepackage[backend=biber, 
style=alphabetic,
]{biblatex}
\addbibresource{\jobname.bib}

\begin{document}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed dm nonumlllllllllllll \cite[270]{xyz}. invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebu. clita kasd gubergren, no sea takimata 

Pino dfgdfgfdgfgfgfgf sdsdsds den dfgdfgfgfgfgfg eines Datensatzes irreversibel \cite[270]{xyz}. invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebu. clita kasd gubergren, no sea takimata 
\end{document}

enter image description here

Then you can reword your sentences or rearrange your text such that the line breaks look fine afterwards.

If microtype cannot help you and you don't want to rearrange your text, you might have to resort to more ad-hoc solutions.

You can allow for additional stretch space via \emergencystretch. You will probably have to experiment with the value, in your MWE

\setlength{\emergencystretch}{2pt}

worked just fine. See also What is the meaning of \fussy, \sloppy, \emergencystretch, \tolerance, \hbadness?, Temporarily increase the limit on space size? and How to use \sloppy for just some references?

\documentclass[parskip=half,12pt]{scrreprt}
\usepackage[a4paper, margin=2.54cm, marginparwidth=2.0cm, footskip=1.0cm]{geometry}
\usepackage{mathptmx}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
    @book{xyz,
        title={Iasd},
        author={Kersten, X. and Bjhsdfojgf, A.D. and HBjdsf, J. and Sjkvhds, K.W.},
        year={2013},
    }
\end{filecontents*}
\usepackage[backend=biber, 
style=alphabetic,
]{biblatex}
\addbibresource{\jobname.bib}    

\setlength{\emergencystretch}{2pt}

\begin{document}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed dm nonumlllllllllllll \cite[270]{xyz}. invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebu. clita kasd gubergren, no sea takimata 

Pino dfgdfgfdgfgfgfgf sdsdsds den dfgdfgfgfgfgfg eines Datensatzes irreversibel \cite[270]{xyz}. invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebu. clita kasd gubergren, no sea takimata 
\end{document}

enter image description here

The higher \emergencystretch can be changed locally with the suggestions in An environment for setting \emergencystretch locally

\newenvironment{emergency}[1]{%
  \par
  \setlength{\emergencystretch}{#1}%
}{%
  \par
}

You then wrap the environment emergency with a suitable length in the argument around the paragraph having breaking troubles.

\documentclass[parskip=half,12pt]{scrreprt}
\usepackage[a4paper, margin=2.54cm, marginparwidth=2.0cm, footskip=1.0cm]{geometry}
\usepackage{mathptmx}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
    @book{xyz,
        title={Iasd},
        author={Kersten, X. and Bjhsdfojgf, A.D. and HBjdsf, J. and Sjkvhds, K.W.},
        year={2013},
    }
\end{filecontents*}
\usepackage[backend=biber, 
style=alphabetic,
]{biblatex}
\addbibresource{\jobname.bib}

\newenvironment{emergency}[1]{%
  \par
  \setlength{\emergencystretch}{#1}%
}{%
  \par
}

\begin{document}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed dm nonumlllllllllllll \cite[270]{xyz}. invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebu. clita kasd gubergren, no sea takimata 

\begin{emergency}{1pt}
Pino dfgdfgfdgfgfgfgf sdsdsds den dfgdfgfgfgfgfg eines Datensatzes irreversibel \cite[270]{xyz}. invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebu. clita kasd gubergren, no sea takimata
\end{emergency}

Pino dfgdfgfdgfgfgfgf sdsdsds den dfgdfgfgfgfgfg eines Datensatzes irreversibel \cite[270]{xyz}. invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebu. clita kasd gubergren, no sea takimata 

Lorem \cite[270]{xyz} ipsum
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.