处理没有连字符的长单词(即文件名)

处理没有连字符的长单词(即文件名)

我想知道对于没有音节的长单词最好的方法是什么,因此在这种情况下连字符是错误的/不好的。

就我而言,我有一个很长的文件名,我想将其放在一行中而不使用连字符(因为这基本上会使它显示“错误”的文件名)

这是我的简化示例:

\documentclass{article}
\begin{document}

Lorem ipsum dolor sit amet, consectetuer 
adipiscing elit. Ut purus elit, vestibulum 
ut, placerat ac, adipiscing vitae, felis 
\texttt{my\_realy\_super\_long\_file\_name.ext} 
Curabitur dictum gravida mauris. Nam arcu 
libero, nonummy eget, consectetuer id, vulputate 
a, magna. 

\end{document}

这使我的“文件名”超出了边缘: 超出利润率

\linebreak当然,一种方法是在名称前面使用,这会在文件名之前的行上拉长间距(在我看来这不是很好):磅

可能对此没有一种黄金方法,但我想在这里听听一些关于此类事情的意见/最佳实践。

答案1

有几种可能性

在此处输入图片描述

\documentclass{article}
\begin{document}

Lorem ipsum dolor sit amet, consectetuer 
adipiscing elit. Ut purus elit, vestibulum 
ut, placerat ac, adipiscing vitae, felis 
\texttt{my\_realy\_super\_long\_file\_name.ext} 
Curabitur dictum gravida mauris. Nam arcu 
libero, nonummy eget, consectetuer id, vulputate 
a, magna. 


\begin{sloppypar}
Lorem ipsum dolor sit amet, consectetuer 
adipiscing elit. Ut purus elit, vestibulum 
ut, placerat ac, adipiscing vitae, felis 
\texttt{my\_realy\_super\_long\_file\_name.ext} 
Curabitur dictum gravida mauris. Nam arcu 
libero, nonummy eget, consectetuer id, vulputate 
a, magna. 
\end{sloppypar}

\begin{flushleft}
Lorem ipsum dolor sit amet, consectetuer 
adipiscing elit. Ut purus elit, vestibulum 
ut, placerat ac, adipiscing vitae, felis 
\texttt{my\_realy\_super\_long\_file\_name.ext} 
Curabitur dictum gravida mauris. Nam arcu 
libero, nonummy eget, consectetuer id, vulputate 
a, magna. 
\end{flushleft}

Lorem ipsum dolor sit amet, consectetuer 
adipiscing elit. Ut purus elit, vestibulum 
ut, placerat ac, adipiscing vitae, felis 
\texttt{%
\def\_{\hspace{0pt plus 2pt}\textunderscore\nolinebreak[2]\hspace{0pt plus 2pt}}%
my\_realy\_super\_long\_file\_name.ext} 
Curabitur dictum gravida mauris. Nam arcu 
libero, nonummy eget, consectetuer id, vulputate 
a, magna. 

\end{document}

答案2

其他解决方案:使用urlseqsplit包。演示:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{url, seqsplit, xcolor}

\begin{document}

Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Ut purus elit, vestibulum
ut, placerat ac, adipiscing vitae, felis
%\texttt{my\_realy\_super\_long\_file\_name.ext}
\textcolor{red}{\url{my_realy_super_long_file_name.ext}}
Curabitur dictum gravida mauris. Nam arcu
libero, nonummy eget, consectetuer id, vulputate
a, magna.
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. \textcolor{cyan}{\seqsplit{my\_realy\_super\_long\_file\_name.ext}} 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.

\end{document} 

在此处输入图片描述

相关内容