3

I want to have two equations, in two lines, the first the most at left, the second, the most at right:

equation 1  
      equation 2

So, the newbie in me try to do

\documentclass{article}
\begin{document}

\parbox{0.3\textwidth}{
  \[
    \begin{array}{l}
      equation 1\hfill\\
      \hfill equation 2
    \end{array}
  \]
}

\end{document}

which, of course, does not work.

I can replace the \hfill by a specific \hspace{size}, but it is not what I want: I want the space to be added to be calculated automatically.

One (horrible) way to make it work is the following:

\documentclass{article}

\newcommand{\twoEq}[2]{
  \begin{array}{p{\linewidth}}
    \(\displaystyle{#1}\hfill\)\\
    \(\displaystyle\hfill{#2}\)
  \end{array}
}
\begin{document}

\parbox{0.3\textwidth}{
  \[
    \twoEq{equation 1}{equation 2}
  \]
}

\end{document}

Can somebody propose a more elegant solution?

4
  • 2
    you might try multline from amsmath: \begin{multline*} equation 1 \\ equation 2 \end{multline*}. this uses the full page width, so you might want to put it into a minipage. May 27, 2014 at 12:39
  • 1
    array isn't really suitable for display equations, it sets each cell in inline mode and is designed for arrays/matrices. multline is designed for the layout you describe as indicated by barabara. May 27, 2014 at 12:42
  • @barbarabeeton Thanks! That is exactly what I was looking for! I added your comment as an answer, but please, fell free to add it by yourself and I remove mine. May 27, 2014 at 13:04
  • Your horrible workaround was actually the best (or only?) working option in my situation, so I would like to upvote your question as an answer. ;-) Just note that you should prevent the array from adding left and right margins, hence \begin{array}{@{}p{\linewidth}@{}} with @{} on the left and right sides of the array format specification.
    – Maëlan
    Mar 5, 2021 at 19:41

3 Answers 3

4

You can use multlined from the mathtools package:

\documentclass{article}
\usepackage{mathtools}

\begin{document}

\[
\begin{multlined}[.3\displaywidth]
  overlong equation 1\\
  overlong equation 2
\end{multlined}
\]

\end{document}

enter image description here

3
  • Great. Thanks! I still prefer Barbara's solution, just because I already use amsmath for other things, but it is nice to see that there are several elegant solutions. May 27, 2014 at 13:02
  • mathtools is an extention to amsmath. It even loads amsmath if you haven't already.
    – daleif
    May 27, 2014 at 13:04
  • I just realize that this solution is better, because it works even in a \[...\] environment, while multline doesn't. May 27, 2014 at 13:09
0
\documentclass{article}
\begin{document}

\parbox{0.3\textwidth}{
  \[
    \begin{array}{lr}
      equation 1 & \\
      & equation 2
    \end{array}
  \]
}

\end{document}
1
  • In this case you will have the first equation in the first column and the second in the second, which is not what I want. I want them to overlap. May 27, 2014 at 12:49
0

Barbara Beeton gave the following nice answer in a comment:

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\parbox{0.3\textwidth}{
  \begin{multline*}
    equation 1\\
    equation 2
  \end{multline*}
}

\end{document}
4
  • 2
    The \parbox should go inside \[...\] and a minipage seems better: \[\begin{minipage}{.3\textwidth}\begin{multline*}...\end{multline*}\end{minipage}\]
    – egreg
    May 27, 2014 at 13:03
  • Thanks, I removed the \[...\] directly, because they are not needed. May 27, 2014 at 13:06
  • Sorry, but they are necessary, unless you want your equation next to the left margin with the normal indent.
    – egreg
    May 27, 2014 at 13:08
  • Mmmm... but in that case you are using \[...\] for \begin{center}...\end{center}. The thing is that multline only work in text mode, not in math mode (that is way I accepted your answer as the best answer for this question, because multlined can be used even in mathmode). May 27, 2014 at 13:12

You must log in to answer this question.

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