如何将颜色框与我的文本对齐?

如何将颜色框与我的文本对齐?

我正在尝试将彩色框插入到我的标题中,如下所示。

在此处输入图片描述

但是下面的代码没有将彩色框与文本对齐。我怎样才能自动将它们与文本对齐?

在此处输入图片描述

\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

试试这个代码。它添加了一个命令\Cbox{<color>},将带框的彩色方块放在基线上。

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}

相关内容