Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to break listing to pages in latex?

Tags:

latex

listings

I'm trying to split my listing into several pages, but unfortunately, it doesn't work.

I have read it should work automatically if you set breaklines=true. I can't. Is there another option without creating multiple listings?

    \lstset{numbers=left,
    columns=fullflexible,
    stepnumber=1,
    basicstyle=\footnotesize\ttfamily,
    numberstyle=\color{lineNumberColor}\tiny,
    inputencoding=utf8,
    showtabs=false,
    extendedchars=true,
    showstringspaces=false,
    showspaces=false,
    tabsize=4,
    postbreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\color{pred}\hookrightarrow\space}},
    commentstyle=\slshape\color{commentColor},
    keywordstyle=\color{keywordColor}\bfseries,
    stringstyle=\color{stringColor}\ttfamily,
    breaklines=true,
    breakatwhitespace=true,
}

example

like image 297
N33D Avatar asked Sep 28 '18 07:09

N33D


People also ask

How to insert page break in LATEX?

The \pagebreak command tells LaTeX to break the current page at the point of the command. With the optional argument, number, you can convert the \pagebreak command from a demand to a request. The number must be a number from 0 to 4. The higher the number, the more insistent the request is.

What are listings LATEX?

The listings package is a source code printer for LATEX. You can typeset stand alone files as well as listings with an environment similar to verbatim as well as you can print code snippets using a command similar to \verb.


1 Answers

Assuming you want to specify where a new page starts in your listing, you can do that using the escapeinside option. The breaklines option ensures line wraps to fit the page horizontally when set to true.

By specifying escapeinside=`` , you can escape the listings context between two backtics (`). To break a line you can insert \newpage between the backticks like so:

\begin{lstlisting}[escapeinside=``]
    page 1

    `\newpage`

    page 2
\end{lstlisting}

The listing should be split up into two pages with page 1 written on one page and page 2 written on the next one.

like image 85
upe Avatar answered Sep 29 '22 01:09

upe