2

I am using the cleveref package for cross-references in my document. I am using \cref throughout my document, so the label is added to the reference. However, I would like the label Figure and Table to be in small caps shape (\scshape?). How can I achieve this?

Here is an MWE:

\documentclass{article} \usepackage[capitalise]{cleveref} \begin{document} \begin{table} \begin{tabular}{lr} \hline 0 & 1\\ 1 & 0\\ \hline \end{tabular} \caption{A table} \label{tab:example} \end{table} Here is a reference: \cref{tab:example}. \end{document} 
3
  • Do you just want the label capitalized, or also the reference? The first can be achieved using the options provided by the caption package: \usepackage[labelfont = {sc}]{caption} Commented May 18, 2017 at 9:07
  • No, I also want the reference to be in small caps. Since I am using cref, the output of \cref{tab:example} looks like Table 1. There, I want the word Table to be in small caps. Commented May 18, 2017 at 9:09
  • 1
    Adding \Crefformat{figure}{#2{}\scshape{Figure} #1{}#3} and \Crefformat{table}{#2{}\scshape{Table} #1{}#3} to the preamble seems to work. Commented May 18, 2017 at 9:24

1 Answer 1

4

The solution I found is in two parts: \usepackage[labelfont = {sc}]{caption} capitalizes the label. \Crefformat{figure}{#2{}\scshape{Figure} #1{}#3} and \Crefformat{table}{#2{}\scshape{Table} #1{}#3} the reference. Of course, if you want the same behaviour for equations, sections etc. these have to be added.

Explanation of the arguments of \Crefformat from the documentation on ctan:

It should contain three arguments, #1, #2 and #3. The first argument is the formatted version of the label counter (e.g. \theequation). The other two are used to mark the beginning and end of the part of the cross-reference that forms the hyperlink when the hyperref package is used, and must appear in that order.

\documentclass{article} \usepackage[labelfont = {sc}]{caption} \usepackage[capitalise]{cleveref} \Crefformat{figure}{#2{}\scshape{Figure} #1{}#3} \Crefformat{table}{#2{}\scshape{Table} #1{}#3} \begin{document} \begin{table} \begin{tabular}{lr} \hline 0 & 1\\ 1 & 0\\ \hline \end{tabular} \caption{A table} \label{tab:example} \end{table} Here is a reference: \cref{tab:example}. \end{document} 
5
  • How would you do it for German? \Crefformat{Abbildung}{#2{}\scshape{Figure} #1{}#3} or \Crefformat{figure}{#2{}\scshape{Abbildung} #1{}#3}? Or any more elegant solution? Commented May 24, 2017 at 6:47
  • @thymaro: not sure. I had expected the cleveref package to play properly when you set the language to german using \usepackage[ngerman]{babel}, but it doesn't seem to be the case ... depending on what you need to achieve, you could either use the \autoref command (provided by hyperref package), redefine manually as you suggested ... or find a fix for cleveref to work with other languages, but that would best be posted as separate question I think Commented May 24, 2017 at 6:59
  • Thanks for the quick answer. I don't actually need to do this, so I'll refrain from posting the question. I was just wondering how this would be achieved and if you already knew a method. As long as noone else is bugged by this, I guess we should let it rest. Commented May 24, 2017 at 7:14
  • nothing is stopping you from asking a question even if you're not in desperate need for an answer now ;) Commented May 24, 2017 at 7:18
  • 1
    @thymaro: I couldn't let go, and actually it does work also for cleveref (of course). You just need to load with the [ngerman] option ... Commented May 24, 2017 at 8:35

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.