2

In the following code the figure number is shown as 1.1. How can I change the figure number format to 1-1?

\documentclass{book}
\usepackage{graphicx}
\usepackage{caption}


\begin{document}
\chapter{One}
test
\begin{figure}[ht!]
\centering
 \includegraphics[scale=0.5]{10.png} \caption{} \label{handle}
\end{figure}

Figure \ref{handle}.
\end{document}
2
  • 1
    do you want to change it only in ref? what about in caption (Figure 1.1: caption)?
    – touhami
    Feb 12, 2016 at 6:34
  • @touhami I want to change it everywhere. Feb 12, 2016 at 6:36

1 Answer 1

4

Here is a solution

\documentclass{book}
\usepackage{graphicx}
\usepackage{caption}
\renewcommand\thefigure{\ifnum \value{chapter}>0 \thechapter-\fi \arabic{figure}}

\begin{document}
\chapter{One}
test
\begin{figure}[ht!]
\centering
 \includegraphics[scale=0.5]{myfoto} \caption{bla} \label{handle}
\end{figure}

Figure \ref{handle}.
\end{document}
6
  • it does not work for me with xelatex. Feb 12, 2016 at 6:39
  • it shows only one number. But I want both numbers like 1-1. Feb 12, 2016 at 6:42
  • Will this method reset the within-chapter figure number back to "1" at the start of every chapter?
    – Mico
    Feb 12, 2016 at 8:07
  • @Mico no, it doesn't but the class book does so yes the figure counter will be reset at every (unstarred) chapter start.
    – touhami
    Feb 12, 2016 at 8:40
  • @Mico I am voting for reopening this question. here the O.P. want to change the format of counter.
    – touhami
    Feb 12, 2016 at 14:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .