5

I am writing a paper that involves some code. I set the code using alltt because I like to use \color and that doesn't seem to work in verbatim or listings. But I am having problems with indentation. Usually, it's exactly what is shown. But sometimes not. For instance:

\documentclass{article}
\usepackage{alltt}
\usepackage{color}
\usepackage{float}

\begin{document}
\begin{alltt}
proc template;
 define statgraph fancybox;
 begingraph;
   entrytitle "Box plot w/histogram";
   layout lattice/rows = 2 columns = 1
    order = columnmajor rowweights = (.8 .2);
    columnaxes;
        columnaxis /griddisplay = on;
        columnaxis /label = '' griddisplay = on;
    endcolumnaxes;
      boxplot x = ht y = wt;
      barchart x =  ht y = wt;
    endlayout;
endgraph;
end;
run;
\end{alltt}
\end{document}

the second row that starts with columnaxis is not indented to match the one just above.

I'm running pdflatex on a Windows machine.

8

The issue is cause because you have tabs instead of spaces in some lines (as egreg already thought). See this screenshot with the tabs marked as blue arrows. My editor makes the tabs four spaces long.

Tabs

Because a tab is only a single character it is also just turned into one space and four. It would be possible to make it expand to four spaces but it would be difficult to make it behave like a normal tab, i.e. jump to the next column.

The solution is easy: simply replace the tabs with the right number of spaces.

  • 1
    Further, any good editor can be made to insert 4 (or however many) spaces when you hit TAB, so you can still have the convenience of hitting TAB. – ShreevatsaR Jun 1 '11 at 16:19
  • 1
    @Peter: Feel free to accept it then. – Martin Scharrer Jun 2 '11 at 3:49
4

The only reason I see for the line not to have the shown indentation is that in the input file there's a "TAB" instead of spaces. Watch out for them: just put the cursor at the beginning of the line and use the arrow to move right. You should see a jump: that's the "TAB" which should be changed into a sequence of spaces.

Your Answer

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

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