0
votes

I am writing a latex document with chapters and sections, but sections are indenting like subsections. At the risk of boring you, here is the code. I've tried to include a minimal verifiable example, but I may have missed something.

\chapter{In the begin there was Euclid}

\section{Greatest Common Divisor}

And some things.

\begin{lstlisting}
func GCD(a int32, b int32) int32 {
    var u int32
    var v int32
    var t int32
    var x int32

    if a < 0 && a < -math.MaxInt32 {
        fmt.Println("GCD: integer overflow")
        a = -a
    }
    if b < 0 && b < -math.MaxInt32 {
        fmt.Println("GCD: integer overflow")
        b = -b
    }
    if b == 0 {
        x = a
    } else {
        u = a
        v = b
        for v != 0 {
            t = u % v
            u = v
            v = t
        }
        x = u
    }
    return x
}
\end{lstlisting}

And more.

\section{Section 2}

And some stuff.

\begin{lstlisting}

func XGCD(a int32, b int32) (int32, int32, int32) {
    var u, v, u0, v0, u1, v1, u2, v2, q, r int32
    var aneg, bneg int32

    if a < 0 {
        if a < -math.MaxInt32 {
            fmt.Println("XGCD: integer overflow")
        }
        a = -a
        aneg = 1
    }

    if b < 0 {
        if b < -math.MaxInt32 {
            fmt.Println("XGCD: integer overflow")
        }
        b = -b
        bneg = 1
    }

    u1 = 1
    v1 = 0
    u2 = 0
    v2 = 1
    u = a
    v = b

    for v != 0 {
        q = u / v
        r = u % v
        u = v
        v = r
        u0 = u2
        v0 = v2
        u2 = u1 - q*u2
        v2 = v1 - q*v2
        u1 = u0
        v1 = v0
    }
    if aneg != 0 {
        u1 = -u1
    }
    if bneg != 0 {
        v1 = -v1
    }
    return u, u1, v1
}
\end{lstlisting}

The problem is that the second section always indents too far as if it's a subsection of the first. Here's a picture (the red text was added after taking the screen shot).enter image description here

I'm thinking it has something to do with the page break.

The page is being included in the following document.

\documentclass[a4paper,twoside]{scrbook}
\usepackage{amsmath,amsthm,verbatim,amssymb,amsfonts,amscd, graphicx, listings}
\usepackage{graphics}
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}
\newtheorem{corollary}{Corollary}
\newtheorem{lemma}{Lemma}
\newtheorem{proposition}{Proposition}
\newtheorem*{surfacecor}{Corollary 1}
\newtheorem{conjecture}{Conjecture} 
\newtheorem{question}{Question} 
\theoremstyle{definition}
\newtheorem{definition}{Definition}

\begin{document}
\title{Number Theory and Abstract Algebra for Programmers}
\author{Kilgore Trout}
\frontmatter
\maketitle
\tableofcontents
\mainmatter
\include{introduction}
\include{in_the_beginning_there_was_euclid}
\include{and_then_there_were_groups}

\end{document}

I tried removing all of the packages and to minimize the whole thing, but nothing worked. Is there a problem with lstlisting spanning pages? Did I miss a closing statement somewhere? Why is the page 4 indented so far?

UPDATE: I don't think it's the page break causing the problem. I added a \clearpage before the new section and it was still nested with the previous section.

1

1 Answers

1
votes

This is normal behavior for the Book document type.

Left pages have a supplementary margin on the left while right pages have this supplementary margin on the right. These margins are here for sidenotes. (Folk's like Fermat make important use of these...)

Your second section happens to be on the second page, that explain the margin your seeing.

For more details about the book class margins have a look at this answer.