几个名称参考和页边距

几个名称参考和页边距

我已经为此苦苦挣扎了nameref一段时间。我试图让他们尊重一行上的可用空间,但我似乎找不到办法。

LaTeX 代码如下:

\documentclass{report}
%\documentclass{scrreprt}
\usepackage[inner=3.5cm,outer=2.5cm,top=2.5cm,bottom=2.5cm,pdftex]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[pdftex]{hyperref}

\hypersetup{
    colorlinks = true
}

\overfullrule=15pt % debug

\begin{document}

\chapter{Chapter name}

\section{Section name}

\subsection{XML\_DOM\_NodeFirstSonGet}\label{XMLDOMNodeFirstSonGet}
\subsection{XML\_DOM\_NodeSonsCount}\label{XMLDOMNodeSonsCount}
\subsection{XML\_DOM\_NodeSonsGet}\label{XMLDOMNodeSonsGet}
\subsection{XML\_DOM\_NodeSonsNodesCount}\label{XMLDOMNodeSonsNodesCount}
\subsection{XML\_DOM\_NodeSonsNodesCount}\label{XMLDOMNodeSonsNodesGet}

Normal text:\\\newline
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse\

See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsGet}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}.\
See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}.\

See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}, \nameref{XMLDOMNodeFirstSonGet}.
\end{document}

生成的 PDF 如下所示:

在此处输入图片描述

如您所见,包含\namerefs 的第二行和第三行超出了范围,并且不会像普通文本那样遵守行宽。

结果甚至更糟,\documentclass{scrreprt}因为它们都太满并且被页面限制裁剪了:

在此处输入图片描述

由于我不知道将显示的字符串的长度,因此我无法任意强制换行。

令我震惊的是,我没有找到有关此行为的任何信息。有办法解决这个问题吗?

答案1

包含以下内容的段落结构\nameref是“糟糕的”,因为 TeX 无法在未知的“单词”中强制换行。作为一种可能的修正,并看看如果 TeX 不太在意让事情看起来漂亮,它会看起来有多糟糕,在段落前添加\sloppypar(或至少将其范围限制在受影响段落周围的组中{... ) 。替代方案包括使用或可能使用可断开的下划线(或两者的组合):}\nameref\raggedright

在此处输入图片描述

在此处输入图片描述

在此处输入图片描述

在此处输入图片描述

这是一个完整的例子:

\documentclass{report}
%\documentclass{scrreprt}
\usepackage[inner=3.5cm,outer=2.5cm,top=1cm,bottom=1cm]{geometry}
\usepackage{lmodern}
\usepackage{hyperref}

\hypersetup{
    colorlinks = true
}

\overfullrule=15pt % debug

\begin{document}

\chapter{Chapter name}

\section{Section name}

\subsection{XML\textunderscore DOM\textunderscore NodeFirstSonGet}\label{XMLDOMNodeFirstSonGet}
\subsection{XML\textunderscore DOM\textunderscore NodeSonsCount}\label{XMLDOMNodeSonsCount}
\subsection{XML\textunderscore DOM\textunderscore NodeSonsGet}\label{XMLDOMNodeSonsGet}
\subsection{XML\textunderscore DOM\textunderscore NodeSonsNodesCount}\label{XMLDOMNodeSonsNodesCount}
\subsection{XML\textunderscore DOM\textunderscore NodeSonsNodesCount}\label{XMLDOMNodeSonsNodesGet}

Normal text:

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse

Using \verb|\sloppypar|:

{\sloppypar
See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsGet}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}.

See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}.

See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}, \nameref{XMLDOMNodeFirstSonGet}.
}

\bigskip

Using \verb|\raggedright|:

{\raggedright
See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsGet}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}.

See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}.

See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}, \nameref{XMLDOMNodeFirstSonGet}.
}

\bigskip

Different \verb|\textunderscore|:

{\let\oldtextunderscore\textunderscore%
\renewcommand{\textunderscore}{\oldtextunderscore\hspace{0pt}}%
See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsGet}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}.

See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}.

See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}, \nameref{XMLDOMNodeFirstSonGet}.
}

Different \verb|\textunderscore| + \verb|\sloppypar|:

{\let\oldtextunderscore\textunderscore\sloppypar%
\renewcommand{\textunderscore}{\oldtextunderscore\hspace{0pt}}%
See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsGet}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}.

See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}.

See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}, \nameref{XMLDOMNodeFirstSonGet}.
}

\end{document}

相关内容