TransWikia.com

How to remove label and number from cref?

TeX - LaTeX Asked on January 26, 2021

I am trying to reference multiple subfigures in the caption of a figure separated by dash.
For example, the caption of the figure should look like:

Fig1. this is a figure. (a) first figure. (b) second figure. (c-e) the
rest of figures.

When I try using labelcref the figure number still appears:

Fig1. this is a figure. (a) first figure. (b) second figure. 1(c) to 1(e) the
rest of figures.

how can I remove the number and label and just keep the letters?

The solution here did not work for me because of multiple unrecogniazed command errors, and it is too complicated.

documentclass{article}
usepackage{subfigure}
usepackage{epsfig}
usepackage{cleveref}

begin{document}
    
    begin{figure}
        centering
        setcounter{subfigure}{0}
        subfigure[]{includegraphics{fig1}label{fig1}}
        subfigure[]{includegraphics{fig2}label{fig2}}
        subfigure[]{includegraphics{fig3}label{fig3}}
        subfigure[]{includegraphics{fig4}label{fig4}}
        subfigure[]{includegraphics{fig5}label{fig5}}
        caption{
            This is a figure.
            cref{fig1} first figure,
            cref{fig2} second figure,
            and labelcref{fig3,fig4,fig5} rest of figures.
        }   
    end{figure}
    
end{document}

This is the output I am getting:
enter image description here

But I want it to look like:

Fig1. this is a figure. (a) first figure. (b) second figure. (c-e) the
rest of figures.

One Answer

In the following example, package subcaption is loaded instead of subfigure, and epsfig is replaced with graphicx. Recent version of graphicx can handle eps figures automatically. Also,

  • subfloat is used instead of subfigure since subcaption defines the latter as an environment,
  • option labelsep=none is used to center the caption of subfigure (since it has empty caption title), and
  • option subrefformat=parens is used to make subref{fig1} produce (a) instead of just a.

At last, dummy images provided by mwe package are used since I don't have image files fig1, fig1, ... .

documentclass{article}
usepackage{graphicx}
usepackage{subcaption}
%usepackage{hyperref}
usepackage{cleveref}

captionsetup[sub]{labelsep=none, subrefformat=parens}
crefrangelabelformat{subfigure}
  {(#3crefstripprefix{#2}{#1}#4--#5crefstripprefix{#1}{#2}#6)}

begin{document}
    
begin{figure}
    centering
    subfloat[label{fig1}]{includegraphics[width=3cm]{example-image-a}}quad
    subfloat[label{fig2}]{includegraphics[width=3cm]{example-image-b}}quad
    subfloat[label{fig3}]{includegraphics[width=3cm]{example-image-c}}
    subfloat[label{fig4}]{includegraphics[width=3cm]{example-image-a}}quad
    subfloat[label{fig5}]{includegraphics[width=3cm]{example-image-b}}
    caption{%
        This is a figure.
        subref{fig1} first figure,
        subref{fig2} second figure,
        and labelcref{fig3,fig4,fig5} rest of figures.
    }   
end{figure}
    
end{document}

enter image description here

If you prefer labelcref from cleveref than subref from subcaption, see answers in question Combining cleveref and subref.

Correct answer by muzimuzhi Z on January 26, 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