hi:
I meet a problem about how to setup caption style.
I hope to create a new caption style such as 1-1, 1-2;
that means if the table in chap1, the caption with first table will
show 1-1:...; and the caption with the second table will show 1-2
, and if in chapter 2, the caption will be 2-1, and 2-2, .. and so on.
do any one know how to make it, any help is high appreciated, thanks.
Graphics, Figures & Tables ⇒ how to modify the caption style with table and figure
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 modify the caption style with table and figure
You should have told us your document class. So I can only assume. For the report class consider the following example which borrows code from the class itself and modifies it.
Further customization of captions can be done with the caption package.
Best regards and welcome to the board
Thorsten¹
Code: Select all
\documentclass[11pt,a4paper]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[font=small,labelfont={bf,sf},tableposition=top]{caption}
\makeatletter
\renewcommand{\thefigure}{\ifnum \c@chapter>\z@ \thechapter-\fi \@arabic\c@figure}
\renewcommand{\thetable}{\ifnum \c@chapter>\z@ \thechapter-\fi \@arabic\c@table}
\makeatother
\begin{document}
\chapter{One}
\begin{figure}[!ht]
\centering
\rule{6.4cm}{3.6cm}
\caption{Dummy figure}\label{fig:dummy}
\end{figure}
\begin{table}[!ht]
\caption{Dummy table}\label{tab:dummy}
\centering
\rule{6.4cm}{3.6cm}
\end{table}
\end{document}
Best regards and welcome to the board
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 modify the caption style with table and figure
thanks. and it works when the class is report. But it not work
when the documentclass is article, how do I modify?
And I also meet a problem, if I hope I could apply these codes to the
section in appendix, and I modify the \chapter to \appendix, however,
it not work. how to solve that? and what is the meaning of c@ and >\z@.
thanks
when the documentclass is article, how do I modify?
And I also meet a problem, if I hope I could apply these codes to the
section in appendix, and I modify the \chapter to \appendix, however,
it not work. how to solve that? and what is the meaning of c@ and >\z@.
thanks
how to modify the caption style with table and figure
The article class has no chapters, but you talked about "chap1" and "chapter 2"!?clement wrote:thanks. and it works when the class is report. But it not work when the documentclass is article, how do I modify?
The \ifnum stuff is just for the case you don't have a chapter yet, so the "-" won't appear than. Usually you can drop that. \@arabic\c@figure is identical to \arabic{figure}. (\c@chapter is identical to \value{chapter} and \z@ is identical to 0 (zero))and what is the meaning of c@ and >\z@.
So
Code: Select all
\renewcommand{\thefigure}{\ifnum \c@chapter>\z@ \thechapter-\fi \@arabic\c@figure}
Code: Select all
\renewcommand{\thefigure}{\thechapter-\arabic{figure}}