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 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)
        {
            XDocument doc = XDocument.Load("XMLFile1.xml");
            textBox1.Text = doc.Descendants("dos").Single().Value.Replace("\n","\r\n");
            int val = textBox1.Lines.Count();
            (*@{\center\vdots}@*)
            XmlDocument doc2 = new XmlDocument();
            doc2.Load("XMLFile1.xml");
            textBox2.Text = doc2.GetElementsByTagName("dos")[0].InnerText;
        }
\end{lstlisting}
share|improve this question
3  
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
1  
@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
3  
@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
1  
@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

3 Answers 3

up vote 5 down vote accepted

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)
{
    XDocument doc = XDocument.Load("XMLFile1.xml");
    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();
    doc2.Load("XMLFile1.xml");
    textBox2.Text = doc2.GetElementsByTagName("dos")[0].InnerText;
}
\end{lstlisting}
\end{document}

Result

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

share|improve this answer
    
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)
        {
            XDocument doc = XDocument.Load("XMLFile1.xml");
            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();
            doc2.Load("XMLFile1.xml");
            textBox2.Text = doc2.GetElementsByTagName("dos")[0].InnerText;
        }
\end{lstlisting}

enter image description here

share|improve this answer
    
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

use it this way:

(*@{\hspace*{3cm}\vdots}@*)
share|improve this answer
    
that sentence also break the box –  mjsr May 15 '11 at 15:07

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.