Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a listings environment in my document with backgroundcolor=\color{grey} to get a nice grey background and mathescape=true for using math symbols. However when using the \vdots command inside a code listing I get a break in my listing, as follows:

\documentclass{book}
\usepackage{color}
\definecolor{grey}{rgb}{0.9,0.9,0.9}
\usepackage{listings}
\lstset{%
language=Lisp,
basicstyle=\small,
backgroundcolor=\color{grey},
mathescape=true}

\begin{document}
\begin{lstlisting}
(let ((<$var_1$> <$exp_1$>)
      (<$var_2$> <$exp_2$>)
      $\vdots$
      (<$var_n$> <$exp_n$>))
   <$body$>))
\end{lstlisting}
\end{document}

Resulting output:

enter image description here

So far it's only \vdots which is doing this (and it happens multiple times so I know it's not a fluke). Is there a fix for this, or maybe would minted work better at this sort of thing? (Although I'd rather not switch if I don't have to.)

share|improve this question
    
Nice question! You could improve the question by providing compilable code with \documentclass and everything. –  Hendrik Vogt Feb 13 '11 at 6:59
    
@Hendrik - Thanks! Ask and ye shall receive. –  Andrew Arnold Feb 13 '11 at 7:09
1  
And suddenly I don't get Undefined color `grey' anymore :-) –  Hendrik Vogt Feb 13 '11 at 7:34
add comment

2 Answers

up vote 4 down vote accepted

The problem seems to be that listings expects a constant line height, and that \vdots just takes up too much vertical space. One fix is to redefine \vdots so that it takes up less vertical space:

\renewcommand\vdots{%
  \vbox{\baselineskip3pt\lineskiplimit0pt\kern1pt\hbox{.}\hbox{.}\hbox{.}\kern-1pt}}

share|improve this answer
    
Looks very nice! Thanks for your help. –  Andrew Arnold Feb 13 '11 at 13:36
add comment
\documentclass{book}
\usepackage{color}
\definecolor{grey}{gray}{0.9}
\usepackage{listings}

\lstset{%
language=Lisp,
basicstyle=\small,
backgroundcolor=\color{grey},
mathescape=true}

\begin{document}
\begin{lstlisting}
(let ((<$var_1$> <$exp_1$>)
      (<$var_2$> <$exp_2$>)
      $\makebox(0,7.5){\vdots}$
      (<$var_n$> <$exp_n$>))
   <$body$>))
\end{lstlisting}
\end{document}
share|improve this answer
1  
This solution eats a bit of the lowest of the three dots. My opinion: Here, a bit of explanation what \makebox does would be much more valuable than the full code. –  Hendrik Vogt Feb 13 '11 at 9:35
    
This doesn't quite work in my document since it shoves the dots to the far left of the page, eating up any indentation. On the other hand, I learned something new about \definecolor! –  Andrew Arnold Feb 13 '11 at 13:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.