0

I am trying to insert colored boxes into my caption like below.

enter image description here

But my code below does not align the colored boxes with the text. How can I automatically align them with the text?

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{tikz}
\usepackage{float}
\usepackage{subfig}

\title{test}
\author{test}%

\date{January 2022}

\begin{document}

\maketitle

\begin{figure}
$A^{L}$ \includegraphics[width=0.3\columnwidth,height=0.25cm]{example-image-a} $A^{R}$ \includegraphics[width=0.3\columnwidth,height=0.25cm]{example-image-a}\\
$\hat{A}^{L}$ \includegraphics[width=0.3\columnwidth,height=0.25cm]{example-image-a} $\hat{A}^{R}$ \includegraphics[width=0.3\columnwidth,height=0.25cm]{example-image-a}\\
$\hat{A}^{L}$ \includegraphics[width=0.3\columnwidth,height=0.25cm]{example-image-a} $\hat{A}^{R}$ \includegraphics[width=0.3\columnwidth,height=0.25cm]{example-image-a}
\caption{Qualitative results for recognition. Stir \colorbox{red!80}}
\end{figure}

\end{document}
1
  • Your MWE contain error: syntax for \collorbox is \colorbox{<color>}{<content>}. Instead of use a \colorbox is define new command as is better to define new command as is done in @Simon Dispa answer.
    – Zarko
    Commented Feb 27, 2022 at 15:11

1 Answer 1

5

Try this code. It was added a command \Cbox{<color>} that puts a framed colored square on the baseline.

d

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{tikz}
\usepackage{float}
\usepackage{subfig}

\title{test}
\author{test}%

\date{January 2022}

\newcommand{\Cbox}[1]{\setlength{\fboxsep}{0pt}\fbox{\color{#1}\rule{2ex}{2ex}}} % added <<<<<<<<<<<
    
\begin{document}

\maketitle

\begin{figure}[ht!]
    \centering
    $A^{L}$ \includegraphics[width=0.3\columnwidth,height=0.25cm]{example-image-a} $A^{R}$ \includegraphics[width=0.3\columnwidth,height=0.25cm]{example-image-a}\\
    $\hat{A}^{L}$ \includegraphics[width=0.3\columnwidth,height=0.25cm]{example-image-a} $\hat{A}^{R}$ \includegraphics[width=0.3\columnwidth,height=0.25cm]{example-image-a}\\
    $\hat{A}^{L}$ \includegraphics[width=0.3\columnwidth,height=0.25cm]{example-image-a} $\hat{A}^{R}$ \includegraphics[width=0.3\columnwidth,height=0.25cm]{example-image-a}
    \caption{Qualitative results for recognition: \Cbox{red!80}~stir, \Cbox{green}~lift,  \Cbox{gray!50}~idle,  \Cbox{yellow}~hold, \Cbox{blue!30}~approach.}
\end{figure}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .