6

I'm trying to create a documentation listing similar to that used by MSDN. Here was my first attempt at that:

\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}

Which produces:

example output

Of course, this is wrong behavior -- the registry key bit needs to go on it's own, not pushed over to the right on the first line. I tried following the instructions on this question, which left this:

\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}

producing:

example longer output

This is bad because now there's a huge space before the verbatim text. Also, XeTeX decided to complain quite a bit about bad boxes on this one.

I've tried several "massagings" of this -- such as removing the explicit newline after the \hline on Verbatim environments only. That shrinks the space, but not enough -- it still looks like a huge gaping hole.

How would one fix this?

EDIT: In response to the comment:

\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}

produces:

Still spaced

Billy ONeal
  • 10,439

2 Answers2

2

Perhaps there is better method, but it seems that if you eliminate the \\ and include a \vspace{-\baselineskip} before the verbatim environment you get reasonable looking results:

enter image description here

\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} 
Peter Grill
  • 223,288
2

Similar to the solution provided in Control vertical space before and after verbatim environment?, here is a version of your MWE that is properly aligned:

enter image description here

% 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}

Here is a comparable view using inline verbatim (via \verb) to show the corresponding vertical alignment. On the left is a section of the above output, while the code below is added to the right:

enter image description here

\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}
Moriambar
  • 11,466
Werner
  • 603,163
  • I'm confused.. what's the difference in the output? – Billy ONeal Feb 07 '12 at 06:23
  • @BillyONeal: The difference between my output in the first example and that of @ PeterGrill's answer is minimal. However, when you put his and mine next to one another, you'll notice the difference. The reason being that the verbatim environment is set as a list (trivlist), which adds a little space above/at the beginning (see the linked post). There's no difference in the output of the last example even though the left image is created using the verbatim environment, compared to the inline \verb for the right image. – Werner Feb 07 '12 at 06:27
  • Ah, makes sense. (Sorry for being a dullard at such things) – Billy ONeal Feb 07 '12 at 06:33
  • @BillyONeal: More specific to @ PeterGrill's answer: You'll notice that the height from the item label to the first line is smaller in the verbatim items than in the regular items. As I mentioned this may be negligible to most people. – Werner Feb 07 '12 at 06:43
  • Yeah; if I was publishing a book or something then this does look more consistent. Unfortunately it's a lot more code to do per-entry :( – Billy ONeal Feb 07 '12 at 06:55