我有一个简单的逐项列表,如以下 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}
不幸的是,这并没有像预期的那样破坏文本块,如下所示:
我该如何修复此项以使其能够正确换行?
答案1
\underline
不允许换行。
包裹ulem
文本不能隐藏在宏或花括号中。
\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}
包裹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}
答案2
尝试使用url
或breakurl
包。正如文档所述url
:
命令 \url 是一种逐字命令,允许在某些字符或字符组合处换行,接受重新配置,并且通常可以用作另一个命令的参数。(\urldef 命令提供了强大的命令,可在 \url 无法用作参数的情况下使用。)该命令适用于电子邮件地址、超文本链接、目录/路径等,这些内容通常没有空格,因此默认情况下,该软件包会忽略其参数中的空格。但是,软件包选项“允许空格”,这对于空格是文件名常见部分的操作系统很有用。