Graphics, Figures & Tableshow to modify the caption style with table and figure

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
clement
Posts: 15
Joined: Wed Oct 14, 2009 5:06 am

how to modify the caption style with table and figure

Post by clement »

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.

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

how to modify the caption style with table and figure

Post by localghost »

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.

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}
Further customization of captions can be done with the caption package.


Best regards and welcome to the board
Thorsten¹
clement
Posts: 15
Joined: Wed Oct 14, 2009 5:06 am

Re: how to modify the caption style with table and figure

Post by clement »

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
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

how to modify the caption style with table and figure

Post by sommerfee »

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 article class has no chapters, but you talked about "chap1" and "chapter 2"!?
and what is the meaning of c@ and >\z@.
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))

So

Code: Select all

\renewcommand{\thefigure}{\ifnum \c@chapter>\z@ \thechapter-\fi \@arabic\c@figure}
could be replaced by

Code: Select all

\renewcommand{\thefigure}{\thechapter-\arabic{figure}}
Axel
clement
Posts: 15
Joined: Wed Oct 14, 2009 5:06 am

Re: how to modify the caption style with table and figure

Post by clement »

thanks
Post Reply