0

I would like to extend again a bit further my extended figure caption to account for tables as well. Previous questions are

Hypertarget pointing at \thefigure

Automatically "protect" new paragraph in extended figure caption

What the macro does is, defining a command \extcaption{Some extended information about the current figure} to be placed into a figure float, whose content is written into a .efc file then printed somewhere at the end of the document by a command \printextcaption.

To extend it to tables, I do not think I need to recall all the code as, essentially, I would need a function (called \checkwhichfloat in the MWE) that is able to detect in which float it is called, and return the appropriate counter and string.

Here is the code:

\documentclass[10pt]{report}

\newcommand\efccounter{}
\newcommand\efctext{}

% \newcommand\checkwhichfloat{
% If figure
\renewcommand\efccounter{\thefigure}
\renewcommand\efctext{Figure}
% else if table
\renewcommand\efccounter{\thetable}
\renewcommand\efctext{Table}
%

\begin{document}

\begin{figure}
%\checkwhichfloat
\caption{This is \efctext~\efccounter}
\end{figure}

\begin{table}
%\checkwhichfloat
\caption{This is \efctext~\efccounter}
\end{table}

\end{document}
  • 1
    Usually \@captype contains the current floating environment name. – Axel Sommerfeldt Dec 7 '15 at 19:57
0

Thanks to @Axel Sommerfeldt's comment, I managed a solution with the pdftexcmds package (And skimming up this website):

\documentclass[10pt]{report}
\usepackage{pdftexcmds} 

\newcommand\efccounter{} % Contains counter
\newcommand\efctext{} % Contains float env. string
% -------------------------------
\makeatletter
\newcommand\checkwhichfloat{
% If figure
\ifnum\pdf@strcmp{\@captype}{figure}=0
\renewcommand\efccounter{\thefigure}
\renewcommand\efctext{Figure}
% If table
\else\ifnum\pdf@strcmp{\@captype}{table}=0
\renewcommand\efccounter{\thetable}
\renewcommand\efctext{Table}
\fi\fi}
\makeatother

\begin{document}

\begin{figure}
\checkwhichfloat
\caption{This is \efctext~\efccounter}

\end{figure}

\begin{table}

\checkwhichfloat
\caption{This is \efctext~\efccounter}
\end{table}

\end{document}

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.