# How to avoid linebreak at http: in url

I have a long url that gets wrapped at http: in my layout (using beamer).

This is the latex-code:

\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{url}

\begin{document}

\begin{frame}
\frametitle{Weiterführende Informationen}
\begin{itemize}
\item \url{https://docs.oracle.com/javase/tutorial/collections/}
\end{itemize}
\end{frame}

\end{document}


And this is the result:

I just want it to break at any of the / of the path but explicitly not after http:// (i.e. also not after the / of the protocol)

• May you try \usepackage{url} in your preambel? I know that this works at least for citations. – SeRe May 7 '16 at 10:57
• @SeRe have you read my question? The issue is not about the \url command not working. Its about the line-breakage inside that command. – ohcibi May 7 '16 at 10:58
• Oh sorry, I was to fast :D So I tried it now and with changing the font size, it is in one line. Is this a possible solution for you? \usepackage{url} % ... \begin{document} % ... \begin{frame} \frametitle{Weiterführende Informationen} \begin{itemize} \item \small\url{https://docs.oracle.com/javase/tutorial/collections/} \end{itemize} \end{frame} %... \end{document} – SeRe May 7 '16 at 11:05
• Of course not! The question was about how to avoid linebreaks. – ohcibi May 7 '16 at 11:07
• Reducing font size is one way to avoid line breaks. However, you can enter a \mbox{} surrounding your \urlcommand. But then it will break befor the URL and you get your item above the URL. I solved it like this now: \documentclass{beamer} \usepackage{pifont} \usepackage{url} % ... \begin{document} % ... \begin{frame} \frametitle{Weiterführende Informationen} \mbox{\ding{226} \url{https://docs.oracle.com/javase/tutorial/collections/}} \end{frame} %... \end{document} – SeRe May 7 '16 at 11:20

## 1 Answer

You could --locally or generally -- add the colon to the nobreak list:

\documentclass{beamer}
\usepackage{etoolbox}

\begin{document}

\begin{frame}
\frametitle{Weiterführende Informationen}
\begin{itemize}\appto\UrlNoBreaks{\do\:}%
\item \url{https://docs.oracle.com/javase/tutorial/collections/}
\end{itemize}
\end{frame}

\end{document}


• I don't know if this is really the "right" solution but it enables me to explicitly control the non-breakage (or even the breakage with \UrlBreaks) in urls, which Is why I accepted this. – ohcibi May 7 '16 at 11:19
• Could you explain why you usepackaged etoolbox? I've tried it without that and it still works? – ohcibi May 7 '16 at 11:23
• When I remove etoolbox in my example I get an error that \appto is not defined. – Ulrike Fischer May 7 '16 at 12:47
• Ah ok. I guess it is included by the beamer class then. – ohcibi May 7 '16 at 13:02
• I'm using the beamer class in my example and it doesn't load etoolbox. – Ulrike Fischer May 7 '16 at 13:18