0

I want to have a colored box within an algorithm environment. I use tcolorbox within an algorithm environment. The result is shown below. I use the before skip balanced=-0.075cm and after skip balanced=-0.075cm options to remove the white space between the colored box and the top and bottom rules. Surprisingly, this only works for the bottom rule and not the top rule. As you can see there is a white space gap between the the colored box and the top rule. I am wondering if there is a nice way to handle this?

enter image description here

\documentclass{article}

\usepackage[dvipsnames]{xcolor}
\usepackage[most]{tcolorbox}

\usepackage{setspace}

\usepackage{algorithm}
\usepackage[noend]{algpseudocode}

\usepackage[extrafootnotefeatures]{xepersian}

\settextfont{Persian Modern}
\setdigitfont{Persian Modern} 
\setlatintextfont[Scale=0.9]{TeX Gyre Heros}

\algnewcommand{\LineComment}[1]{\State {\color{ForestGreen} \(\triangleright\) #1}}
\newcommand\norm[1]{\lVert#1\rVert}
\newtcolorbox{algBox}{sharp corners, before skip balanced=-0.075cm, after skip balanced=-0.075cm, boxrule=0pt, frame hidden}

\begin{document}
الگوریتم ناحیه‌ی اعتماد یک روش برای حل مساله‌های بهینه‌سازی نامقید است. جزییات آن در الگوریتم \ref{alg:tr:classic} آمده است.
\begin{algorithm}[b!]
\caption{الگوریتم ناحیه‌ی اعتماد کلاسیک}
\label{alg:tr:classic}
\begin{algBox}
\begin{latin}
\setstretch{1}
\hspace*{\algorithmicindent} \textsc{Classic-Trust-Region}(‎$f$, $\mathbf{x}_0$):
\begin{algorithmic}[1]
\LineComment{Initialization}
\State Set maximum value for trust region radius $\Delta_{\max} > 0$
\State Set an initial trust region radius $\Delta_0 \in (0, \Delta_{\max})$
\State Set $\eta \in [0, \frac{1}{4}]$
\end{algorithmic}
\end{latin}
\end{algBox}
\end{algorithm}

\end{document}
2
  • 1
    You could try before=\vspace*{-0.075cm} instead, but I am unsure whether this is the best way to solve this. Mar 21 at 14:44
  • @JasperHabicht: It worked! Another trick that worked is adding \usepackage[skip=0cm]{caption} to preamble. Mar 21 at 15:05

1 Answer 1

0

Use before=\vspace*{-0.075cm} instead of before skip balanced=-0.075cm. Another way is to add \usepackage[skip=0cm]{caption} to preamble.

You must log in to answer this question.

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