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

2
  • Please tell us how or where \HiLi is defined.
    – Mico
    Aug 25, 2020 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, 2020 at 19:04

1 Answer 1

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}
4
  • Yes! Well, like 99%... If I use this on a if-else, only the conditional check gets highlighted, not the "if" itself...
    – dv3
    Aug 26, 2020 at 14:41
  • Not sure. Probably need to play around with the \HiLi command... Aug 26, 2020 at 14:54
  • @dv3 Can you add a MWE for that case?
    – Simd
    Aug 26, 2020 at 18:37
  • @Anush it's vitalstatistix code, but applied not only to a state line, but also to a \IF line...
    – dv3
    Aug 26, 2020 at 21:14

You must log in to answer this question.

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