Generallistings | Change Caption Label

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
amppinheiro
Posts: 4
Joined: Wed Jun 06, 2012 11:32 am

listings | Change Caption Label

Post by amppinheiro »

Hi all!

I am Portuguese and I need to display some Python code in my document. I am already familiar with the listing package. I am used to write in English (so I have never stumble upon this problem before), the Portuguese document class does not translate the Listings label in caption. How can I do this? At the moment I am using the Title option but I would really like to give a label to those code listings (in Portuguese).

Now I have tried to mess with the \captionsetup, from what I understand the command should be the following

Code: Select all

\captionsetup[listing]{name=Exemplo de código}
But I can't seem to get it right, what am I doing wrong? Can anyone help?

Thanks!

Recommended reading 2024:

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

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

listings | Change Caption Label

Post by localghost »

The caption package doesn't help in redefining the caption label for the listings. But Section 4.9 of the listings manual lists all parameters regarding captions for listings.

Code: Select all

\documentclass[11pt,a4paper,portuges]{article}
\usepackage[T1]{fontenc}
\usepackage{selinput}      % semi-automatic determination of input encoding
\SelectInputMappings{      % by a list of selected glyphs
  aacute={á},              % see: http://partners.adobe.com/public/developer/en/opentype/glyphlist.txt
  ccedilla={ç},
  Euro={€},
}
\usepackage{babel}
\usepackage{listings}

\lstset{
  basicstyle=\ttfamily,
}
\renewcommand*{\lstlistingname}{Exemplo de código}

\begin{document}
  \begin{lstlisting}[
    language=Python,
    gobble=4,
    frame=single,
    captionpos=b,
    caption={Python code},
    label={lst:example},
    float
  ]
    def faculty(x):
      if x > 1:
        return x * faculty(x - 1)
      else:
        return 1
  \end{lstlisting}
\end{document}

Thorsten
amppinheiro
Posts: 4
Joined: Wed Jun 06, 2012 11:32 am

Re: listings | Change Caption Label

Post by amppinheiro »

Thank you! Works like a charm!
Post Reply