2

I followed this QA link to left-align the equation and this to prefer using \hspace instead of \hskip:

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath,mathtools}
\usepackage[algosection, ruled, lined]{algorithm2e}
\usepackage{etoolbox,setspace}

\makeatletter \newenvironment{shiftedflalign*}{% \start@align\tw@\st@rredtrue\m@ne \hspace{-7pt} }{% \endalign } \makeatother

\begin{document}

\begin{algorithm} $c\coloneqq 0$ \begin{shiftedflalign} 1+1=2 && \end{shiftedflalign} \begin{shiftedflalign} 1+1=2 &&\ 1+1=2 \end{shiftedflalign}

\Return{$(x,y,z)$} \caption{removemarked()} \label{alg:removemarked} \end{algorithm} \end{document}

The rendered pdf where the linebreak seems to make the \hspace{-7pt} working for the 1+1=2 && fail: enter image description here

Other methods I have tried but also failed:

  1. alignat with all left-aligned
  2. \setlength{\mathindent}{0pt}

Q: How to tune the multiline equation with the self-defined indentation by something like flalign or others?

Edited:

To answer the Willie Wong's 2nd comment, the above tex is one example. My working tex code is to use many equations, so I use align here although I originally was to use the $$ mode. My purpose is to make these equations aligned to the rest context in the algorithm block, so I tried as the above shows.

Also as Willie Wong's 2nd comment says, the inline maths mode works for me.

An5Drama
  • 63
  • 6
  • 1
    The answer that you found is equivalent to putting a \hspace{-7pt} in front of the first line of an flalign*. You can check that if you also (manually) put \hspace{-7pt} at the start of the second line, then it "works". This is not an issue if you have a positive hspace, because the first column is to be right-aligned by the line that has the "longest" first column, and 0 is less than other positive numbers. – Willie Wong Nov 17 '23 at 07:36
  • Thanks for your answer. It works for me. – An5Drama Nov 17 '23 at 07:43
  • 1
    There's probably a better (more systematic) solution; but for it you will have to tell us what you wish to accomplish, and not what you have tried. (Specifically, why not just use inline equations? They are automatically flushleft.) – Willie Wong Nov 17 '23 at 07:46
  • The issue you are running into seems to be that \begin{flalign*} doesn't actually result in a flush-left output, and has a bit of space in front. This is specific to within \begin{algorithm} so something is adding an extra space/indent somewhere. – Willie Wong Nov 17 '23 at 07:48
  • Ok. I have edited my questions after seeing your comment. Hope it can help you understand my question. 2. To answer the 3rd comment by Willie Wong: yes, I refered to this result in some way in the edited contents.
  • – An5Drama Nov 17 '23 at 07:54
  • I thought maybe one \newcommand to create one new line command with \hspace{-7pt} preceded is enough to meet the above feature request (I will test it later). Then is there one elegant way to make \hspace{-7pt} work for all lines with just one global setting if not using \newcommand? If not, it is also enough for me to mark this question solved. – An5Drama Nov 17 '23 at 08:01