Specify Figure name color and slant

by Joe   Last Updated April 14, 2015 22:10 PM - source

Evertime 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.

Tags : captions


Answers 1


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}{@{}[email protected]{}}
    \includegraphics[width=100pt]{example-image-a} \\
    {\subfigfont (a) first}
  \end{tabular} \qquad
  \begin{tabular}{@{}[email protected]{}}
    \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.

Werner
Werner
April 14, 2015 20:22 PM

Related Questions


Caption figure in Latex

Updated March 28, 2015 14:07 PM



Add a caption under an image

Updated May 04, 2015 21:10 PM