4

How can I color the words: "Figure and Table" with one color and their numbers with another color?(see attached figure).

Thank you very muchenter image description here

\documentclass{book}
\usepackage{graphicx}
\usepackage{capt-of}% or \usepackage{caption}
\usepackage{booktabs}
\usepackage{varwidth}

\begin{document}

\chapter{Chapter one}

\begin{table}[ht!]
  \begin{varwidth}[b]{0.6\linewidth}
    \centering
    \begin{tabular}{ l r r r }
      \toprule
      Student & Hours/week & Grade \\
      \midrule
      Ada Lovelace & 2 & A \\
      Linus Thorvalds & 8 & A \\
      Bruce Willis & 12 & F \\
      Richard Stallman & 10 & B \\
      Grace Hopper & 12 & A \\
      Alan Turing & 8 & C \\
      Bill Gates & 6 & D \\
      Steve Jobs & 4 & E \\
      \bottomrule
    \end{tabular}
    \caption{Student Database}
    \label{table:student}
  \end{varwidth}%
  \hfill
  \begin{minipage}[b]{0.4\linewidth}
    \centering
    \includegraphics[width=40mm]{example-image}
    \captionof{figure}{2-D scatterplot of the Student Database}
    \label{fig:image}
  \end{minipage}
\end{table}

\end{document}
0
4

I would like to suggest taking an approach that preserves the ability to create cross-references to table and figure objects without rendering the associated numbers in cyan.

enter image description here

\documentclass{book}
\usepackage{graphicx,booktabs,xcolor}

%% new code:
\renewcommand\tablename{\textcolor{purple}{Table}}
\renewcommand\figurename{\textcolor{purple}{Figure}}
\usepackage[font=small,labelfont={color=cyan}]{caption}

\usepackage[noabbrev]{cleveref} % optional, for \cref macro

\begin{document}

\stepcounter{chapter} % just for this example

\begin{table}[ht!]
  \begin{minipage}[b]{0.5\linewidth}
    %\centering
    \begin{tabular}{@{} l r r @{}}
      \toprule
      Student & Hours/week & Grade \\
      \midrule
      Ada Lovelace & 2 & A \\
      Linus Thorvalds & 8 & A \\
      Bruce Willis & 12 & F \\
      Richard Stallman & 10 & B \\
      Grace Hopper & 12 & A \\
      Alan Turing & 8 & C \\
      Bill Gates & 6 & D \\
      Steve Jobs & 4 & E \\
      \bottomrule
    \end{tabular}
    \caption{Student Database}
    \label{table:student}
  \end{minipage}
  \hfill
  \begin{minipage}[b]{0.4\linewidth}
    %\centering
    \includegraphics[width=\linewidth]{example-image}
    \captionof{figure}{2-D scatterplot of the Student Database}
    \label{fig:image}
  \end{minipage}
\end{table}

Cross-references to table \ref{table:student} and figure \ref{fig:image}.

Cross-references to \cref{table:student,fig:image}.
\end{document}
3

Like this?

enter image description here

\documentclass{book}
\usepackage{graphicx}
\usepackage{booktabs}

\usepackage{xcolor}
\usepackage{caption}
\captionsetup{font=small,
              labelfont={color=purple}}
\DeclareCaptionLabelSeparator{colon}{\color{cyan}: }
\renewcommand\thetable{\textcolor{cyan}{\thechapter.\arabic{table}}}
\renewcommand\thefigure{\textcolor{cyan}{\thechapter.\arabic{table}}}

\begin{document}

\chapter{Chapter one}

\begin{table}[ht!]
  \begin{minipage}[b]{0.6\linewidth}
    \centering
    \begin{tabular}{ l r r }
      \toprule
      Student & Hours/week & Grade \\
      \midrule
      Ada Lovelace & 2 & A \\
      Linus Thorvalds & 8 & A \\
      Bruce Willis & 12 & F \\
      Richard Stallman & 10 & B \\
      Grace Hopper & 12 & A \\
      Alan Turing & 8 & C \\
      Bill Gates & 6 & D \\
      Steve Jobs & 4 & E \\
      \bottomrule
    \end{tabular}
    \caption{Student Database}
    \label{table:student}
  \end{minipage}%
  \hfill
  \begin{minipage}[b]{0.4\linewidth}
    \centering
    \includegraphics[width=40mm]{example-image}
    \captionof{figure}{2-D scatterplot of the Student Database}
    \label{fig:image}
  \end{minipage}
\end{table}

\end{document}

Edit: Now label separator has the same color as caption number.

3
  • Yes :). Thank you very very much.
    – Nehme
    Dec 5 '21 at 9:29
  • @Nehme, see edited answer. Now the colon has the same color as numbers.
    – Zarko
    Dec 5 '21 at 9:35
  • Yeees, thanks a lot. I like it so much. He's great like that.
    – Nehme
    Dec 5 '21 at 14:35

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.