6

I'm trying to put three equations in the same line.

I used the tabularx package as was advised by this post: How to place and number 3 short equations in one line?.

However since I am using equation with different heights, they do not align well vertically.

I manage to solve this using \vspace but I would like to know if there is a more elegant solution. Here is the code I used:

\documentclass[11pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{tabularx}
\usepackage[margin=0.25in]{geometry}
\begin{document}

\noindent\begin{tabularx}{\textwidth}{@{}XXX@{}}
  \vspace{0.1mm}
  \begin{equation}
    Euc(P,Q)= \left( \sum_{i=1}^n \left| p_i - q_i \right|^2 \right)^{1/2}
    \label{eqn:1}
  \end{equation} &
  \vspace{1.5mm}
  \begin{equation}
    Canb(P,Q)=\sum_{i=1}^n \frac{|p_i-q_i|}{|p_i|+|q_i|}
    \label{eqn:2}
  \end{equation} &
  \vspace{5.8mm}
  \begin{equation}
    Man(P,Q)=\sum_{i=1}^n |p_i-q_i|
    \label{eqn:3}
  \end{equation}
\end{tabularx}
\end{document}

enter image description here

  • Two equation numbers in the same row are bad style; three are … ;-) The line is very cluttered and makes it difficult to see the numbers themselves. – egreg Feb 16 '14 at 22:28
8

To place three numbered equations next to one another, you could use the multicols environment, which is provided by the multicol package. In the example below, using this environment makes it unnecessary to fiddle with various tabular-like environments or experiment with \vspace adjustments.

enter image description here

Incidentally, using \left( ... \right) to enclose a summation symbol with limits tends to generate parentheses that are far too large, typographically speaking. Better to use \biggl( ... \biggr) in such cases. (This is not only my prescription; you may find it in the TeXbook as well.)

\documentclass[11pt,a4paper]{article}
\usepackage{mathtools,multicol}
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\DeclareMathOperator{\Euc}{Euc}
\DeclareMathOperator{\Canb}{Canb}
\DeclareMathOperator{\Man}{Man}
\usepackage[margin=0.4in]{geometry}
\begin{document}
\begin{multicols}{3}
\begin{equation}
\Euc(P,Q)= \biggl( \sum_{i=1}^n \abs{ p_i - q_i }^2 \biggr)^{1/2}
    \label{eqn:1}
\end{equation}

\begin{equation}
\Canb(P,Q)=\sum_{i=1}^n \frac{\abs{p_i-q_i}}{\abs{p_i}+\abs{q_i}}
    \label{eqn:2}
\end{equation}

\begin{equation}
\Man(P,Q)=\sum_{i=1}^n \abs{p_i-q_i}
    \label{eqn:3}
\end{equation}
\end{multicols}
\end{document}
  • Wow, didn't know about the multicol package. Thank you for the parenthesis tip as well! – Pedro Dreyer Feb 15 '14 at 14:31
2

What you are trying to do doesn't look nice IMHO; I would just use

\documentclass{scrbook}

\usepackage{mathtools}

\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\DeclareMathOperator*{\Euc}{Euc}
\DeclareMathOperator*{\Canb}{Canb}
\DeclareMathOperator*{\Man}{Man}

\begin{document}

\begin{align}
 \label{eqn:1}
  \Euc(P,Q)  &= {\mkern -6mu}\left(\sum_{i = 1}^n \abs*{p_i - q_i}^2\right)^{\mkern -6mu 1/2},\\
 \label{eqn:2}
  \Canb(P,Q) &= \sum_{i = 1}^n \frac{\abs*{p_i - q_i}}{\abs*{p_i} + \abs*{q_i}},\\
 \label{eqn:3}
  \Man(P,Q)  &= \sum_{i = 1}^n \abs*{p_i - q_i}.
\end{align}

\end{document}

output

  • Sorry, but the first code example that I posted was wrong, so you would get a very ugly layout indeed. Please see the corrected example. – Pedro Dreyer Feb 15 '14 at 14:13

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.