TransWikia.com

Write full ref name

TeX - LaTeX Asked by Churkin Aleksey on July 2, 2021

renewcommand{figurename}{Paint }
begin{figure}[h]
    includegraphics{22.png}
    label{fig:22}
end{figure}

This is example reference autoref{fig:22}

It write

This is example reference Figure 1

instead

This is example reference Paint 1.

What should I do to get Paint 1?

2 Answers

Just create a new environment for paintings.

It would just be easier to create your own new environment than tinkering with figure. Combining the solutions from here and here you can easily create a new environment for paintings that behaves just like figures would, but built for purpose:

Output

enter image description here

MWE

documentclass[10pt,a4paper]{article}
usepackage{newfloat}
usepackage{hyperref}
usepackage{cleveref}


DeclareFloatingEnvironment[
fileext=lop,
listname={List of Paintings},
name=Painting,
placement=tbhp,
within=section,
]{painting}

crefname{painting}{painting}{paintings}
Crefname{painting}{Painting}{Paintings}


begin{document}
begin{painting}
centering
Some painting should go here.
caption{Something about the painting.}
label{painting}
end{painting}

You could use texttt{autoref} to reference autoref{painting}, but likely texttt{cref} would be better to refer to cref{painting} as either Cref{painting} or cref{painting}.
end{document}

Correct answer by oliversm on July 2, 2021

If all your figure environment should be labeled “Paint” (but you should check the grammar), you can do it with hyperref only.

However you need the caption, or the label will refer to something random.

documentclass{article}
usepackage{graphicx}
usepackage{hyperref}

renewcommand{figurename}{Paint} % is it right?
renewcommand{figureautorefname}{Paint}

begin{document}

begin{figure}[htp]
centering

includegraphics[width=2cm]{example-image}

caption{A caption}label{fig:22}
end{figure}

This is example reference autoref{fig:22}

end{document}

enter image description here

With cleveref:

documentclass{article}
usepackage{graphicx}
usepackage{hyperref}
usepackage[nameinlink]{cleveref}

renewcommand{figurename}{Paint} % is it right?
crefname{figure}{Paint}{Paints}

begin{document}

begin{figure}[htp]
centering

includegraphics[width=2cm]{example-image}

caption{A caption}label{fig:22}
end{figure}

This is example reference cref{fig:22}

end{document}

Answered by egreg on July 2, 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