5

is it possible to color in red part of a text and/or of a caption (let's say, just some words)?

I tried to create the environment:

\newenvironment{redtext}{\color{red}}{\ignorespacesafterend}

following this reference. However, it cannot be used for captions.

Thank you.

1
  • Which class file are you used minimal or article and could you please post MWE. – Balaji Sep 4 '13 at 9:37
9

For captions you can use the interface provided by the »caption« package. Have a look at this approach derived from Section 4 of the package manual.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{caption}
\usepackage{xcolor}

\DeclareCaptionFont{red}{\color{red!50!black}}
\DeclareCaptionFont{green}{\color{green!50!black}}
\captionsetup{
  labelfont={bf,red},
  textfont={green}
}

\begin{document}
  \begin{figure}[!htb]
    \centering
    \rule{8cm}{4.5cm}
    \caption{Dummy figure}
  \end{figure}
\end{document}

It should be no big deal to apply that in your document.


enter image description here


Update

For only parts of the caption you can use the \textcolor command. It's suggestive to define a new command in this case.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{xcolor}

\newcommand{\alert}[1]{\textcolor{red}{#1}}

\begin{document}
  \begin{figure}[!htb]
    \centering
    \rule{8cm}{4.5cm}
    \caption{This is a \alert{Dummy figure}}
  \end{figure}
\end{document}

enter image description here

2
  • What if I have to color just part of a caption (let's say, some words)? I think the method you are proposing is coloring the whole caption. – Eleanore Sep 4 '13 at 9:45
  • 1
    @Eleanore: Then you can simply use \textcolor{red}{Colored text} as described in Section 2.6 of the »xcolor« manual. Somehow I must have misinterpreted your question. – Thorsten Donig Sep 4 '13 at 9:48

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.