3

Due to local text writing requirements I have to put numbers of figures and tables before labels: "1 figure" instead "Figure 1", "1 table" instead "Table 1"

How to do this? Regards, Jonas

2 Answers 2

5

Using the caption package you can define the caption label format using DeclareCaptionLabelFormat. I've added a dot so that it would be "1. Figure"m you can remove the dot and it will be "1 Figure".

\documentclass{article}
\usepackage{mwe}

\usepackage{caption}  

\DeclareCaptionLabelFormat{mycaptionlabel}{#2. #1}

\captionsetup{labelformat=mycaptionlabel}
\captionsetup[table]{name={Lentele}}
\captionsetup[figure]{name={Pav.}}

\begin{document}
\begin{figure}
    \centering
    \includegraphics[scale=.3]{example-image-a}
    \caption{my figure}
\end{figure}

\begin{table}[]
    \centering
    \begin{tabular}{c|c}
         A&table  \\ \hline
         1&2 
    \end{tabular}
    \caption{Caption}
    \label{tab:my_label}
\end{table}

\end{document}

and the outcome: enter image description here

Note the following:

  1. We change the name of the float through the captionsetup option.
  2. the captionsetup command can be used without options in [], in which case the setup will apply to all floats. You can define to which float (i.e. table or figure) to apply using the option. Therefore if you wish the number to come first only in tables, delete the \captionsetup{labelformat=mycaptionlabel} line, and add the labelformat option to the table line
5
  • Thank you for quick reply. I have included code like this, but result is the same: "Lentelė 1.4:" May be the lavel format is "inherited" and has to be somehow "flushed"? \usepackage{mwe} \usepackage{caption} \DeclareCaptionLabelFormat{#2. #1}{mycaptionlabel} \captionsetup{labelformat=mycaptionlabel} \renewcommand{\figurename}{Pav.} \renewcommand{\tablename}{Lentelė} Oct 29, 2020 at 7:28
  • Can the issue be related to the fact, that I have to redefine caption only for one section of the document? Oct 29, 2020 at 8:10
  • I have changed the answer accordingly. You should use the package setup and not run it over with renewcommand
    – Elad Den
    Oct 29, 2020 at 9:18
  • The comands that you have - I have tested - work OK in new clean document, but does not work in my document with multiple chapters. Oct 29, 2020 at 9:59
  • In this case we need you to change your question: write a small Minimal Working Example (MWE): a clean document that recreates the problem. It should start with \documentclass and end with \end{document} and contain all relevant packages and commands
    – Elad Den
    Oct 29, 2020 at 10:17
3

For the standard classes like article, report and book the caption is controlled by the commands \fnum@figure and \fnum@table. By default they are defined as

\def\fnum@figure{\figurename\nobreakspace\thefigure}
\def\fnum@table{\tablename\nobreakspace\thetable}

where \thefigureand \thetable are the definitions of how the number is written, and \figurename and \tablename the name of the figure and table (i.e. Figure and Table).

You can redefine these commands with reverse order to get what you want. In the below code I have made commands for the reverse order and default order. I have used two column layout to fit it on one page. (If you include other packages for typesetting the captions this might not work. In that case it is probably easier to use the commands in that package to get the desired behavior, like @EladDen suggests in another answer.)

\documentclass[twocolumn]{article}
\usepackage{graphicx}
\makeatletter
\newcommand\ReverseCaption{%
  \renewcommand\fnum@figure{\thefigure\nobreakspace\figurename}
  \renewcommand\fnum@table{\thetable\nobreakspace\tablename}
}
\newcommand\DefaultCaption{%
  \renewcommand\fnum@figure{\figurename\nobreakspace\thefigure}
  \renewcommand\fnum@table{\tablename\nobreakspace\thetable}
}
\makeatother
%%%%%%%%%%%%%%%%%%%
\begin{document}
\section{First section}
In Figure~\ref{fig:imgA} image A is shown and a table in Table~\ref{tab:tabA}.
\begin{figure}[htb]
  \centering
  \includegraphics[width=40mm]{example-image-a}
  \caption{Image A}
  \label{fig:imgA}
\end{figure}
\begin{table}[htb]
  \centering
  \begin{tabular}{lll}
    x & y & z\\\hline
    1 & 2 & 3
  \end{tabular}
  \caption{Table A}
  \label{tab:tabA}
\end{table}

\section{Second section}
\ReverseCaption
In \ref{fig:imgB}~Figure image B is shown and a table in \ref{tab:tabB}~Table.
\begin{figure}[htb]
  \centering
  \includegraphics[width=40mm]{example-image-b}
  \caption{Image B}
  \label{fig:imgB}
\end{figure}
\begin{table}[htb]
  \centering
  \begin{tabular}{lll}
    x & y & z\\\hline
    1 & 2 & 3
  \end{tabular}
  \caption{Table B}
  \label{tab:tabB}
\end{table}

\newpage
\section{Third section}
\DefaultCaption
 In Figure~\ref{fig:imgC} image C is shown and a table in Table~\ref{tab:tabC}.
\begin{figure}[htb]
  \centering
  \includegraphics[width=40mm]{example-image-c}
  \caption{Image C}
  \label{fig:imgC}
\end{figure}
\begin{table}[htb]
  \centering
  \begin{tabular}{lll}
    x & y & z\\\hline
    1 & 2 & 3
  \end{tabular}
  \caption{Table C}
  \label{tab:tabC}
\end{table}
\end{document}

enter image description here

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.