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 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.

share|improve this question
    
Are you using spaces or tabs? –  egreg May 31 '11 at 17:28
    
I get both columnaxis /... lines with the same indention, like in your post. Image: i.stack.imgur.com/HOc5W.png –  Martin Scharrer May 31 '11 at 18:07
    
Please add a full minimal working example (MWE) that produces this incorrect indention, not just the alltt environment. Thanks. –  Martin Scharrer May 31 '11 at 18:08
    
Hi Martin, I modified it to be a full example. –  Peter Flom May 31 '11 at 19:02

2 Answers 2

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.

share|improve this answer
    
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
    
Thanks! That worked –  Peter Flom Jun 2 '11 at 0:27
1  
@Peter: Feel free to accept it then. –  Martin Scharrer Jun 2 '11 at 3:49

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.

share|improve this answer

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.