3

I want to write an equation in latex like the following one. enter image description here

But I can not align a set of numbers with the coefficients completely. Here's my code:

\begin{equation}
\begin{aligned}
LNEP = & -0.23LNEER & +1.21LNCOST & +1.50LNFD & -1.03LNCP & -9.44 \\
& (0.12) & (0.13) & (0.27) & (0.37) & (1.33)
\end{aligned}
\end{equation}

And it looks like this: enter image description here

Could somebody help me pls? Many thanks.

  • Welcome to TeX.SX! Please make your code snippet an MWE, with emphasis on working. It should start with \documentclass and end with \end{document}. – schtandard Aug 19 at 22:52
4

You can use alignedat.

\documentclass{article}

\usepackage{amsmath}

% Change the multiplication symbol to a centered dot.
\let\xtimes\times
\let\times\cdot

\begin{document}

\begin{equation}
  \begin{alignedat}{5}
    \mathrm{LNEP} 
    = -0&.23 \times \mathrm{LNEER} &{}
    + 1&.21 \times \mathrm{LNCOST} &{}
    + 1&.50 \times \mathrm{LNFD} &{}
    - 1&.03 \times \mathrm{LNCP} &{}
    - 9&.44 \\
    (0&.12)&
    (0&.13)&
    (0&.27)&
    (0&.37)&
    (1&.33)
  \end{alignedat}
\end{equation}

\end{document}

MWE output

Please not the changes I made to your code.

  • The names (if you have to use multi-letter variables) should be in \mathrm.
  • I think implicit multiplication looks confusing with those names, better use it explicitly.
  • The {} between & and + or - ensures the correct spacing around the operators.
  • Unlike your example image, I aligned the numbers at the decimal point.
  • 3
    Rather use {}+ and {}- to have the proper spacing around binary operators. – Werner Aug 19 at 23:28
  • 1
    @Werner Thanks for the hint. – schtandard Aug 20 at 6:51
  • Thanks for your detailed answer. Really helps me a lot. – Tianyi Chen Aug 21 at 10:56
2

Your forgot that n alignment points require 2n–1 ampersands. I propose a solution with alignedat{5}, and another, simpler, with stackengine, which requires no alignment points:

\documentclass{article}
\usepackage{geometry}
\usepackage{mathtools}
\usepackage[usestackEOL]{stackengine}
\newcommand{\mystackunder}[2] {\stackMath\stackunder{#1}{\mathclap{#2}}}

\begin{document}

\begin{equation}
\begin{alignedat}[t]{5}
LNEP = -0.23&LNEER &{} +1.21 & LNCOST &{} +1.50 & LNFD &{} -1.03 & LNCP &{} -9.44 & \\
 (0.12) & & (0.13) & & (0.27) & & (0.37) & & (1.33)
\end{alignedat}
\end{equation}
\bigskip

\begin{equation}%
LNEP = \mystackunder{-0.23}{(0.12)} LNEER +\mystackunder{1.21}{ (0.13)}LNCOST +\mystackunder{1.50}{(0.27)} LNFD -\mystackunder{1.03}{(0.37)} LNCP -\mystackunder{9.44}{(1.33)}
\end{equation}

\end{document} 

enter image description here

  • Thanks for your answer. – Tianyi Chen Aug 21 at 10:56
2

Keep together the coefficient and the accuracy. This allows for making the parentheses having zero width. Between the coefficient and the variable I added a thin space for better clarity.

\documentclass{article}
\usepackage{amsmath}

\newcommand{\cfac}[2]{% coefficient with accuracy
  \begingroup\renewcommand{\arraystretch}{0.7}%
  \begin{array}[t]{@{}r@{}}#1\\\makebox[0pt][r]{$($}#2\makebox[0pt][l]{$)$}\end{array}%
  \endgroup
}
\newcommand{\tvar}[1]{\mathrm{#1}}

\begin{document}

\begin{equation}
\tvar{LNEP} =
\cfac{-0.23}{0.12}\,\tvar{LNEER} + \cfac{1.21}{0.13}\,\tvar{LNCOST} +
\cfac{1.50}{0.27}\,\tvar{LNFD}   - \cfac{1.03}{0.37}\,\tvar{LNCP}   - \cfac{9.44}{1.33}
\end{equation}

\end{document}

enter image description here

  • Thanks for your answer. – Tianyi Chen Aug 21 at 10:56

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.