1

I am trying in every way to find all the possibilities to best center the first equation in a subequations environment. I can't use the option alignat because the colored enumeration (here there is the full code of @Werner An elegant aspect for enumerate the equations of a book)

\documentclass{book}

\usepackage{mathtools}
\usepackage[svgnames, dvipsnames, table, x11names]{xcolor}
\usepackage{pifont}

\definecolor{ocre}{RGB}{243,102,25} 
%----------------------------------------------------------------------------------
%   Change number equations with sections
%----------------------------------------------------------------------------------
\usepackage{chngcntr}
\counterwithin{equation}{section}

\renewcommand{\theequation}{\thesection-\arabic{equation}}
\newcommand{\eqnnumsymbol}{\textcolor{ocre}{\reflectbox{\ding{228}}}}

\makeatletter
\newtagform{bbrackets}% <name>
  [\textbf]% Internal style
  {(}% Left bracket
  {\ifnum\pdfstrcmp{\@currenvir}{equation}=0
     \eqnnumsymbol%
   \else
     \ifnum\pdfstrcmp{\@currenvir}{align}=0
       \eqnnumsymbol%
     \fi
   \fi
   )}% Right bracket
\makeatother
\usetagform{bbrackets}

\begin{document}

See both~\eqref{eq:eqn1} and~\eqref{eq:eqn2}. Also see~\eqref{eq:eqn3}.

\begin{equation}
  \oint \mathbf{E} \cdot d \mathbf{a} = \int \rho \, \mathrm{d}v \label{eq:eqn1}
\end{equation}

\begin{equation}
  \oint \mathbf{B} \cdot d \mathbf{a} =  \mathbf{0} \label{eq:eqn2}
\end{equation}

\begin{align}
  abc \label{eq:eqn3}
\end{align}

\end{document}

disappears in my book.

enter image description here

I tried to reverse the symbols of & or to add it, but nothing to do. Do you have any suggestions? Thank you all.

I am adding the MWE and the screenshot.

enter image description here

