TransWikia.com

Modified command to obtain an alternative list of figures

TeX - LaTeX Asked on May 24, 2021

I would like to have a modified listoffigures command (named mlistoffigures), which takes the text printed for the figures from an extra command (named extracommand).
Could you please help me how to define these two commands?
It would be useful if extracommand worked also for non-float figures (like captionof).

My MWE is as follows:

documentclass{article}
usepackage{graphicx}
usepackage{caption}
usepackage{subcaption}
usepackage{duckuments}

captionsetup[subfigure]{list=true}

begin{document}

listoffigures
mlistoffigures %command to be defined

%
%Desired output of mlistoffigures (using extracommand{}):
% 1. Fig. 1
% 2. Fig. 2
%    a Fig. 2a
%    b Fig. 2b

begin{figure}
centering
includegraphics{example-image-a}
label{fig:alef}
caption[Alef figure.]{Alef.}
extracommand{Fig. 1} %command to be defined
end{figure}

begin{figure}
    begin{subfigure}[]{textwidth}
    centering
    includegraphics[width=textwidth]{example-image-b}
    label{fig:bet}
    caption[Bet figure.]{Bet.}
    extracommand{Fig. 2a}
    end{subfigure}
    
    begin{subfigure}[]{textwidth}
    centering
    includegraphics[width=textwidth]{example-image-c}
    label{fig:gimel}
    caption[Gimel figure.]{Dalet.}
    extracommand{Fig. 2b}
    end{subfigure}

    caption[Bet + gimel figure.]{Bet + gimel.}
    extracommand{Fig. 2}
end{figure}

end{document}

One Answer

EDIT

This is an answer that I think meets the OP's requirements as he stated in his comment to my earlier communication.

% mlofprob.tex  SE 597456   EDITED VERSION WORKS !!!!!!!!!!!!!!!!!!!!!!!!

documentclass{article}
usepackage{graphicx}
usepackage{caption}
usepackage{subcaption}
usepackage{duckuments}

usepackage{comment}

captionsetup[subfigure]{list=true}

usepackage{tocloft}
newcommand{listmfiguresname}{M List of Figures}
newlistof{extracmd}{mlf}{listmfiguresname}

newcommand{extracommand}[2]{%
  addtocontents{mlf}{#1: Figure #2par}
}

begin{document}

listoffigures
listofextracmd

begin{figure}
centering
includegraphics{example-image-a}
%label{fig:alef}
caption[Alef figure.]{Alef.}
label{fig:alef}
extracommand{example-image-a}{ref{fig:alef}}
end{figure}

begin{figure}
    begin{subfigure}[]{textwidth}
    centering
    includegraphics[width=textwidth]{example-image-b}
 %   label{fig:bet}
    caption[Bet figure.]{Bet.}
    label{fig:bet}
    extracommand{example-image-b}{ref{fig:bet}}
    end{subfigure}
    
    begin{subfigure}[]{textwidth}
    centering
    includegraphics[width=textwidth]{example-image-c}
%    label{fig:gimel}
    caption[Gimel figure.]{Dalet.}
    label{fig:gimel}
    extracommand{example-image-c}{ref{fig:gimel}}
    end{subfigure}

    caption[Bet + gimel figure.]{Bet + gimel.}
end{figure}

end{document}

enter image description here

** ORIGINAL POSTING**

Not an answer but it shows what I tried. After your above comment I did not understand the basics of what you are after. I tried for a new `listof...` but after some failures I gave up (although I'm sure that it is possible) ---time constraints came into this. 

I thought that perhaps what you needed was just to list the figure numbers. Below I have done that by using `ref{<fig-label>}`. I had to modify your original code as `label` has to come after `caption`.

 

        % mlofprob.tex  SE 597456   DIDN'T WORK!!!!!!!!!!!!!!!!!!!!!!!!
    
    documentclass{article}
    usepackage{graphicx}
    usepackage{caption}
    usepackage{subcaption}
    usepackage{duckuments}
    
    usepackage{comment}
    
    captionsetup[subfigure]{list=true}
    
    begin{comment}
    usepackage{tocloft}
    newcommand{listmfiguresname}{M List of Figures}
    newlistof{extracmd}{mlf}{listmfiguresname}
    
    end{comment}
    
    providecommand{extracommand}[1]{%
      addcontentsline{mlf}{}{#1}par
    }
    renewcommand{extracommand}[1]{}
    
    
    begin{document}
    
    listoffigures
    %mlistoffigures %command to be defined
    %listofextracmd
    %
    %Desired output of mlistoffigures (using extracommand{}):
    % 1. Fig. 1
    % 2. Fig. 2
    %    a Fig. 2a
    %    b Fig. 2b
    
    textbf{Figure numbers}
    
    ref{fig:alef}
    
    ref{fig:bet}
    
    ref{fig:gimel}
    
    
    begin{figure}
    centering
    includegraphics{example-image-a}
    %label{fig:alef}
    caption[Alef figure.]{Alef.}
    label{fig:alef}
    extracommand{Fig. 1} %command to be defined
    end{figure}
    
    begin{figure}
        begin{subfigure}[]{textwidth}
        centering
        includegraphics[width=textwidth]{example-image-b}
     %   label{fig:bet}
        caption[Bet figure.]{Bet.}
        label{fig:bet}
        extracommand{Fig. 2a}
        end{subfigure}
        
        begin{subfigure}[]{textwidth}
        centering
        includegraphics[width=textwidth]{example-image-c}
    %    label{fig:gimel}
        caption[Gimel figure.]{Dalet.}
        label{fig:gimel}
        extracommand{Fig. 2b}
        end{subfigure}
    
        caption[Bet + gimel figure.]{Bet + gimel.}
        extracommand{Fig. 2}
    end{figure}
    
    end{document}

Answered by Peter Wilson on May 24, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP