2

I'm looking for a method to improve my current command:

\newcommand{\deq}[2][]{\begin{tcolorbox}[
    colback = blizzardblue!30!white, colframe = white,
    top = -0.3cm, bottom = 0.1cm]\begin{flalign}
        \text{\bfseries #1} && #2 & &
    \end{flalign}\end{tcolorbox}
}

that produces

enter image description here

What I want to improve is to be allowed to write a second title for the equation. Using a table, I get this:

enter image description here

but I couldn't find a way to center horizontally and vertically the equation. The code for the table is this:

\begin{tcolorbox}[
    colback = blizzardblue!30!white, colframe = white]
    \begin{tabularx}{\textwidth}{Lcr}
        \bfseries Clausius's Theorem 
        & $\dps\sideset{_R}{}\oint \frac{\dbar Q}{T} = 0$ & \refstepcounter{equation}(\theequation) \\
        \bfseries Part of the Second Law of Thermodynamics
    \end{tabularx}
\end{tcolorbox}

I'm using this packages:

\usepackage[italicdiff]{physics}
\usepackage[scr = rsfso]{mathalfa} 
\usepackage{mathtools} 
\usepackage{amssymb}

\usepackage{xcolor} \definecolor{blizzardblue}{rgb}{0.4, 0.6, 0.8} \usepackage{tcolorbox} \tcbuselibrary{skins, breakable, hooks, theorems}

The best answer to the question must contain the equation centered (horizontally and vertically) and a command (like the one I wrote) to produce the table/environment with 3 arguments: #1 equation (mandatory) and, if it's possible, #2 primary title (optional) and #3 secundary title (optional). I don't know if this possible to have more than one optional argument. Thanks for reading and for you help!

Peluche
  • 613

1 Answers1

4

I'd set the second part outside the flalign.

\documentclass{article}
\usepackage[italicdiff]{physics}
\usepackage[scr = rsfso]{mathalfa} % para \mathscr
\usepackage{mathtools} % si molesta sacar.
\usepackage{amssymb}

\usepackage{xcolor} \usepackage{tcolorbox} \tcbuselibrary{skins, breakable, hooks, theorems}

\definecolor{blizzardblue}{rgb}{0.4, 0.6, 0.8}

% https://tex.stackexchange.com/a/282196/4427 \newcommand{\dbar}{{d\mkern-7mu\mathchar'26\mkern-2mu}}

\NewDocumentCommand{\deq}{omo}{% \begin{tcolorbox}[ colback = blizzardblue!30!white, colframe = white, ] \setlength{\abovedisplayskip}{0pt} \begin{flalign} \IfValueT{#1}{\textbf{#1}} && #2 && \end{flalign} \IfValueT{#3}{\bfseries #3} \end{tcolorbox} }

\begin{document}

\deq[Clausius's Theorem] {\sideset{_R}{}\oint \frac{\dbar Q}{T} = 0}

\deq[Clausius's Theorem] {\sideset{_R}{}\oint \frac{\dbar Q}{T} = 0} [Part of the Second Law of Thermodynamics]

\end{document}

enter image description here

egreg
  • 1,121,712
  • Why are you using \NewDocumentCommand instead of \newcommand? It's better? – Peluche Feb 07 '23 at 14:19
  • 1
    @Peluche With it I can define two optional arguments. – egreg Feb 07 '23 at 14:20
  • 1
    @Peluche \newcommand is a limited way to define new commands. In general, you should prefer \NewDocumentCommand in all circumstances. Among other things, commands defined with \newcommand that have optional arguments will break if they appear in any sectioning command. – Don Hosek Feb 07 '23 at 14:28