0

In latex I defined a new environment called 'myequation'. Here for left hand side terms, their end points are aligned. I want to align center points of left hand side terms instead of their end points in addition to aligning the 'equal to' symbol. How can I modify my new environment to make this change. Also is it possible to make a page break in between some steps if I want and also put a particulat step in a box?

\documentclass[12pt, arrowdel]{article}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{amssymb}

\def\l{\left}
\def\r{\right}
\def\d{\mathrm{d}}
\def\pt{(\tau)}


%To align the equation number below for multiple line of equations
\newenvironment{myequation}{%
  \begin{equation}
  \begin{aligned}[b]
}{%
  \end{aligned}
  \end{equation}
}
\begin{document}

\begin{myequation}
    \dot{\rho} &= 3 \frac{\dot{a}}{a} \l(\rho + w \rho\r) =0\\
    \d \ln \rho &= -3\; \d \ln a (1+w(a))\\
    \int_{\rho_*}^{\rho} \d \ln \rho &= -3 \int_{a_*}^{a\pt}\d \ln a (1+w(a))\\
    \rho\pt  &= \rho_* e^{-3\int_{a_*}^{a\pt}\d \ln a (1+w(a))}
\end{myequation}
\end{document}

The image of the equations in 'myequation' environment

5
  • 1
    For center alignment, align(ed) is the wrog tool. You'll need an array.
    – campa
    Nov 3, 2023 at 12:16
  • 1
    Welcome to TeX.SE! Just curious, why you like to have math terms before equal sign centered? This appear (to my opinion, but I'm sure that at most people here, looks ugly :-(.
    – Zarko
    Nov 3, 2023 at 12:22
  • 2
    please fix your example, I added \begin{document} but it still errors with LaTeX Warning: Command \r invalid in math mode on input line 15. ! Please use \mathaccent for accents in math mode. \l is a slashed l and \r is a ring accent, you should at least redefine them or (much) better adjust the example not to use non standard definitions of core latex functions. It just makes it harder to test answers. Nov 3, 2023 at 12:24
  • In the final row, please, please replace e^{-3\int_{a_*}^{a\pt}\d \ln a (1+w(a))} with \exp\biggl(-3\int_{a_*}^{a\pt}\d \ln a (1+w(a))\biggr).
    – Mico
    Nov 3, 2023 at 12:48
  • thanks for the edit, but it's not good style to use \def it allows you to over-write core latex functionality with no warning, as here. Just hope you never need names such as Ångstrom in the bibliography as you have redefined that name to be an error. Nov 3, 2023 at 20:21

1 Answer 1

1

If I modify the example so that it produces output

enter image description here

Then you can add one extra \hfil into the preamble used by aligned so it centres, but the result is not really usable:

enter image description here

\documentclass[12pt]{article}
\usepackage{amsmath}

%To align the equation number below for multiple line of equations
\makeatletter
\newenvironment{myequation}{%
\renewcommand{\start@aligned}[2]{%eek centred lhs
    \RIfM@\else
        \nonmatherr@{\begin{\@currenvir}}%
    \fi
    \savecolumn@ % Assumption: called inside a group
    \alignedspace@left
      \ams@start@box{##1}\bgroup
        \maxfields@##2\relax
        \ifnum\maxfields@>\m@ne
            \multiply\maxfields@\tw@
            \let\math@cr@@@\math@cr@@@alignedat
            \alignsep@\z@skip
        \else
            \let\math@cr@@@\math@cr@@@aligned
            \alignsep@\minalignsep
        \fi
        \Let@ \chardef\dspbrk@context\@ne
        \default@tag
        \spread@equation % no-op if already called
        \global\column@\z@
        \ialign\bgroup
           &\column@plus
            \hfil
            \strut@
            $\m@th\displaystyle{####}$%
\hfil%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            \tabskip\z@skip
           &\column@plus
            $\m@th\displaystyle{{}####}$%
            \hfil
            \tabskip\alignsep@
            \crcr
          \ams@return@opt@arg
}%
  \begin{equation}
  \begin{aligned}[b]
}{%
  \end{aligned}
  \end{equation}
}
\makeatother

\begin{document}
\begin{myequation}
    \dot{\rho} &= 3 \frac{dot{a}}{a} (\rho + w \rho) =0\\
    d \log \rho &= -3\; d \log a (1+w(a))\\
    \int_{\rho_*}^{\rho} d \log \rho &= -3 \int_{a_*}^{ap}d \log a (1+w(a))\\
    \rho p  &= \rho_* e^{-3\int_{a_*}^{ap}d \log a (1+w(a))}
\end{myequation}
\end{document}
2
  • please fix that "dota". Nov 3, 2023 at 19:24
  • @barbarabeeton nah, it's irrelevant I just changed \d to d because the OP did not define it (I changed \ln to \log for same reason, so the math is all wrong anyway, it's just filler text Nov 3, 2023 at 19:26

You must log in to answer this question.

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