サイドバイサイドアルゴリズムで行を強調する

サイドバイサイドアルゴリズムで行を強調する

2 列の LaTeX テンプレート (IEEEtran) があり、そこに 2 つのアルゴリズムを並べて配置しています。

\documentclass[10pt,conference]{article}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{xcolor}
\def\HiLi{\leavevmode\rlap{\hbox to \hsize{\color{yellow!50}\leaders\hrule height .8\baselineskip depth .5ex\hfill}}}
\begin{document}


\begin{figure*}[htbp]
\centering
 \begin{minipage}[t]{0.49\textwidth}
    
  \begin{algorithm}[H]
        \caption{Foo}
        \begin{algorithmic}[1]
            \REQUIRE $Beer$
            \HiLi \STATE $s \leftarrow HighlightThis$
            \STATE $f \leftarrow Foo()$

        \end{algorithmic}
    \end{algorithm}
 \end{minipage}
 \begin{minipage}[t]{0.49\textwidth}
    
    \begin{algorithm}[H]
        \caption{Bar}
        \begin{algorithmic}[1]
            \REQUIRE $Wine$\\
            \STATE $s \leftarrow Bar()$
            \STATE $b \leftarrow Bar1()$
        \end{algorithmic}
    \end{algorithm}
    \vfill
 \end{minipage}
\end{figure*}

\end{document}

私の目標は、「HighlightThis」という行を強調表示することです。次の 2 つを試しました。アプローチ1TikZアプローチ

問題は、どちらのアプローチでもハイライトが完全に間違った位置に置かれてしまうことです。アプローチ 1 の結果: ここに画像の説明を入力してください

どうすればいいでしょうか?ご協力ありがとうございます

答え1

これがあなたの目指すものなのですか?

\HiLi コマンドを変更して、\hsize の代わりに \linewidth を使用するようにし、アルゴリズム内の \HiLi コマンドの配置を移動しました。以下を参照してください。

\documentclass[10pt,conference]{article}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{xcolor}
\def\HiLi{\leavevmode\rlap{\hbox to \linewidth{\color{yellow!50}\leaders\hrule height .8\baselineskip depth .5ex\hfill}}}
\begin{document}


\begin{figure*}[htbp]
\centering
 \begin{minipage}[t]{0.49\textwidth}
    
  \begin{algorithm}[H]
        \caption{Foo}
        \begin{algorithmic}[1]
            \REQUIRE $Beer$
            \STATE \HiLi $s \leftarrow HighlightThis$
            \STATE $f \leftarrow Foo()$
        \end{algorithmic}
    \end{algorithm}
 \end{minipage}
 \begin{minipage}[t]{0.49\textwidth}
    
    \begin{algorithm}[H]
        \caption{Bar}
        \begin{algorithmic}[1]
            \REQUIRE $Wine$\\
            \STATE $s \leftarrow Bar()$
            \STATE $b \leftarrow Bar1()$
        \end{algorithmic}
    \end{algorithm}
    \vfill
 \end{minipage}
\end{figure*}

\end{document}

関連情報