3

I have a 2 column latex template (IEEEtran), in which I put 2 algorithms side by side:

\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}

My goal is to highlight the line "HighlightThis". I've tried these 2: Approach1, TikZ Approach.

The problem is with both approaches, the highlight gets completely misplaced: Approach 1 result: enter image description here

How can this be done? Thanks for your help

dv3
  • 143
  • Please tell us how or where \HiLi is defined. – Mico Aug 25 '20 at 18:58
  • @Mico this comes from the mentioned approach 1, I edited the question to make the code compilable, including the approach. I mainly need one of the approaches to work, I can also gladly use TikZ if it's possible then – dv3 Aug 25 '20 at 19:04

1 Answers1

2

Is this what you're going for?

I changed the \HiLi command to use \linewidth instead of \hsize and moved the \HiLi command placement in the algorithm. See below:

\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}