0

I have a simple itemized list like the following MWE:

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{lmodern}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{lipsum}
\begin{document}
\begin{itemize}
\item \href{http://google.com}{[ID1]: \underline{\lipsum[1]}}
\end{itemize}
\end{document}

This unfortunately doesn't break the block of text as expected, as shown below:

enter image description here

How can I fix this item so it will line break properly?

3
  • 2
    \underline does not support linebreaks. If you really really need linebreaks (please think again), them the soul package (AFAIR) have an alternative, that does support linebreaks.
    – daleif
    Aug 20 '15 at 11:38
  • @salimbou It is not (yet) related, because \underline already prevents the line breaks independent from the link. If dvips is used (the question does not mention it), this would be another problem on top of the non-breakable \underline, which prevents line breaks. Then it would be related (but not a duplicate). Aug 20 '15 at 12:03
5

\underline does not allow line breaks.

Package ulem

The text must not hidden in a macro or in curly braces.

\documentclass[10pt,a4paper]{article}
\usepackage{hyperref}
\usepackage{lmodern}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage[normalem]{ulem}

\newcommand\lipsumi{Lorem ipsum dolor sit amet, consectetuer
  adipiscing elit. Ut purus elit, vestibulum ut, placerat ac,
  adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu
  libero, nonummy eget, consectetuer id, vulputate a, magna. Donec
  vehicula augue eu neque. Pellentesque habitant morbi tristique
  senectus et netus et malesuada fames ac turpis egestas. Mauris ut
  leo. Cras viverra metus rhoncus sem. Nulla et lectus vestibulum urna
  fringilla ultrices.  Phasellus eu tellus sit amet tortor gravida
  placerat. Integer sapien est, iaculis in, pretium quis, viverra ac,
  nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus.
  Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla.
  Curabitur auctor semper nulla. Donec varius orci eget risus. Duis
  nibh mi, congue eu, accumsan eleifend, sagittis quis, diam. Duis
  eget orci sit amet orci dignissim rutrum.}

\begin{document}
\begin{itemize}
\item \href{https://google.com/}{[ID1]: %
  \expandafter\uline\expandafter{\lipsumi}}
\end{itemize}
\end{document}

Result ulem

Package soul

\documentclass[10pt,a4paper]{article}
\usepackage{hyperref}
\usepackage{lmodern}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{soul}

\newcommand\lipsumi{Lorem ipsum dolor sit amet, consectetuer
  adipiscing elit. Ut purus elit, vestibulum ut, placerat ac,
  adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu
  libero, nonummy eget, consectetuer id, vulputate a, magna. Donec
  vehicula augue eu neque. Pellentesque habitant morbi tristique
  senectus et netus et malesuada fames ac turpis egestas. Mauris ut
  leo. Cras viverra metus rhoncus sem. Nulla et lectus vestibulum urna
  fringilla ultrices.  Phasellus eu tellus sit amet tortor gravida
  placerat. Integer sapien est, iaculis in, pretium quis, viverra ac,
  nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus.
  Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla.
  Curabitur auctor semper nulla. Donec varius orci eget risus. Duis
  nibh mi, congue eu, accumsan eleifend, sagittis quis, diam. Duis
  eget orci sit amet orci dignissim rutrum.}

\begin{document}
\begin{itemize}
\item \href{https://google.com/}{[ID1]: %
  \expandafter\ul\expandafter{\lipsumi}}
\end{itemize}
\end{document}

Result soul

1

Try using the url or breakurl packages. As documentation for url says:

The com­mand \url is a form of ver­ba­tim com­mand that al­lows line­breaks at cer­tain char­ac­ters or com­bi­na­tions of char­ac­ters, ac­cepts re­con­fig­u­ra­tion, and can usu­ally be used in the ar­gu­ment to an­other com­mand. (The \urldef com­mand pro­vides ro­bust com­mands that serve in cases when \url doesn't work in an ar­gu­ment.) The com­mand is in­tended for email ad­dresses, hy­per­text links, di­rec­to­ries/paths, etc., which nor­mally have no spaces, so by de­fault the pack­age ig­nores spaces in its ar­gu­ment. How­ever, a pack­age op­tion “al­lows spaces”, which is use­ful for op­er­at­ing sys­tems where spaces are a com­mon part of file names.

https://www.ctan.org/pkg/url?lang=en

https://www.ctan.org/pkg/breakurl?lang=en

1
  • 1
    I do not think this is the problem. \underline does not support linebreaks
    – daleif
    Aug 20 '15 at 11:37

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.