Text FormattingHelp with lstlisting

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
mario595
Posts: 2
Joined: Fri Jun 12, 2009 1:16 pm

Help with lstlisting

Post by mario595 »

I need help with lstlisting package.I would like to know how can I insert a new page jump in a lstlisting environment. I want to know a "command" like \newpage that I can use within a lstlisting environment.
Thanks!! :D

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

Help with lstlisting

Post by localghost »

I'm not sure whether I understand you right. I can't see any problems in having page breaks within listings. Consider this example.

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{babel}
\usepackage[includeheadfoot,margin=2cm]{geometry}
\usepackage[svgnames]{xcolor}
\usepackage{listings}
\usepackage{bera}

\parindent0em

\lstset{%
%  language=[LaTeX]TeX,
  numbers=none,
  tabsize=3,
  breaklines=true,
  aboveskip=1ex,
  belowskip=1ex,
  basicstyle=\small\ttfamily,
  framerule=0pt,
  backgroundcolor=\color{gray!25},
  columns=fullflexible,
}

\begin{document}
  \lstinputlisting{article.cls}
\end{document}
Perhaps the manual of the listings package will tell you more.


Best regards and welcome to the board
Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
mario595
Posts: 2
Joined: Fri Jun 12, 2009 1:16 pm

Help with lstlisting

Post by mario595 »

Thanks for your reply.Maybe I have not explained well.For example,if I write this:

Code: Select all

\begin{lstlisting}[language=C,numbers=left,numberstyle=\tiny ,basicstyle=\small]

int i=0;
int j=10;
while (1){
   i++;
   j--;
}
\end{lstlisting}
perhaps the result will be:

Code: Select all

int i=0;
int j=10;
while(1){
   i++;
----NEW PAGE---------------
   j--;
}
and y don't like that the loop its "broken" and I prefers this:

Code: Select all

int i=0;
int j=10;
----NEW PAGE---------------
while(1){
   i++;
   j--;
}
How I can tell to lstlisting that I want continue in a new page in this point?
I hope to explained better...
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

Help with lstlisting

Post by localghost »

Read Section 4.14 (Escaping to LaTeX, p. 38f) of the listings manual.
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
Post Reply