# listings package - including textfile - tabstops wrong [closed]

In MikTex with \usepackage{listings}, when including a textfile into a pdf-document using

\lstinputlisting[]{textfile.xt}


then ocassionally, the display of the tabstops in the created pdf-file doesn't match the display of the tabstops in the original textfile (when opened with an editor such as notepad).

This looks rather ugly. What can be done about it?

PS: I don't know how to upload pictures here, otherwhise I would append an example to make it clearer.

-

## closed as unclear what you're asking by Jubobs, Speravir, ChrisS, Jesse, cmhughesJan 16 at 5:21

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

You can add a picture just providing a link to it with the "link" button. Any user with enough privileges will be able to set the image to visible. However also a minimal example would be better. –  egreg Oct 6 '11 at 12:32
I was hoping this would be a known problem. Also, with the link button I can just provide a link, I cannot upload an image. –  Ben Oct 6 '11 at 12:45
@Ben: Add the image in the regular way (by clicking on the image button/Ctrl+G). This is still possibly regardless of your reputation. However, with low reputation, instead of leaving things as-is, just paste the image URL (at the bottom of your post after uploading) and nothing else. –  Werner Oct 6 '11 at 14:16

I think you have a problem with the standard interpretation of the tabsize for tabulators. You can redefine the size of them with tabsize=X, where X is the number of empty spaces. Per default this number is 8 (which seems too long for some textformats).

\lstset{tabsize=2}
\begin{lstlisting}
...
\end{lstlisting}


Source: Chapter "2.5 Special Characters" Listings.pdf

Tabulators You might get unexpected output if your sources contain tabulators. The package assumes tabulator stops at columns 9, 17, 25, 33, and so on. This is predefined via tabsize=8. If you change the eight to the number n, you will get tabulator stops at columns n + 1, 2n + 1, 3n + 1, and so on.

-
Thank you, using tabsize (in combination with adding a few whitespaces manually into the textfile) solved the problem at hand. It is uncomfortable though, since I'll probably have to work out the right tabsize manually for every file + I still don't understand why it can't just display it as I see it in notepad. –  Ben Oct 6 '11 at 14:24
Why does it assume tabulator stops at certain positions, rather than just putting them where I put the tab characters in my textfile? Is there a way to overwrite this default behaviour such that it puts the tabstops where they are in my file? –  Ben Oct 6 '11 at 14:26
It depends on your Editor. Sometimes you can choose between tabulator or just put an predefined amount of empty space in case of an desired tabulator. Last one is more definite for same view in Latex. If you still wanna use tabulators, you need to take care of coding conventions. Usually it should then look the same as in your Editor (except that the tabulator size is defined too long). –  Markus G. Oct 6 '11 at 18:33