\texttt 不会换行

\texttt 不会换行

我用它\texttt来格式化一些文本。如果超出了行宽,我需要将其分成两行。我用过,\justify但并不总是有效。下面的脚本显示了两个示例,一个运行良好,另一个则不行。你能找出为什么\justify在一种情况下不起作用吗?

\documentclass[sigconf]{acmart}
\newcommand*\justify{%
  \fontdimen2\font=0.4em% interword space
  \fontdimen3\font=0.2em% interword stretch
  \fontdimen4\font=0.1em% interword shrink
  \fontdimen7\font=0.1em% extra space
  \hyphenchar\font=`\-% allowing hyphenation
}
\usepackage{lipsum}
\begin{document}
\title{Test}

\author{First Author}
\affiliation{%
  \institution{First University}
  \city{City}
  \state{Country}
}
\email{[email protected]}

\author{Second Author}
\affiliation{%
  \institution{Second University}
  \city{City}
  \state{Country}
}
\email{[email protected]}
\begin{abstract}
Abstract here.
\end{abstract}
\maketitle
\section{Section}
\lipsum

\texttt{\justify{xxxx:xxxx;yyyyyyyyy:yy-yy-yyyy;zzzzzzz:zz-zz-zzzz;uuu-uuuuu:uuuuuu-uuuuuu;aaaaaaaaaaaaaaaa:a;cccccc:c;wwwwww:[email protected]}}

\texttt{\justify{long-text-long-text-long-text-long-text-long-text-long-text-long-text-long-text-long-text-long-text-long-text-long-text-long-text-}}

\end{document}

答案1

在此处输入图片描述

\RequirePackage[hyphens]{url}
\documentclass[sigconf]{acmart}

\usepackage{lipsum}
\begin{document}
\title{Test}

\author{First Author}
\affiliation{%
  \institution{First University}
  \city{City}
  \state{Country}
}
\email{[email protected]}

\author{Second Author}
\affiliation{%
  \institution{Second University}
  \city{City}
  \state{Country}
}
\email{[email protected]}
\begin{abstract}
Abstract here.
\end{abstract}
\maketitle
\section{Section}
\lipsum

\begin{flushleft}

\path|xxxx:xxxx;yyyyyyyyy:yy-yy-yyyy;zzzzzzz:zz-zz-zzzz;uuu-uuuuu:uuuuuu-uuuuuu;aaaaaaaaaaaaaaaa:a;cccccc:c;wwwwww:[email protected]|

\path|long-text-long-text-long-text-long-text-long-text-long-text-long-text-long-text-long-text-long-text-long-text-long-text-long-text-|

\end{flushleft}

\end{document}

相关内容