1

I want to apply background color to a particular line within an algorithm. Based on this, I have the MWE:

\documentclass{article}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\usepackage[usenames,dvipsnames,svgnames]{xcolor}
    \begin{document}
        \begin{minipage}[t]{.49\textwidth}
            \null   
            \begin{algorithm}[H]
                \caption{Puda}\label{puda}
                \begin{algorithmic}[1]
                    \State \colorbox[RGB]{239,240,241}{Hu}
                    \State Hu
                    \Return 
                \end{algorithmic}
            \end{algorithm}
        \end{minipage}
    \end{document}

and the output:

I want that the rest of the line is filled with the same background color (marked in yellow). Any idea?

1

Here is some solution with manual tweaks. The macro \colorline wraps its content inside a \colorbox and corrects some alignment issues.

\documentclass{article}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\usepackage[usenames,dvipsnames,svgnames]{xcolor}
\setlength{\fboxsep}{1pt}
\newcommand{\colorline}[1]{
\hspace{-0.03\linewidth}\colorbox{gray!30}{\makebox[0.99\linewidth][l]{Hu}}
 }

    \begin{document}
        \begin{minipage}[t]{.49\textwidth}
            \null   
            \begin{algorithm}[H]
                \caption{Puda}\label{puda}
                \begin{algorithmic}[1]
                    \State \colorline{Hu}
                    \State Hu
                    \Return 
                \end{algorithmic}
            \end{algorithm}
        \end{minipage}
    \end{document}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.