2

I have an equation and i want to right align it:

\documentclass{report}
\usepackage{amsmath,amsfonts,amsthm,bm} %math

%----------------------------------------
%Align Equations to LEFT MARGIN (use \mathleft then \mathcenter)
\makeatletter
\newcommand{\mathleft}{\@fleqntrue\@mathmargin0pt}
\newcommand{\mathcenter}{\@fleqnfalse}
\makeatother
%----------------------------------------

\begin{document}
\begin{align}
center
\end{align}
\mathleft
\begin{align}
left
\end{align}
\end{document}

I have an awesome piece of code that allows me to leftalign with \mathleft, is it possible to have one that right align?

enter image description here

  • 2
    Please, just don't. – Henri Menke Apr 25 '18 at 4:32
  • What should this alternation mean? Is it just for academic curiosity? – egreg Apr 25 '18 at 6:41
  • @egreg I really got something in which thing was right next to the equation number, but now I'm on a different machine and can't reproduce it. I'll therefore remove my comments. – user121799 Apr 25 '18 at 16:14
  • @egreg I'm back home at my machine, and posted an illustration below. Either my TeXLive is broken, I am drunk, or I have a point. – user121799 Apr 25 '18 at 23:16
5

Of course you can, though not without reading the TeXbook (Exercise 19.8). Look at the final example, though, which could be what you're looking for.

\documentclass{article}
\usepackage{amsmath}

\usepackage{lipsum}

\begin{document}

\lipsum*[2]
\begin{equation}
\hfilneg \text{left} \hspace{10000pt minus 1fil}
\end{equation}
\lipsum*[2]
\begin{equation}
\text{center}
\end{equation}
\lipsum*[4]
\begin{equation}
\hspace{10000pt minus 1fil} \text{right} \hfilneg
\end{equation}
But I guess you want something like this final example,
because ``right aligning'' equations has generally no
use:
\begin{multline}
\text{the first part of a very long equation,
      that is set flush left} \\
\text{the final part, also quite long, set flush right}
\end{multline}

\end{document}

enter image description here

  • I was thinking about separating the equation in 2 environments, however, as you predicted, multiline did the job. – Vitor Abella Apr 25 '18 at 19:04
1

NOT AN ANSWER. Hello @egreg, when I compile

\documentclass{report}
\usepackage{amsmath,amsfonts,amsthm,bm} %math

%----------------------------------------
%Align Equations to LEFT MARGIN (use \mathleft then \mathcenter)
\makeatletter
\newcommand{\mathleft}{\@fleqntrue\@mathmargin0pt}
\newcommand{\mathcenter}{\@fleqnfalse}
\makeatother
%----------------------------------------

\begin{document}
\begin{align}
center
\end{align}
\mathleft
\begin{flalign}
left
\end{flalign}
\begin{equation}
\hfill right
\end{equation}
\end{document}

I get

enter image description here

  • Using \mathleft to get right alignment is cheating! ;-) – egreg Apr 26 '18 at 8:27
  • @egreg This was already in the OP's code. So I made the comment that (s)he could use \hfill, and tested it before. And what's wrong with cheating? ;-) – user121799 Apr 26 '18 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.