Who is online

In total there are 22 users online :: 0 registered, 0 hidden and 22 guests (based on users active over the past 5 minutes)
Most users ever online was 1327 on Tue Nov 05, 2013 7:11 pm

Users browsing this forum: No registered users and 22 guests

listings | Appendix with custom Setup for Code Listings

Add tags LaTeX specific issues not fitting into one of the other forums of this category.

listings | Appendix with custom Setup for Code Listings

Hi guys,

first topic here. I am a newbie, attempting to end my first report.

I need to insert C++ code in the appendix, and what I'd like to obtain is to have a particular style for the lstlisting environment (for C++ and with smaller font) only for the appendix, while preserving the unspecialised style for the rest of the document.

Another nice feature would be having a different margin for the pages in the appendix. What is the solution?

Regards
- s.fox
Superfox_il_Volpone

Posts: 3
Joined: Sat Nov 17th, 2012

Re: listings | Appendix with custom Setup for Code Listings

Regarding the listings package, you can use \lstset anywhere in the document, and it will affect only the following listings. See documentation for more information.

Changing the margins in the appendix could be done with the geometry package, or possibly through a different construction depending on the document class you use.

A small example of how this could be done:
Code: Select all  •  Open in writeLaTeX
\documentclass{article}\usepackage{geometry}\usepackage{listings}\geometry{margin=2in}\begin{document}\begin{lstlisting}  program hello    implicit none          print *, 'Hello World'  end program\end{lstlisting}\newgeometry{margin=0.1in}\clearpage\lstset{  language=[95]fortran,  basicstyle=\small\ttfamily,  keywordstyle=\bfseries,  frame=single,}\begin{lstlisting}  program hello    implicit none          print *, 'Hello World'  end program\end{lstlisting}\end{document}
Ubuntu 13.10 + Tex Live 2013 + Texmaker / Windows 7 Pro + MikTex 2.9 + TexnicCenter / Android 4.3 + TexPortal + DroidEdit
hugovdberg

Posts: 133
Joined: Sat Feb 25th, 2012
Location: 's-Hertogenbosch, Netherlands

Re: listings | Appendix with custom Setup for Code Listings

thank you, it worked!

regards
- s.fox
Superfox_il_Volpone

Posts: 3
Joined: Sat Nov 17th, 2012