1

I trying to align a programming model using eqnarray but the command \tag do not work with it, I could use align instead but the alignment is right for the first column and left for the second column.

So what I want to do is use the eqnarray alignment (which is right for the first column and centered for the second column) with align.

This is how both commands look like:

enter image description here

  • Welcome to TeX SX! No =sign (or < or …) between the two ‘columns’? – Bernard Aug 27 '18 at 0:23
  • Nope, that's why I don't want the right-left alignment – GuadalupeAnimation Aug 27 '18 at 0:26
  • Centred w.r.t. what? And should the first column be aligned? – Bernard Aug 27 '18 at 0:33
  • I added a picture so you can see what the problem is – GuadalupeAnimation Aug 27 '18 at 0:42
  • the way you are using `eqnarray – barbara beeton Aug 27 '18 at 1:22
3

Here is a solution using \mathmakebox from the mathtools package:

\documentclass{article}
\usepackage{mathtools}% loads `amsmath'
\DeclareMathOperator*{\Max}{Max}
\begin{document}
A solution with \verb|\mathmakebox|:
\begin{alignat}{2}
           \Max_t & \quad & F(t) = at, \\
\text{subject to} &       & \mathmakebox[\widthof{$F(t) = at,$}][c]{t \le b,} \\
                  &       & \mathmakebox[\widthof{$F(t) = at,$}][c]{t \ge 0.}
\end{alignat}
\end{document}

makebox

  • 1
    (+1) I had completely forgotten this command (much more recent than eqparbox)! – Bernard Aug 27 '18 at 1:47
2

Here are two possibilities with alignat and eqparbox:

\documentclass{article}
\usepackage{mathtools}
\usepackage{eqparbox}
\newcommand{\eqmathbox}[2][M]{\eqmakebox[#1]{$\displaystyle#2$}}

\begin{document}

\begin{alignat}{2}
  \max_t & &\quad & \eqmathbox{F(t) = at}\\
 \text{subject to}& &
 & \eqmathbox{\begin{gathered}[t]
 t\le b, \\t\ge 0.
 \end{gathered}}
\end{alignat}
\begin{alignat}{2}
  \max_t & &\quad & \eqmathbox{F(t) = at}\\
 \text{subject to}& &
 & \eqmathbox{t \le b,} \\
  & & & \eqmathbox{t \ge 0.}
\end{alignat}

\end{document} 

enter image description here

  • is the mathtools package only needed with gathered? – GuadalupeAnimation Aug 27 '18 at 1:12
  • 1
    It is a very useful extension of amsmath (which would be enough for this code), deeply recommended. B.t.w., eqnarray shouldn't be used any more, as it leads to bad spacings. – Bernard Aug 27 '18 at 1:16

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.