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






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

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

الگوریتم ناحیه‌ی اعتماد یک روش برای حل مساله‌های بهینه‌سازی نامقید است. جزییات آن در الگوریتم \ref{alg:tr:classic} آمده است.
\caption{الگوریتم ناحیه‌ی اعتماد کلاسیک}
\hspace*{\algorithmicindent} \textsc{Classic-Trust-Region}(‎$f$, $\mathbf{x}_0$):
\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}]$

  • 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


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 .