Generallistings | Appendix with custom Setup for Code Listings

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
Superfox_il_Volpone
Posts: 3
Joined: Sat Nov 17, 2012 1:08 am

listings | Appendix with custom Setup for Code Listings

Post by Superfox_il_Volpone »

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

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

hugovdberg
Posts: 133
Joined: Sat Feb 25, 2012 6:12 pm

listings | Appendix with custom Setup for Code Listings

Post by hugovdberg »

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

\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
Superfox_il_Volpone
Posts: 3
Joined: Sat Nov 17, 2012 1:08 am

Re: listings | Appendix with custom Setup for Code Listings

Post by Superfox_il_Volpone »

thank you, it worked!

regards
- s.fox
Post Reply