在並排演算法中突出顯示線

在並排演算法中突出顯示線

我有一個 2 列乳膠模板 (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個:方法1,TikZ 方法

問題在於這兩種方法,亮點都完全錯位了: 方法 1 結果: 在此輸入影像描述

如何才能做到這一點?感謝您的協助

答案1

這就是你想要的嗎?

我將 \HiLi 命令更改為使用 \linewidth 而不是 \hsize,並移動了演算法中的 \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}

相關內容