\documentclass[a4paper,12pt]{article}
\usepackage{amsmath,amssymb}
\begin{document}
\begin{subequations}
\begin{align}
\overline {F} &=-\overline{\nabla}U(\bar{r})+ \overline{\nabla} \times \overline{W}(\bar{r}) \label{Undec}\\
U(\bar{r})&=\frac1{4\pi}\int_{\mathcal{V}}\frac{D(\bar{r}')}{R}dV', \quad \overline{W}(\bar{r})=\frac1{4\pi}\int_{\mathcal{V}}\frac{\overline{C}(\bar{r}')}{R}dV' \label{Undec1}
\end{align}
\end{subequations}
\end{document}

ADDENDUM

With gather option I obtain this:

enter image description here

Sebastiano
  • 54,118
  • Your code asks to align at the = signs, is it not a requirement? Or do you expect both equations to be moved to the right? – frougon Jul 23 '19 at 21:28
  • @frougon No, no, it's not important to align the two subequations. If the first equation was aligned to the left with the first one of the second equation, aesthetically I don't think we have a good visibility. – Sebastiano Jul 23 '19 at 21:31
  • So, you don't mind if the equal signs are not aligned, correct? – frougon Jul 23 '19 at 21:32
  • @frougon Correct your question of the comment. The important thing is that it is aesthetically beautiful to see and centered, and that I do not disappear the numbers with the style of the colorful image. – Sebastiano Jul 23 '19 at 21:33
  • Did you add a gather possibility to your bbrackets code? It looks like that would be needed to get the red arrow in the tag. (gather really is the structure that you want here, as @frougon has answered.) – barbara beeton Jul 24 '19 at 02:20
  • @barbarabeeton I hope the translator has done a good translation. frougon was great. unfortunately my code structure where there is the preamble is very long and I thought that something did not work. The compilation is perfect but as you can see it eliminates me, with the new code, all the formatting of the numbers. See image in chat. – Sebastiano Jul 24 '19 at 11:31
  • @frougon Unfortunately with the new code, all the elegant formatting of the numbers disappears. I chatted the image to barbara beeton and you'll find it in the list. Don't worry, it's okay so I'll put a \qquad if it works. :-) – Sebastiano Jul 24 '19 at 11:34
  • @Sebastiano I don't see any list. Apart from “the elegant formatting of the numbers disappears”, I know nothing about the problem you are talking about. As you could see, the code I posted shows the tags the same way as in your first image, so... – frougon Jul 24 '19 at 12:26
  • @frougon There was into chat an image othe lack of symbols near the enumeration. Your work hase been perfect (see message to barbara beeton), impeccable. Surely there's something I don't understand inside my long code that creates conflict with gather and even with multiline that I tried a few minutes ago. I want to thank you for your help and I'm sure you have and will have my trust, in respect, in the good manners I have in my heart. Thanks again and I assure you that you are a good user. – Sebastiano Jul 24 '19 at 15:56
  • @Sebastiano As Graham Chapman said, “I have no quarrel with you, good Sir knight.” :-) (and I have no bridge to cross!) Anyway, my suggestion would be to make a copy of your long document and trim it progressively to make it closer and closer to one of my examples with the arrows. At some point, you should see the “bad behavior” appear; then be careful, rewind and you should find the precise thing that causes the bad behavior (if it's really complicated, Git may help to avoid getting lost between the various versions). – frougon Jul 24 '19 at 19:59
  • If you don't see “bad behavior” appear, you should be able to derive a “continuous path” from one of the simple examples with desired presentation to your book, that should help. I'm still puzzled you have a problem with this, because the code doesn't use any internal macro from other packages, and not even new concepts in the version with redundant code, as compared to what you had before—apart from gather, which I don't really consider as a new concept... – frougon Jul 24 '19 at 20:10
  • @frougon With all my heart, I thank you so much. I don't like to be satisfied and to tell lies. I prefer to be what I am: water and soap, that is simple. You can't imagine the joints in my code. It could simply be a shift of the macro and everything could work. I've never questioned your code. It's easier to find a needle in a haystack than to handle my code. Always thank you and return the help. – Sebastiano Jul 24 '19 at 21:39

1 Answers1

3

If you don't need the equations to be aligned at the equal signs, then I believe the gather environment does what you want:

\documentclass{article}
\usepackage{amsmath}

% From egreg: <https://tex.stackexchange.com/a/501075/73317>
\newcommand{\diff}{\mathop{}\!\mathrm{d}}

\begin{document}

\begin{subequations}
\begin{gather}
\overline{F} = - \overline{\nabla}U(\bar{r}) +
               \overline{\nabla} \times \overline{W}(\bar{r}) \label{Undec}\\
U(\bar{r}) = \frac{1}{4\pi} \int_{\mathcal{V}} \frac{D(\bar{r}')}{R} \diff V',
\quad
\overline{W}(\bar{r}) =
  \frac{1}{4\pi} \int_{\mathcal{V}} \frac{\overline{C}(\bar{r}')}{R} \diff V'
  \label{Undec1}
\end{gather}
\end{subequations}

\end{document}

Screenshot

Note that I removed the & before the equal signs (no alignment tabs in gather). I also used a \diff command from egreg for the differential.

Here is the same with your red arrows in equation tags. First using the same technique to check the environment name (there is a lot of redundancy, we'll remove it below):

\documentclass{article}
\usepackage{mathtools}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{pifont}

% From egreg: <https://tex.stackexchange.com/a/501075/73317>
\newcommand{\diff}{\mathop{}\!\mathrm{d}}

\definecolor{ocre}{RGB}{243,102,25}
\counterwithin{equation}{section}

\renewcommand{\theequation}{\thesection-\arabic{equation}}
\newcommand{\eqnnumsymbol}{\textcolor{ocre}{\reflectbox{\ding{228}}}}

\makeatletter

\newtagform{bbrackets}% <name>
  [\textbf]% Internal style
  {(}% Before
  {\ifnum\pdfstrcmp{\@currenvir}{equation}=0
     \eqnnumsymbol
   \else
     \ifnum\pdfstrcmp{\@currenvir}{align}=0
       \eqnnumsymbol
     \else
       \ifnum\pdfstrcmp{\@currenvir}{gather}=0
         \eqnnumsymbol
       \fi
     \fi
   \fi
   )}% After

\makeatother

\usetagform{bbrackets}

\begin{document}

\section{First section}

\begin{subequations}
\begin{gather}
\overline{F} = - \overline{\nabla}U(\bar{r}) +
               \overline{\nabla} \times \overline{W}(\bar{r}) \label{Undec}\\
U(\bar{r}) = \frac{1}{4\pi} \int_{\mathcal{V}} \frac{D(\bar{r}')}{R} \diff V',
\quad
\overline{W}(\bar{r}) =
  \frac{1}{4\pi} \int_{\mathcal{V}} \frac{\overline{C}(\bar{r}')}{R} \diff V'
  \label{Undec1}
\end{gather}
\end{subequations}

\end{document}

Now, do the environment name check inside \newtagform{bbrackets}[...]{...}{...} in a more elegant way, so that you just have to add the environments in which you want equation tags to have the red arrow to a comma list (see the \forcsvlist{...}{equation, align, gather} line below).

\documentclass{article}
\usepackage{mathtools}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{pifont}
\usepackage{etoolbox}

% From egreg: <https://tex.stackexchange.com/a/501075/73317>
\newcommand{\diff}{\mathop{}\!\mathrm{d}}

\definecolor{ocre}{RGB}{243,102,25}

\counterwithin{equation}{section}
\renewcommand{\theequation}{\thesection-\arabic{equation}}
\newcommand{\eqnnumsymbol}{\textcolor{ocre}{\reflectbox{\ding{228}}}}

\makeatletter

% Helper macro used to insert the arrow symbol from pifont if the current
% environment (\@currenvir) is in the list passed to \forcsvlist.
\newcommand*{\@usearrowifsame}[2]{%
  \ifstrequal{#1}{#2}{\eqnnumsymbol\listbreak}{}%
}

\newtagform{bbrackets}% <name>
  [\textbf]% Internal style
  {(}% Before
  {% Insert the red arrow from pifont in the equation tag when we are inside
   % one of the environments listed in the second argument.
   \forcsvlist{\expandafter\@usearrowifsame\expandafter{\@currenvir}}%
              {equation, align, gather}%
   )}% After

\makeatother

\usetagform{bbrackets}

\begin{document}

\section{First section}

\begin{subequations}
\begin{gather}
\overline{F} = - \overline{\nabla}U(\bar{r}) +
               \overline{\nabla} \times \overline{W}(\bar{r}) \label{Undec}\\
U(\bar{r}) = \frac{1}{4\pi} \int_{\mathcal{V}} \frac{D(\bar{r}')}{R} \diff V',
\quad
\overline{W}(\bar{r}) =
  \frac{1}{4\pi} \int_{\mathcal{V}} \frac{\overline{C}(\bar{r}')}{R} \diff V'
  \label{Undec1}
\end{gather}
\end{subequations}

\end{document}

Screenshot

frougon
  • 24,283
  • 1
  • 32
  • 55