1

I'm trying to put a text on the right side under an equation in LaTeX.

Here is my code:

\begin{dmath}
\mbox{log-likelihood ratio} = A \log{ \left( \frac{A/(A+B)}{(A+C)/N} \right) } + 
B \log{ \left( \frac{B/(A+B)}{(B+D)/N}  \right)} +
C \log{ \left( \frac{C/(C+D)}{(A+C)/N}  \right)} +
D \log{ \left( \frac{ D/(C+D) }{ (B+D)/N }  \right)} 
\end{dmath}

where $N = A + B + C + D

Here's the result:

enter image description here

I want "where N = A + B + C + D" to be under the equation on the right side. How to do that?

migrated from stackoverflow.com Jul 21 '13 at 23:43

This question came from our site for professional and enthusiast programmers.

  • try /hfill before the where statement – Raystafarian Jul 21 '13 at 12:14
  • How do you want the equation number aligned with the addition of your "where" clause? – Werner Jul 21 '13 at 16:30
  • Welcome to TeX.sx! Your post was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. – Werner Jul 22 '13 at 5:35
1

As pointed out in the comments, you can place \hfill before the "where" statement, which will push that statement all the way to the right. This will align it flush right with the equation number, however.

If you wish to avoid the "where" statement being aligned with the equation number, you can use \hphantom{...} to add horizontal space at the end of the "where" statement to make it look as if it 'belongs' to the equation. The picture immediately below has been cropped so you can better compare these two approaches. The picture on bottom used \hpantom{(2)} at the end of the "where" statement to add that extra horizontal space so that it is not immediately below the equation number.

enter image description here

Of course, if you end up moving equations around and equation number (1) becomes, say, equation number (10), then you will have to manually redefine all of the \hpantom{...} commands. You can avoid this by using the \label{...} and \eqref{...} commands of amsmath.

Here is an MWE that will always get the horizontal spacing correct, regardless of the equation number. (And, of course, if you do want the "where" statement to be all the way flush with the right margin, then just delete the \hpantom{...} command.)

\documentclass{article}

\usepackage{amsmath} % needed for \label and \eqref commands to work; must be loaded before breqn
\usepackage{breqn}

\begin{document}

\begin{dmath}
\label{eq:log-likelihood} % used for getting the horizontal space right inside of the \hphantom command, regardless of equation number
\mbox{log-likelihood ratio} = A \log{ \left( \frac{A/(A+B)}{(A+C)/N} \right) } + 
B \log{ \left( \frac{B/(A+B)}{(B+D)/N}  \right)} +
C \log{ \left( \frac{C/(C+D)}{(A+C)/N}  \right)} +
D \log{ \left( \frac{ D/(C+D) }{ (B+D)/N }  \right)}
\end{dmath}

\hfill where $N = A + B + C + D$\hphantom{\eqref{eq:log-likelihood}}

\end{document}

enter image description here

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.