考虑以下文本。此处/etc/postgresql/8.4/main/pg_hba.conf
溢出到边距,并且已连字符连接。/var/lib/pgsql/data/pg_hba.conf
也已连字符连接,但未溢出。
所以,我想知道有什么好的通用方法来处理溢出。我以前遇到过这个问题,通常我只是在//
有问题的文本前面加上一个,但这不是一个好的通用解决方案。例如,如果文本发生变化,那么换行可能毫无理由。
我真的很惊讶 LaTeX 不会简单地将文本移到下一行。有没有一些好的通用方法可以说明 - 如果文本超出范围,则不要破坏该文本并将其移到下一行?我查看了其他问题,可能不存在这样的事情,但也许我遗漏了一些东西。
\documentclass{article}
\usepackage{underscore}
% Text layout
\topmargin 0.0cm
\oddsidemargin 0.5cm
\evensidemargin 0.5cm
\textwidth 16cm
\textheight 21cm
\newcommand{\sourcefile}[1]{\texttt{#1}}
\begin{document}
Therefore, the user running init_db.py needs to have sudo
privileges on the machine, or have a database superuser of the same
name as the shell account. In addition, you may need to modify the
PostgreSQL client authentication configuration. This is located in the
file pg_hba.conf. I give basic instructions about the
necessary modifications in this section. For further information about
PostgreSQL client authentication, see
http://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html
With the Debian and Ubuntu default client authentication configuration
located at \sourcefile{/etc/postgresql/8.4/main/pg_hba.conf}, SNPpy
will run without modification. For other Linux distributions, changes
may be necessary.
For example, the client authentication configuration file is located
in Fedora at \sourcefile{/var/lib/pgsql/data/pg_hba.conf} and its
default values are given in Table 1.
\end{document}
答案1
您可以使用这url
:
\usepackage{url}
\newcommand{\sourcefile}{\url}
使用上述内容并应用于\url{}
URL 可得到:
或者,你可以使用`hyperref 包:
\usepackage{hyperref}
\newcommand{\sourcefile}{\url}
并获得可点击的链接:
如果文档仅供在线查看,您也可以使用
\href{http://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html}{auth pg hba conf}
并获取不显示完整 URL 而是您作为第二个参数指定的文本的链接。
正如 egreg 指出的那样,如果您不想在文件上使用可点击链接,则可以使用\path{}
s\sourcefile
并使用\url
web 链接
\usepackage{hyperref}
\newcommand{\sourcefile}{\path}
和包裹url
,你也可以定义不同的宏,每个宏都可以有自己的风格:
\DeclareUrlCommand\email{\urlstyle{rm}}
\DeclareUrlCommand\directory{\urlstyle{tt}}
笔记:
包裹
showframe
用于显示边距。正如 Martin Scharrer 指出的那样,最好使用
\newcommand{\sourcefile}{\path}% Better!!
或者
\let\sourcefile\path% Better!!
代替
\newcommand{\sourcefile}[1]{\path{#1}}% Not so good
这将允许文件名中存在任何特殊字符的情况,因为它们将以逐字模式处理。因此,例如,以下内容可以很好地适用于“更好的”上面的标记定义:
\sourcefile{~/.cshrc} \sourcefile{abc%20def}
答案2
虽然@Peter 的解决方案更好,但如果您不想拆分文件名,您可以使用这个利用的替代方法\sloppy
。
\documentclass{article}
\usepackage{underscore}
% Text layout
\topmargin 0.0cm
\oddsidemargin 0.5cm
\evensidemargin 0.5cm
\textwidth 16cm
\textheight 21cm
\newcommand{\sourcefile}[1]{\texttt{#1}}
\sloppy
\begin{document}
Therefore, the user running init_db.py needs to have sudo
privileges on the machine, or have a database superuser of the same
name as the shell account. In addition, you may need to modify the
PostgreSQL client authentication configuration. This is located in the
file pg_hba.conf. I give basic instructions about the
necessary modifications in this section. For further information about
PostgreSQL client authentication, see
http://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html
With the Debian and Ubuntu default client authentication configuration
located at \sourcefile{/etc/postgresql/8.4/main/pg_hba.conf}, SNPpy
will run without modification. For other Linux distributions, changes
may be necessary.
For example, the client authentication configuration file is located
in Fedora at \sourcefile{/var/lib/pgsql/data/pg_hba.conf} and its
default values are given in Table 1.
\end{document}
但是你必须牺牲 TeX 调整词间间距的强大能力。