I'd like to have each of my sections, subsections, etc indented similar to how code is normally nested:

int func() {
     if (x) {
        do this stuff  
     // more code here 

I'm not trying to format code, I just visually really like using indentation to understand where a section ends. What's the best way to implement this? I've tried using adjustwidth but it won't support nested subsections. I'd like to stay away from nested \items because I'd like all the support that accompanies sectioning (table of contents, etc).


This is a very quick solution, and has a number of various limitations (especially when you start thinking about lists and different justification modes (centering, etc.)). But it may be enough to get you started. The trick is to adjust \leftskip, which is the glue inserted before each line of a paragraph.

In the code attached, you can always re-do the \setindents command if necessary if the indentation is messed up by something else.











If necessary, you could write something like


and so on to get the behaviour you're after without changing your current text.

A totally different approach might be something like the framed package, but then you lose the ability to have floats (and again, nesting might be tricky).

There's no real reason why adjustwidth from changepage couldn't nest. I've added it to the issue tracker.

These sorts of things are all rather tricky in regular LaTeX. (I'm hoping the new galley in LaTeX3 makes it trivial.)

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.