2

Every time I have to denote a figure name in the text I have to type: {\textcolor{ocre}{\bf{\emph{Fig.\;\ref{figurename}(b)}}}}

Is there an optimized way to specify this in the preamble so I do not have to type this each time I refer to a figure name?

I already specified:

\usepackage{caption}
\usepackage[font={color=ocre,bf,it},figurename=Fig.,labelfont={it}]{caption}

in the preamble to take care of the caption name and text.

3

Since you're writing sub-figure captions and references manually, my suggestion would be to use a macro like the following:

\newcommand{\figref}[2][]{% \figref[<sub-figref>]{<figref>}
  \textcolor{ocre}{\bfseries\emph{\figurename\,\ref{#2}#1}}}

This allows you to use \figref{<figref>} to reference full figures, or \figref[(b)]{<figref>} (say) to reference sub-figures.

Here's a complete minimal example:

enter image description here

\documentclass[dvipsnames]{article}
\usepackage{xcolor,graphicx}
\usepackage{caption}
\DeclareCaptionLabelFormat{mycaplabelformat}{#1\,#2}
\captionsetup[figure]{%
  font={color=red!70!black,bf,it},
  labelformat=mycaplabelformat}

\renewcommand{\figurename}{Fig.}  
\newcommand{\figref}[2][]{% \figref[<sub-figref>]{<figref>}
  \textcolor{red!70!black}{\bfseries\emph{\figurename\,\ref{#2}#1}}}

\newcommand{\subfigfont}{\small}

\begin{document}

\begin{figure}
  \centering
  \begin{tabular}{@{}c@{}}
    \includegraphics[width=100pt]{example-image-a} \\
    {\subfigfont (a) first}
  \end{tabular} \qquad
  \begin{tabular}{@{}c@{}}
    \includegraphics[width=100pt]{example-image-b} \\
    {\subfigfont (b) second}
  \end{tabular}
  \caption{Some caption}
  \label{fig:label}
\end{figure}

\verb|\ref{fig:label}|: \ref{fig:label} \par
\verb|\figref{fig:label}|: \figref{fig:label} \par
\verb|\figref[(b)]{fig:label}|: \figref[(b)]{fig:label}

\end{document}

You may have to make some adjustments to the formatting. However, consistency is the key and wrapping content inside a macro allows you to change things later, if needed.

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.