TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working with platex (the Japanese latex compiler) and I'm trying to change the caption system for Listings and Figures. For both I would like the numbering to be based on section so if its a figure or Listing in section 2 I want it to be in the style of 2.1

Also I want to change the tag Listing to list.

The doctype I'm using is jarticle because its the only type I found that works with Japanese letters.

Any advice would be much appreciated.

An example of my current code is as follows

\documentclass[a4paper]{jarticle}
\usepackage{listings}
\usepackage[dvipdfm]{graphicx}
\title{title}
\author{name}
\begin{document}
\begin{titlepage}
\maketitle
\vfill
\tableofcontents
\end{titlepage}

\section{Basics}
\normalsize
\begin{figure}[ht]
\centering
\includegraphics[width=200pt]{1.eps}
\caption{some caption}%
\end{figure}

\section{Bar}
\normalsize
\scriptsize
\lstset{numbers=left, stepnumber=5, caption={text}, escapeinside={\%*}{*)}, frame=single, tabsize=2}
\begin{lstlisting}
code here
\end{lstlisting}

\end{document}
share|improve this question

migrated from stackoverflow.com May 24 '11 at 10:11

This question came from our site for professional and enthusiast programmers.

    
@Johan please do not change the question to add a solution. The answer is already visible below. – Caramdir May 26 '11 at 2:18

You may use the \@addtoreset{figure}{section} command in combination with \renewcommand{\thefigure}{\thesection.\arabic{figure}}. See this page.

To say something about changing the listing name it would be helpful to see which package you use to format them. Pleas create a minimal working example (MWE).

Here’s mine which shows everything you’ll need I think…

\documentclass{article}

\usepackage{listings}

\renewcommand{\lstlistingname}{List}% [1]
\makeatletter% [2]
    \@addtoreset{lstlisting}{section}% [3]
\makeatother
\AtBeginDocument{% [4]
    \renewcommand{\thelstlisting}{\thesection.\arabic{lstlisting}}%[5]
}

\begin{document}
\section{Section}
Content ...

\begin{lstlisting}[caption=Test]
Test ...
\end{lstlisting}
\end{document}

Notes:
[1] Change the name of listings
[2] Necessary to use command containing @
[3] Lets the listing counter be resetted in a new section
[4] Necessary because \thelstlistings is undefined before begin document.
[5] Renew number layout.


As egreg said thers a second way with the chngcntr package, maybe one prefer this way …

\documentclass{article}

\usepackage{listings}

\usepackage{chngcntr}
\counterwithin{figure}{section}
\AtBeginDocument{\counterwithin{lstlisting}{section}}
\renewcommand{\lstlistingname}{List}

\begin{document}
\section{Section}
Content ...

\begin{lstlisting}[caption=Test]
Test ...
\end{lstlisting}

\begin{figure}
\rule{1cm}{1cm}
\caption{A example}
\end{figure}
\end{document}
share|improve this answer
    
One can simplify by loading chngcntr and saying only \counterwithin{lstlisting}{section} inside \AtBeginDocument (no \@addtoreset is needed, and \counterwithin automatically redefines \the...) – egreg May 24 '11 at 16:49
    
@egreg: Thank. I read it on the linked page in my solution after posting. I like the ways with no extra packages. I added an extra example. – Tobi May 24 '11 at 16:51
    
Why reinventing the wheel? :) It's unfortunate that the LaTeX kernel doesn't provide a user interface for linking counters; chngcntr is powerful and unobtrusive. – egreg May 24 '11 at 17:01
    
@egreg: I see, maybe I can remember the package in future … :-) – Tobi May 24 '11 at 18:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.