# add vdots to a listing without breaking the box

I have a problem when I try to add \vdots in an escaped string inside of a listing environment. The box is cut. How can I avoid the break of the box?

The code is this:

\lstset{language=[Sharp]C,,basicstyle=\footnotesize, showspaces=false,showtabs=false,,breaklines=true,showstringspaces=false,breakatwhitespace=true,frame=trBL, escapeinside={(*@}{@*)}}
\begin{lstlisting}
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = doc.Descendants("dos").Single().Value.Replace("\n","\r\n");
int val = textBox1.Lines.Count();
(*@{\center\vdots}@*)
XmlDocument doc2 = new XmlDocument();
textBox2.Text = doc2.GetElementsByTagName("dos")[0].InnerText;
}
\end{lstlisting}

-
Could you please point out how this differs from your last question Align normal text inside a listing. I have difficulties seeing the difference. –  Martin Scharrer May 15 '11 at 14:41
@MartinScharrer they differs in that they are completely different questions, :D. Using similar code snippet do not imply that the questions are the same. –  mjsr May 15 '11 at 15:01
@voodoomsr: Both questions are about how to get \vdots in a listing and could easily asked as one question. Some other things: Please always add a minimal working example (MWE) that illustrates your problem, not just a code fragment. Also please capitalize your sentences and the title. Thank you. –  Martin Scharrer May 15 '11 at 15:07
@voodoomsr: As said, both could be asked as one question, but if you want to split them into two than it is also OK. People like to compile your code and their solutions. If you don't add the surrounding code EVERYONE which wants to help you has to do that which is the true overhead. Also often (but not here) issues are caused by different seemly unrelated packages. Without seeing the full code it is often very hard to help people. –  Martin Scharrer May 15 '11 at 15:29
@MartinScharrer point taken. In my following questions i'm going to add that lines to avoid people get confuse in package's uses. –  mjsr May 15 '11 at 16:39
show 1 more comment

You can use \raisebox with its two optional arguments to set the official height and depth to zero to avoid the extra vertical spacing which rips the frame open. You can also adjust the vertical position to make the dots be appear vertical centered as well. The horizontal centering can be done using \centerline (or with \hfill <code> \hfill\null):

\documentclass{article}
\usepackage{listings}
\usepackage{mathdots}

\begin{document}
\lstset{language=[Sharp]C,,basicstyle=\footnotesize, showspaces=false,showtabs=false,,breaklines=true,showstringspaces=false,breakatwhitespace=true,frame=trBL, escapeinside={(*@}{@*)}}
\begin{lstlisting}
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = doc.Descendants("dos").Single().Value.Replace("\n","\r\n");
int val = textBox1.Lines.Count();
(*@\centerline{\raisebox{-1pt}[0pt][0pt]{$\vdots$}}@*)
XmlDocument doc2 = new XmlDocument();
textBox2.Text = doc2.GetElementsByTagName("dos")[0].InnerText;
}
\end{lstlisting}
\end{document}


(I removed the spaces in front of the listing because the will push the code to much to the right)

-
thank you very much, that is exactly what i need, :D –  mjsr May 15 '11 at 16:35

Do not use \center, it's wrongly used.

You can just escape the symbol, and be sure it is not too tall.

\documentclass{article}
\usepackage{listings}
\usepackage{mathdots}

\begin{document}
\lstset{language=[Sharp]C,,basicstyle=\footnotesize, showspaces=false,showtabs=false,,breaklines=true,showstringspaces=false,breakatwhitespace=true,frame=trBL, escapeinside={(*@}{@*)}}
\begin{lstlisting}
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = doc.Descendants("dos").Single().Value.Replace("\n","\r\n");
int val = textBox1.Lines.Count();
(*@\makebox[\linewidth][c]{$\smash{\vdots}$}@*)
XmlDocument doc2 = new XmlDocument();
textBox2.Text = doc2.GetElementsByTagName("dos")[0].InnerText;
}
\end{lstlisting}


-
thanks @LeoLiu that is almost what i need, but it is not centered. Is there a way to put that dots in the middle? –  mjsr May 15 '11 at 15:11
@voodoomsr: Martin's solution is OK. There're also some other solutions, I updated the answer to give another valid solution. –  Leo Liu May 15 '11 at 16:25
(*@{\hspace*{3cm}\vdots}@*)