2

How can I align the blue texts?

enter image description here

\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}

\begin{document}

\begin{flalign*}
&\color{red}f:x^2+y^2=4,\qquad \color{blue}f(3)=2&\\
&\color{red}g:x^2-y^2=2,\qquad \color{blue}g(4)=1&
\end{flalign*}

\end{document}
5
  • Are you in two-column mode?
    – Bernard
    Oct 10, 2021 at 8:56
  • No. I drew the black lines later @Bernard
    – cufcuf
    Oct 10, 2021 at 8:57
  • 1
    Why using flalign for such a small equation, in this case?
    – Bernard
    Oct 10, 2021 at 9:04
  • When I use align, the equation starts from the middle. I used flalign because I wanted the equation to start from the left @Bernard
    – cufcuf
    Oct 10, 2021 at 9:06
  • 4
    using an alignment and not specifying any alignment points other than the leftmost edges is very weird though Oct 10, 2021 at 9:22

3 Answers 3

4

I suggest to use the fleqn environment from nccmath, which works somewhat like subequations, and the alignat* environment, which gives you full control on the spacing between the alignment columns:

\documentclass{article}
\usepackage{amsmath, nccmath}
\usepackage{xcolor}
\usepackage[showframe]{geometry}

\begin{document}

\mbox{}\bigskip
\begin{fleqn}
\begin{alignat*}{2}
\color{red}f:x^2+y^2 & =4, & \qquad\color{blue}f(3) & =2\\
\color{red}g:x^2-y^2 & =2, & \color{blue}g(4) & =1
\end{alignat*}
\end{fleqn}

\end{document} 

enter image description here

2

Is that what You need?

enter image description here

\documentclass{article}
\usepackage{amsmath}
\usepackage[dvipsnames]{xcolor}

\begin{document}

\begin{flalign*}
\color{red}f:x^2+y^2=4,\qquad \textcolor{blue}{f(3)=2}\\
\color{red}g:x^2-y^2=2,\qquad \textcolor{blue}{g(4)=1}
\end{flalign*}

\end{document}
2

I'm not sure what's the reason for left alignment. Either you left align every display or none. Anyway, here's code for obtaining precise alignments.

I use array rather than aligned or variants thereon because it allows easier methods for setting colors and respect the spacings.

\documentclass{article}
\usepackage{amsmath}
\usepackage{array}
\usepackage{xcolor}

\begin{document}

\noindent X\dotfill X
\begin{flalign*}% I see no reason for this...
  &% for flalign to work as wanted
  \setlength{\arraycolsep}{0pt}
  \renewcommand{\arraystretch}{1.2}
  \begin{array}{
    >{\color{red}}r
    >{\color{red}{}}c<{{}}
    >{\color{red}}l
    @{\qquad}
    >{\color{blue}}r
    >{\color{blue}{}}c<{{}}
    >{\color{blue}}l
  }
  f &:& x^2+y^2=4, & f(3) &=& 2 \\
  g &:& x^2-y^2=2, & g(4) &=& 1
  \end{array}
  &% for flalign to work as wanted
\end{flalign*}

\end{document}

enter image description here

Without flalign*, which is quite a sledgehammer,

\documentclass{article}
\usepackage{amsmath}
\usepackage{array}
\usepackage{xcolor}

\begin{document}

\noindent X\dotfill X
\[
  \setlength{\arraycolsep}{0pt}
  \renewcommand{\arraystretch}{1.2}
  \hspace{0pt} % glue is needed at the beginning
  \begin{array}{
    >{\color{red}}r
    >{\color{red}{}}c<{{}}
    >{\color{red}}l
    @{\qquad}
    >{\color{blue}}r
    >{\color{blue}{}}c<{{}}
    >{\color{blue}}l
  }
  f &:& x^2+y^2=4, & f(3) &=& 2 \\
  g &:& x^2-y^2=2, & g(4) &=& 1
  \end{array}
  \hspace{1000pt minus 1fill} % pretend this is very wide, but shrinkable to fit
\]

\end{document}

Of course it's simpler if you don't need colors.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\noindent X\dotfill X
\[
\hspace{0pt}
\begin{alignedat}{2}
  f &: x^2+y^2=4, &\qquad f(3) &= 2 \\
  g &: x^2-y^2=2, &\qquad g(4) &= 1
  \end{alignedat}
  \hspace{1000pt minus 1fill}
\]

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .