Graphics, Figures & Tables ⇒ how to modify the caption style with table and figure
how to modify the caption style with table and figure
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.
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
how to modify the caption style with table and figure
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¹
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: how to modify the caption style with table and figure
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}}