1

I'm using XeLaTeX and I used the listings package to display some source code. In \lstset I set the tabsize to 4:

\documentclass[a4paper, 11pt]{article}
\usepackage{filecontents}
\begin{filecontents*}{Text.txt}
public static int[] mergeSort(int[] array) {
    if (array.length == 1) {
        return array;
    }
    int[] left = new int[array.length / 2], right = new int[array.length - left.length];
    System.arraycopy(array, 0, left, 0, array.length / 2);
    System.arraycopy(array, left.length, right, 0, right.length);
    left = mergeSort(left);
    right = mergeSort(right);
    return merge(left, right);
}
\end{filecontents*}
\usepackage{listings}
\lstset{
backgroundcolor=\color{lightgray},
basicstyle=\ttfamily\color{darkgray},
keywordstyle=\ttfamily\color{darkgray},
caption=a,
commentstyle=\color{gray}\ttfamily,
showstringspaces=false,
flexiblecolumns=true,
tabsize=4,
showtabs=false,
xleftmargin=0pt,
xrightmargin = 0pt,
label=DescriptiveLabel,
breaklines=true,
breakatwhitespace=true,
language=JAVA
}}
\begin{document}
\lstinputlisting{Text.txt}
\end{document}

However the tabsize when displaying the code is 3. What could be wrong? Thanks for any help.

  • Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – jub0bs Feb 4 '15 at 20:15
  • Well, it's actually part of a package but ok I'll do that – Oliver Borchert Feb 4 '15 at 20:20
  • Good, but give us something that reproduces the problem. At the moment, your example contains no tabs... – jub0bs Feb 4 '15 at 20:26
  • I saved the file with tabs (which filecontents doesn't write and the output shows them regularly). – egreg Feb 4 '15 at 20:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.