I know that if you pass fleqn
as an option, all amsmath
's environments becomes left aligned, including gather
, however, along with that, they become flushleft.
Actually, what I'm trying to create is a left aligned gather
environment that would be horizontally centered relatively to the page. fleqn
is not what I need, because I want to keep the default behavior of environments, but I found a way to temporarily turn this option on. The question is about how I can center my leftceq
environment without using additional packages as etoolbox
?
There is a dirty workaround with align
environment that makes me put &
at the beginning of each line that's drastically inconvenient with lots of math equations.
\documentclass{article}
\usepackage{mathtools}
\mathtoolsset{showonlyrefs=true}
\usepackage{showframe}
\makeatletter
\newenvironment{leftceq}{
\@fleqntrue%
\gather%
}{%
\endgather
}
\makeatother
\begin{document}
\verb|my environment|
\begin{leftceq}
y_1 = C_1e^{-4x}+C_2e^{-5x}+C_3xe^{-5x}\\
y_2 = C_1e^{6x}+C_2e^{-9x}\cos x+C_3e^{-9x}\sin x
\end{leftceq}\\
\verb|desired result, faked with align environment|
\begin{align}
&y_1 = C_1e^{-4x}+C_2e^{-5x}+C_3xe^{-5x}\\
&y_2 = C_1e^{6x}+C_2e^{-9x}\cos x+C_3e^{-9x}\sin x
\end{align}\\
\verb|default gather|
\begin{gather}
y_1 = C_1e^{-4x}+C_2e^{-5x}+C_3xe^{-5x}\\
y_2 = C_1e^{6x}+C_2e^{-9x}\cos x+C_3e^{-9x}\sin x
\end{gather}
\end{document}
Best Answer
Use the “fake” but making it automatic.
This splits the environment's content at
\\
and places&
in front of every line when passing the lines toalign
.Bad version asked in comments
I cannot recommend doing this, because if it turns out that the numbered version is necessary, one has to duplicate the code. And separating the user interface from the internal code is a plus, besides being the recommended way.
If you want to support nested alignments such as
cases
, I'm afraid you have to do it the hard way.This is a fast (and quite likely it can be improved) modification of the
amsmath
code.