General ⇒ How to fit long code?
How to fit long code?
Hi,
Using listing or verbatim package, the long codes would go into page margin. How is it possible to format long codes?
Look forward to your reply,
Using listing or verbatim package, the long codes would go into page margin. How is it possible to format long codes?
Look forward to your reply,
NEW: TikZ book now 40% off at Amazon.com for a short time.

- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
How to fit long code?
I see no problem with listings.
The used files.
Best regards
Thorsten
Code: Select all
\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[svgnames]{xcolor}
\usepackage{listings}
\usepackage{lmodern}
\lstset{
aboveskip=1ex,
backgroundcolor=\color{gray!25},
basicstyle=\small\ttfamily,
belowskip=1ex,
breaklines=true,
columns=fullflexible,
framerule=0pt,
framexrightmargin=0em,
framexleftmargin=0em,
numbers=left,
numberstyle=\footnotesize\sffamily,
tabsize=2
}
\begin{document}
\lstinputlisting{minimal.cls}
\end{document}
Code: Select all
*File List*
article.cls 2007/10/19 v1.4h Standard LaTeX document class
size11.clo 2007/10/19 v1.4h Standard LaTeX file (size option)
fontenc.sty
t1enc.def 2005/09/27 v1.99g Standard LaTeX file
inputenc.sty 2008/03/30 v1.1d Input encoding file
latin1.def 2008/03/30 v1.1d Input encoding file
babel.sty 2008/07/06 v3.8l The Babel package
bblopts.cfg 2006/07/31 v1.0 MiKTeX 'babel' configuration
english.ldf 2005/03/30 v3.3o English support from the babel system
xcolor.sty 2007/01/21 v2.11 LaTeX color extensions (UK)
color.cfg 2007/01/18 v1.5 color configuration of teTeX/TeXLive
pdftex.def 2009/08/25 v0.04m Graphics/color for pdfTeX
svgnam.def 2007/01/21 v2.11 Predefined colors according to SVG 1.1 (UK)
listings.sty 2007/02/22 1.4 (Carsten Heinz)
keyval.sty 1999/03/16 v1.13 key=value parser (DPC)
lstmisc.sty 2007/02/22 1.4 (Carsten Heinz)
listings.cfg 2007/02/22 1.4 listings configuration
lmodern.sty 2009/10/30 v1.6 Latin Modern Fonts
t1lmr.fd 2009/10/30 v1.6 Font defs for Latin Modern
supp-pdf.tex
t1lmtt.fd 2009/10/30 v1.6 Font defs for Latin Modern
minimal.cls
t1lmss.fd 2009/10/30 v1.6 Font defs for Latin Modern
***********
Best regards
Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: How to fit long code?
Thanks for your quick reply.
How about if one or few lines code is used that doesn't worth to be put in a separate file? If we use long code in \begin{lstlisting} ...\end{lstlisting}, it won't be formatted
How about if one or few lines code is used that doesn't worth to be put in a separate file? If we use long code in \begin{lstlisting} ...\end{lstlisting}, it won't be formatted
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
How to fit long code?
I still see no problem.
Code: Select all
\listfiles
\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[svgnames]{xcolor}
\usepackage{listings}
\usepackage{lmodern}
\lstset{
aboveskip=1ex,
backgroundcolor=\color{gray!25},
basicstyle=\small\ttfamily,
belowskip=1ex,
breaklines=true,
columns=fullflexible,
framerule=0pt,
framexrightmargin=0em,
framexleftmargin=0em,
language=[LaTeX]TeX,
numbers=left,
numberstyle=\footnotesize\sffamily,
tabsize=2
}
\begin{document}
\begin{lstlisting}
\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[svgnames]{xcolor}
\usepackage{listings}
\usepackage{blindtext}
\usepackage{lmodern}
\lstset{
aboveskip=1ex,
backgroundcolor=\color{gray!25},
basicstyle=\small\ttfamily,
belowskip=1ex,
breaklines=true,
columns=fullflexible,
framerule=0pt,
framexrightmargin=0em,
framexleftmargin=0em,
numbers=left,
numberstyle=\footnotesize\sffamily,
tabsize=2
}
\begin{document}
\blindtext % A long comment line just to show that line breaks are possible
\end{document}
\end{lstlisting}
\end{document}
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
How to fit long code?
How about if the code is simply used in \begin{lstlisting} ... \end{lstlisting} is simply used? How to format in this case?
Cheers,
Cheers,
Code: Select all
\documentclass[12pt,a4paper]{report}
\usepackage{listings}
\begin{document}
\begin{lstlisting}
this is a very long long long code that can't be formatted by lstlisting
\end{lstlisting}
\end{document}
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
How to fit long code?
Do you actually read what people are writing to you? Or package manuals? The issue has been solved long since my first reply and at least since my second one. Did you test the sample code? It's just about one single setting.
Just learn to read package manuals. They explain all the features of a package.
Code: Select all
\documentclass[12pt,a4paper]{article}
\usepackage{listings}
\lstset{%
breaklines=true
}
\begin{document}
\begin{lstlisting}
this is a very long long long code that can't be formatted by lstlisting
\end{lstlisting}
\end{document}
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10