1

I'm using tcolorbox to highlight equations in my document. Here's a typical use (I want the whole thing centered and pulled in a bit from the margins, so I start with a center environment, then displayquote, then a tcolorbox, then center the equation inside the box):

\begin{center}
  \begin{displayquote}
    \begin{tcolorbox}[colback=gray!5]
      \begin{center}
        \begin{equation}
          Ax = By
        \end{equation}
      \end{center}
    \end{tcolorbox}
  \end{displayquote}
\end{center}

Equation in box but with unwanted vertical space over it

This produces almost the right result, but there's a blank line in the box above the equation. I've tried a variety of things to get rid of that line (the most promising was \noindent, but the space remained). I'd like to have the same amount of vertical space above the equation as it currently has below, but I'd settle for centering it vertically.

Thanks for any assistance!

2
  • 4
    remove the inner center it is just adding vertical space, it is not centering the equation Mar 14, 2023 at 1:40
  • What is the minimal working example?
    – Sebastiano
    Mar 14, 2023 at 7:43

1 Answer 1

4

You will automatically get a much nicer spacing if you remove all the unnecessary center environments. If you want the tcolorbox to be smaller than the line width, you can change the left/right skip.

You can simplify things further by using the ams equation key, so your tcolorbox will automatically be an equation.

\documentclass{article}

\usepackage[most]{tcolorbox}

\begin{document}

\begin{tcolorbox}[colback=gray!5,left skip=1cm,right skip=1cm]
    \begin{equation}
      Ax = By
    \end{equation}
\end{tcolorbox}

\begin{tcolorbox}[colback=gray!5,ams equation,left skip=1cm,right skip=1cm]
      Ax = By
\end{tcolorbox}


\end{document}

enter image description here

2
  • Perfect! Thank you. And extra thanks for the extra bonus of the ams equation and skip options, both of which I've immediately adopted.
    – Eleeza
    Mar 14, 2023 at 17:30
  • @Eleeza You're welcome! Mar 14, 2023 at 17:32

You must log in to answer this question.

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