5

In my document, I have a block of 3 equations that need to be aligned on the = sign. This is the code:

 \documentclass[a4paper, 11pt]{book}
 \usepackage{amsmath}
 \begin{document}

    \begin{alignat}{2}
      &\text{xxxxxxx1}       &&= 1/y  \\
      &\text{x2} &&=y      \\
      &\text{x3}       &&=y^2+x2
   \end{alignat}

\end{document}

However, I'd also like this block of equations to be left-aligned. Instead, with that code, it is centered on the page.

In a related post, someone suggested to use fleqn as a document class. Nevertheless, I cannot use that, because some of the equations in my document have to be centered, not all of them have to be left-aligned.

  • You want just these three to be aligned on the left margin, but still numbered at the right margin? – Steven B. Segletes Sep 14 '18 at 19:33
  • Yes, exactly. All equations in my document are numbered at the right margin, but I do not want all of them to be aligned at the left margin – Mary Sep 14 '18 at 19:35
6

it is not very clear to me what you like to obtain, so below are two options which cross my mind:

  • in the first is used flalign math environment from the amsmath package
  • in second the gather environment (also from amsmat) is enclosed in fleqn environment proviedad by he package nccmath

enter image description here

(red lines indicate text borders)

     \documentclass[a4paper, 11pt]{book}
    \usepackage{amsmath}
    \usepackage{nccmath}

    %---------------- show page layout. don't use in a real document!
    \usepackage{showframe}
    \renewcommand\ShowFrameLinethickness{0.15pt}
    \renewcommand*\ShowFrameColor{\color{red}}
    %---------------------------------------------------------------%

     \begin{document}

        \begin{flalign}
    \text{xxxxxxx1}  &= 1/y     &\\
    \text{x2}        &= y       &\\
    \text{x3}        &= y^2+x2  &
       \end{flalign}

    or

        \begin{fleqn}
        \begin{gather}
    \text{xxxxxxx1}  = 1/y      \\
    \text{x2}        = y        \\
    \text{x3}        = y^2+x2
        \end{gather}
       \end{fleqn}

    \end{document}

edit: from your comments follows that you like to have something like this:

enter image description here

\documentclass[a4paper, 11pt]{book}
\usepackage{amsmath}
\usepackage{nccmath}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}

\begin{fleqn}
\begin{alignat}{2}
&\text{xxxxxxx1} &&= 1/y      \\
&\text{x2}       &&= y        \\
&\text{x3}       &&= y^2+x2
\end{alignat}
\end{fleqn}

\end{document}
  • The first option is the most similar to what I'd like to obtain; however I'd like to also have x2 and x3 aligned at the left margin – Mary Sep 14 '18 at 20:41
  • this means, that you like to big space between left side of equations and = sign? – Zarko Sep 14 '18 at 20:45
  • Exactly. I cannot manage to do that with alignat, nor with flalign – Mary Sep 14 '18 at 20:53
  • 1
    I took the liberty of simplifying the last code also to get the spacing right. ;-) – egreg Sep 14 '18 at 21:13
  • @egreg, thank you very much. i now is better! – Zarko Sep 14 '18 at 21:15
3

A solution not really completely automated, but you can do your job till find a completed automated method:

\documentclass[a4paper, 11pt]{book}
\usepackage{amsmath}
\usepackage{lipsum}

\newsavebox{\mylongbox}
\newsavebox{\mybox} 
\newcommand{\longer}[1]{\savebox\mylongbox{\hbox{$#1$}}}
\newcommand{\forceLeft}[1]{\savebox{\mybox{$#1$}}\usebox{\mybox}\hspace{\dimexpr\wd\mylongbox-\wd\mybox}}

\begin{document}
\lipsum[2]

%Store the longer item
\longer{\text{xxxxxxx1}}
        \begin{flalign}
    \text{xxxxxxx1}  &= 1/y     &\\
%Use \forceleft command for the others
    \forceLeft{\text{x2}}      &= y       &\\
    \forceLeft{\frac{1}{3}\cdot x_2}        &= y^2+x2  &
       \end{flalign}


\end{document}

enter image description here

  • You are welcome Mary. – koleygr Sep 15 '18 at 11:39

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.