1

Here’s an example of an equation I’m trying to align (I have lots throughout my 50-page NT paper):

$$\frac{5x^2}{4}+\frac{17x^4}{16}+\frac{65x^6}{64}+\frac{257x^8}{256}+\ldots \hspace{9.5cm}$$

I want to be able to get rid of the hspace.

It’d be really frustrating if all LaTeX has is this hspace thingy plus manual trial-and-error adjustments. And no, I don’t want to default left-alignment for all equations across the document, no.

Here’s my settings:

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{setspace}
\usepackage{amssymb}
\usepackage{indentfirst}
\usepackage[superscript]{cite}

Here’s the codes that are creating the centered formatting:

\[\frac{5x^2}{4}+\frac{17x^4}{16}+\frac{65x^6}{64}+\frac{257x^8}{256}+\ldots \]

\begin{flalign*}
\frac{5x^2}{4}+\frac{17x^4}{16}+\frac{65x^6}{64}+\frac{257x^8}{256}+\ldots 
\end{flalign*}

I'm editing this question, so @egreg sees my code, which is not working to create equation numbering:

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{nccmath}
\usepackage{setspace}
\usepackage{amssymb}
\usepackage{indentfirst}
\usepackage[superscript]{cite}
\usepackage{geometry}
\geometry{top=15mm,left=15mm}

\newenvironment{eqleft*}
 {\begin{equation*}}
 {\hspace{10000pt minus 1fil}\end{equation*}
\ignorespacesafterend}

\begin{document}
\begin{eqleft*}
\frac{5x^2}{4}+\frac{17x^4}{16}+\frac{65x^6}{64}+\frac{257x^8}{256}+\dotsb
\end{eqleft*}

\begin{ceqn}
\begin{align} \label{eq:eq:k_div_n_closed}
A=\sum_{j=1}^{k}\tan{\frac{2\pi nj}{k}} 
\end{align}
\end{ceqn}\\
\indent The above summation can be rewritten as a closed-form as follows:

\end{document}

First issue Second issue

Second issue First issue

2 Answers2

3

For a single left aligned equation (that is, not using fleqn), you can exploit flalign*, with more than one column.

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{lipsum} % for context

\begin{document}

\lipsum*[4]
\begin{flalign*}
\frac{5x^2}{4}+\frac{17x^4}{16}+\frac{65x^6}{64}+\frac{257x^8}{256}+\dotsb &&&
\end{flalign*}
\lipsum[5]

\end{document}

enter image description here

Note \dotsb rather than \ldots.

Actually, you can do it with \hspace and no guessing:

\[
\frac{5x^2}{4}+\frac{17x^4}{16}+\frac{65x^6}{64}+\frac{257x^8}{256}+\dotsb
\hspace{10000pt minus 1fil}
\]

would do. See https://tex.stackexchange.com/a/348745/4427

It's better, however, to define a proper environment:

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{lipsum} % for context

\newenvironment{eqleft}
 {\begin{equation*}}
 {\hspace{10000pt minus 1fil}\end{equation*}}

\begin{document}

\lipsum*[4]
\begin{eqleft}
\frac{5x^2}{4}+\frac{17x^4}{16}+\frac{65x^6}{64}+\frac{257x^8}{256}+\dotsb
\end{eqleft}
\lipsum[5]

\end{document}

The output is the same.

If you also want to be able to add equation numbers, define eqleft and eqleft*:

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{lipsum} % for context

\newenvironment{eqleft}
 {\begin{equation}\hspace{0pt}}
 {\hspace{10000pt minus 1fil}\end{equation}\ignorespacesafterend}
\newenvironment{eqleft*}
 {\begin{equation*}}
 {\hspace{10000pt minus 1fil}\end{equation*}\ignorespacesafterend}

\begin{document}

\lipsum*[4]
\begin{eqleft*}
\frac{5x^2}{4}+\frac{17x^4}{16}+\frac{65x^6}{64}+\frac{257x^8}{256}+\dotsb
\end{eqleft*}
\lipsum*[5]
\begin{eqleft}
\frac{5x^2}{4}+\frac{17x^4}{16}+\frac{65x^6}{64}+\frac{257x^8}{256}+\dotsb
\end{eqleft}
\lipsum[6]

\end{document}

enter image description here

egreg
  • 1,121,712
  • Using that creates a problem, which is the equation numbers disapper. I want to replace begin{equation} with flalign but keep the equation numbers. –  Aug 17 '18 at 17:13
  • @JRS. Didn't I answer the question in the edit? Not with equation, of course, but this should not be a problem. Please, avoid comments in all caps or boldface. – egreg Aug 17 '18 at 17:53
  • Your new code to add equation number doesn't work –  Aug 17 '18 at 18:42
  • And the visual pollution of the latin texts doesn't help either. –  Aug 17 '18 at 18:42
  • @JRS. I see the expected equation number. – egreg Aug 17 '18 at 19:10
  • @JRS. I've just tried the code example from this answer: I get equation numbers. If you are not seeing them with this code, then I guess we need to see your .log to see if there is a version issue. If you are not seeing them in your 'real' document, can you try to start from the demo and 'build up' until you can pin down the problematic part, so a suggestion can be made. – Joseph Wright Aug 17 '18 at 19:31
  • @egreg I've edited the OP to show my code, and I ran it, and it's not numbering the equation. –  Aug 17 '18 at 20:07
  • @JRS. You should notice that, in the final version eqleft numbers the equation, whereas eqleft* doesn't. If you use eqleft* it's obvious you don't get a number. – egreg Aug 17 '18 at 20:09
  • @egreg Yes, worked! –  Aug 17 '18 at 20:16
  • @egreg The only drawback is the fact the enhanced editor no longer displays the equations in green, as with the usual \begin{equation}. Is there a way to get that back? –  Aug 17 '18 at 20:32
  • @JRS. There are tens of “enhanced editors”. – egreg Aug 17 '18 at 20:37
  • @egreg Ok, thanks, I won't be too ambitious now, super happy I finally fixed that tough issue with your help :) –  Aug 17 '18 at 20:44
0

Check the following code, it should produce the desired result

\documentclass[12pt,fleqn]{article}
\usepackage{amsmath}
\usepackage{setspace}
\usepackage{amssymb}
\usepackage{indentfirst}
\usepackage[superscript]{cite}

\begin{document}

\[\frac{5x^2}{4}+\frac{17x^4}{16}+\frac{65x^6}{64}+\frac{257x^8}{256}+\ldots \]

\begin{flalign*}
\frac{5x^2}{4}+\frac{17x^4}{16}+\frac{65x^6}{64}+\frac{257x^8}{256}+\ldots 
\end{flalign*}


\end{document}
TeXnician
  • 33,589
execind
  • 21