I am trying to add a green box around the first two terms in my equation (beta_0 and b_i). I also want to add a circle around the second term (b_i). Is it possible to do this in LaTeX? My code is below which produces the equation. Any help would be great.


    \mathbf{Y_{ij}} = \beta_{0} +\mathbf{ b_i} + \beta_1x_1 + \ldots + \beta_nx_n + \mathbf{\epsilon_{ij}}


2 Answers 2


For complex drawings (circles, etc), you might need to go the tikz road.

But for simple shading of elements, a regular \colorbox should do, i.e.




    \mathbf{Y_{ij}} = \highlight{\beta_{0}} +\mathbf{ b_i} + \beta_1x_1 + \ldots + \beta_nx_n + \mathbf{\epsilon_{ij}}

which yields

highlight result

In case you want to do more than just highlight terms but are looking to explain the terms, I once wrote the following code for my master's thesis presentation:



        \color{#1}\centering\small #3\\%

    \mathbf{Y_{ij}} = \overwrite{\beta_{0}}{very important!} +\mathbf{b_i} + \beta_1x_1 + \ldots + \beta_nx_n + \mathbf{\epsilon_{ij}}

which this time yields:

overwrite result

You can even easily extend that code to fade the color from slide to slide and highlight one term at a time if you're using beamer (just add a \temporal<+> before the \stackrel, duplicate the \stackrel code three times and change the colors in each variant).


Complementing Xavier answer, if you want to highlight using circles, ellipses or more exotic shapes, here is some tikz MWE.


            $ \max_{\alpha_i\geq0}\sum_{1\leq i\leq n}\alpha_i-\frac12\sum_{1\leq i,j\leq n}\alpha_i\alpha_jy_iy_j
                \node[fill=red!25, ellipse, anchor=base]
                {$\langle\mathbf x_i,\mathbf x_j\rangle$};

enter image description here

  • 1
    Is there a way to modify this so that the shape more closely fits the expression it surrounds and doesn't introduce extra spacing, especially with an ellipse? I'm aware of tex.stackexchange.com/a/542997/218142 but that solution doesn't use TikZ. Nov 7, 2020 at 16:26

You must log in to answer this question.

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