我如何修复逐字逐句导致描述列表环境中出现额外换行符的问题?

我如何修复逐字逐句导致描述列表环境中出现额外换行符的问题?

我正在尝试创建一个类似于微软。这是我第一次尝试:

\subsubsection{User Default Page URL}
\begin{description}
\item[Rationale] This is the default page displayed to a user when
(s)he opens a new window or tab in Microsoft's Internet Explorer browser.
\item[Data Sources] \begin{verbatim}
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer]
"Default_Page_URL"="${url}"
\end{verbatim}
\item[Log Format] \begin{verbatim} 
uDefaultPageUrl=${url}
\end{verbatim}
\item[Description] The variable \var{url} is escaped using the URL
escaping scheme defined in \ref{urlescape}.
\end{description}

其结果为:

示例输出

当然,这是错误的行为——注册表项位需要单独放置,而不是在第一行的右侧推移。我尝试按照这个问题,结果如下:

\subsubsection{User Default Page URL}
\begin{description}
\item[Rationale] \hfill \\ This is the default page displayed to a user when
(s)he opens a new window or tab in Microsoft's Internet Explorer browser.
\item[Data Sources] \hfill \\ \begin{verbatim}
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer]
"Default_Page_URL"="${url}"
\end{verbatim}
\item[Log Format] \hfill \\ \begin{verbatim} 
uDefaultPageUrl=${url}
\end{verbatim}
\item[Description] \hfill \\ The variable \var{url} is escaped using the URL
escaping scheme defined in \ref{urlescape}.
\end{description}

生产:

示例更长的输出

这很糟糕,因为现在逐字文本前有一个巨大的空格。此外,XeTeX 决定对这个糟糕的框提出很多抱怨。

我尝试过几次“调整”方法,比如\hline仅在 Verbatim 环境中删除后面的显式换行符。这可以缩小空间,但效果不够好,它看起来仍然像一个巨大的空洞。

如何修复这个问题?

编辑:回应评论:

\subsubsection{User Default Page URL}

\begin{description}
\item[Rationale] This is the default page displayed to a user when
(s)he opens a new window or tab in Microsoft's Internet Explorer browser.
\item[Data Sources] \hfill

\begin{verbatim}
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer]
"Default_Page_URL"="${url}"
\end{verbatim}
\item[Log Format]
\begin{verbatim} 
uDefaultPageUrl=${url}
\end{verbatim}
\item[Description] The variable \var{url} is escaped using the URL
escaping scheme defined in \ref{urlescape}.

\end{description}

生成:

仍有间隔

答案1

也许有更好的方法,但似乎如果你消除并在环境之前\\包含一个,你会得到合理的结果:\vspace{-\baselineskip}verbatim

在此处输入图片描述

\documentclass{article}
\newcommand*{\var}[1]{\texttt{#1}}%  Macro definition not provided in MWE

\begin{document}
\subsubsection{User Default Page URL}

\begin{description}
\item[Rationale] \hfill 

This is the default page displayed to a user when
(s)he opens a new window or tab in Microsoft's Internet Explorer browser.
\item[Data Sources] \hfill\vspace{-\baselineskip}

\begin{verbatim}
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer]
"Default_Page_URL"="${url}"
\end{verbatim}
\item[Log Format] \hfill \vspace{-\baselineskip}
%
\begin{verbatim} 
uDefaultPageUrl=${url}
\end{verbatim}
\item[Description] \hfill 

The variable \var{url} is escaped using the URL
escaping scheme defined in \ref{urlescape}.
\end{description}
\end{document} 

答案2

与提供的解决方案类似控制逐字环境前后的垂直空间?,这是正确对齐的 MWE 版本:

在此处输入图片描述

% Reference: https://tex.stackexchange.com/questions/43638/
% Related: https://tex.stackexchange.com/questions/43331/
\documentclass{article}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
\preto{\@verbatim}{\topsep=0pt \partopsep=0pt}
\makeatother
\newcommand{\var}[1]{\bgroup\ttfamily\string$\string{#1\string}\egroup}%$
\begin{document}

\setcounter{section}{3}\setcounter{subsection}{2}% Just for this example
\subsubsection{User Default Page URL}

\begin{description}
\item[Rationale] This is the default page displayed to a user when
(s)he opens a new window or tab in Microsoft's Internet Explorer browser.
\item[Data Sources] \hspace*{\fill} \\[-\dimexpr\baselineskip+\parskip\relax]
\begin{verbatim}
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer]
"Default_Page_URL"="${url}"
\end{verbatim}
\item[Log Format] \hspace*{\fill} \\[-\dimexpr\baselineskip+\parskip\relax]
\begin{verbatim} 
uDefaultPageUrl=${url}
\end{verbatim}
\item[Description] The variable \var{url} is escaped using the URL
escaping scheme defined in~3.2.1.

\end{description}
\end{document}

以下是使用内联逐字(via)显示相应垂直对齐的比较视图\verb。左侧是上述输出的一部分,而以下代码添加到右侧:

在此处输入图片描述

\documentclass{article}
\newcommand{\var}[1]{\bgroup\ttfamily\string$\string{#1\string}\egroup}%$
\begin{document}

\setcounter{section}{3}\setcounter{subsection}{2}% Just for this example
\subsubsection{User Default Page URL}

\begin{description}
\item[Rationale] This is the default page displayed to a user when
(s)he opens a new window or tab in Microsoft's Internet Explorer browser.
\item[Data Sources] \hspace*{\fill} \\
\verb|[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer]| \\
\verb|"Default_Page_URL"="${url}"|
\item[Log Format] \hspace*{\fill} \\
\verb|uDefaultPageUrl=${url}|
\item[Description] The variable \var{url} is escaped using the URL
escaping scheme defined in~3.2.1.

\end{description}
\end{document}

相关内容