Jak řešit zalomení URL s BibTeX a balíčkem Hyperref (LaTeX návod)
If you’ve ever written a LaTeX document with long URLs in your bibliography, you might have encountered formatting issues, especially when using the BibTeX bibliography manager along with the hyperref package. Long URLs can cause lines to overflow the margins or disrupt your document’s layout. In this post, we’ll show you how to properly insert a linebreak in URL with BibTeX and hyperref package—the right way.
Why URLs Cause Problems in LaTeX
LaTeX is a typesetting system that prioritizes aesthetic layout. By default, it doesn’t know how to break long URLs across lines unless told explicitly. When using the hyperref
package, this can lead to overfull lines in your bibliography section, especially if your BibTeX entries contain lengthy links.
The Role of the hyperref
Package
The hyperref
package turns references, citations, and URLs into clickable links. It also provides tools to manage URL formatting and line-breaking. But to make it behave well with BibTeX, we need to adjust a few things.
Solution: Linebreak in URL with BibTeX and Hyperref Package
Here’s a step-by-step approach:
✅ Step 1: Load Required Packages
In the preamble of your .tex
document, load the following packages:
\usepackage{hyperref}\usepackage{url} % Often loaded automatically by hyperref, but good to be explicit
The url
package allows for intelligent line-breaking in URLs. hyperref
builds upon it to make links clickable.
✅ Step 2: Configure hyperref
for Better Line Breaking
Add this configuration to your preamble:
\hypersetup{ breaklinks=true, colorlinks=true, urlcolor=blue}
This tells LaTeX to allow links (including URLs) to break across lines when necessary.
✅ Step 3: Format URLs Properly in Your BibTeX File
In your .bib
file, make sure you use the \url{}
command inside the url
field:
@online{example2025, author = {John Doe}, title = {Handling Long URLs in LaTeX}, year = {2025}, url = {\url{https://www.example.com/very/long/url/that/needs/to/break}}, note = {Accessed: 2025-05-04}}
The \url{}
command ensures that LaTeX treats the contents as a URL, applying intelligent line-breaking behavior.
✅ Step 4: Optional Tweaks for Better Results
If you still see layout issues, try adding:
\sloppy
just before your bibliography. This gives LaTeX more flexibility in adjusting line breaks, especially with long, unbreakable strings like URLs.
Streamline Your Reference Management with CiteDrive
Managing BibTeX files by hand can be error-prone—especially when dealing with long URLs or collaborative projects. CiteDrive makes it easy to create, organize, and maintain your BibTeX libraries entirely online. You can connect your CiteDrive project directly to Overleaf and have your bibliography update automatically as you work.
CiteDrive handles complex references—including those with long URLs—while keeping your .bib
file clean, synced, and versioned. It’s designed specifically for LaTeX users who want to spend less time fixing citation issues and more time writing.
Summary
Adding a linebreak in URL with BibTeX and hyperref package is simple once you know the right tools. To recap:
- Use
\url{}
in your BibTeX entries. - Load
hyperref
and configure it to break links. - Use
\sloppy
if needed to avoid overfull boxes. - Let tools like CiteDrive manage your BibTeX entries with less hassle.