5

I am new to LaTeX,

Here is my formula,

Output

\documentclass{article}
\begin{document}
    \begin{equation}
        \small{
        \Delta (h)_{T+S} =
        \prod_{j=1}^{N} \left[\frac {P(x^j,y^j|\theta_{paired})} 
        {P(x^j,y^j|\theta_{unpaired})}\right]\left[\frac{P(bp)_{x^j,y^j} 
        P(bp_{x^j,y^j}|pbp_{x^{j-1},y^{j+1}}) P(dl_{x^j})  
        P(dl_{x^j}|pdl_{x^{j-1}})P(dr_{y^j})P(dr_{y^j}|pdr_{y^{j+1}})}{P(sl) 
        P(dl|sl) P(sr) P(dr|sr)}\right]}
    \end{equation}
\end{document}

I want the equation to be split over two lines, how can I do this? I tried, multline, align*, split, alignedat, nothing seems to work. Please help me with this. Thank you in advance.

  • 2
    Welcome to TeX.SE. – Sebastiano Jun 20 at 20:14
  • How wide is the textblock? (Alternatively, please tell us which paper size is employed, and how wide the margins are.) – Mico Jun 21 at 3:01
12

Here there is my proposal to split your equation.

EDIT: The slight change in my code is due an additional \cdot.

enter image description here

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{mathtools,amssymb}
\begin{document}
\begin{equation}
\begin{split}
\Delta (h)_{T+S} & =\prod_{j=1}^{N} \left[\frac {P(x^j,y^j|\theta_{\mathrm{paired}})} 
{P(x^j,y^j|\theta_{\mathrm{unpaired}})}\right] \\
& \cdot \left[\frac{P(bp)_{x^j,y^j} 
P(bp_{x^j,y^j}|pbp_{x^{j-1},y^{j+1}}) P(dl_{x^j}) P(dl_{x^j}|pdl_{x^{j-1}})P(dr_{y^j})P(dr_{y^j}|pdr_{y^{j+1}})}{P(sl) 
P(dl|sl) P(sr) P(dr|sr)}\right]
\end{split}
\end{equation}
\end{document}
  • 1
    Thank you so much, this works fine. – User Jun 20 at 20:14
  • 1
    This is unusual typesetting. You've put the line break in a sensible place, but I've never seen anybody write the operator on both lines. blah \cdot \\ blah or blah \\ \cdot blah are normal. – David Richerby Jun 21 at 14:35
  • 3
    @DavidRicherby blogs.msdn.microsoft.com/murrays/2007/09/01/… suggests that this is "popular in Russian mathematical typography". – Marcel Krüger Jun 22 at 9:18
8

The brackets are surplus here, the fraction is a group by itself, so you don't need extra grouping. If I use brackets, I will enclose the whole formula to the right of the = sign into a pair of brackets. I also used \biggl[ and \biggr] for easy splitting. Finally, as @Sebastiano suggested, use \mathrm for text.

Note: you didn't tell us how thick the margins are, so I assumed 1in. If my answer is still too wide, uncomment the \small block.

\documentclass{article}
\usepackage{amsmath}
\usepackage[margin=1in]{geometry}

\begin{document}

%{\small
\begin{equation}
\begin{split} \Delta (h)_{T+S} &= 
\prod_{j=1}^{N} \biggl[\frac {P(x^j,y^j|\theta_\mathrm{paired})} 
{P(x^j,y^j|\theta_\mathrm{unpaired})} \times{} \\
&\phantom{{}={}}\frac{P(bp)_{x^j,y^j} 
P(bp_{x^j,y^j}|pbp_{x^{j-1},y^{j+1}}) P(dl_{x^j})  
P(dl_{x^j}|pdl_{x^{j-1}})P(dr_{y^j})P(dr_{y^j}|pdr_{y^{j+1}})}{P(sl) 
P(dl|sl) P(sr) P(dr|sr)}\biggr]
\end{split}
\end{equation}
%}

\end{document}

enter image description here

  • 1
    I'm a little late for a positive vote on your good work. – Sebastiano Jun 20 at 20:52
  • 1
    Thank you, you were the fastest. – AboAmmar Jun 20 at 20:57
  • If possible, I'd push the second line to the right so it began to the right of the product sign. That would visually cue that it's a part of the product (though the brackets and the presence of $j$s in the second line do make this semantically clear). – David Richerby Jun 21 at 14:36
7

A way to put the equation on a single line, with the \splitfrac command from mathtools, the \medmath command from nccmath and some adjustment for the delimiters:

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{mathtools, nccmath, amssymb}

\begin{document}

\begin{equation}
\Delta (h)_{T+S} =\prod_{j=1}^{N} \left[\frac {P(x^j,y^j\mid\theta_{\mathrm{paired}})}
{P(x^j,y^j\mid\theta_{\mathrm{unpaired}})}\right]\cdot
 \left[\frac{\medmath{\splitfrac{P(bp)_{x^j,y^j}
P\bigl(bp_{x^j,y^j}\mid pbp_{x^{j-1},y^{j+1}}\bigr)P(dl_{x^j}) }{ P(dl_{x^j}\mid pdl_{x^{j-1}})P\bigl(dr_{y^j}\bigr)P\bigl(dr_{y^j}\mid pdr_{y^{j+1}}\bigr)\rule[-1.5ex]{0pt}{1ex}}}}{P(sl)
P(dl|sl) P(sr) P(dr| sr)^{\strut} }\right]
\end{equation}

\end{document} 

enter image description here

  • I know the command \splitfrac but I did not want to use it because it is not my favorite. +1 – Sebastiano Jun 20 at 20:59
  • 2
    @Sebastiano: I think it mainly depends on the case at hand. Here, combined with \medmath and some vertical space tweaking, I find it doesn't look so bad – Bernard Jun 20 at 21:04
  • De gustibus non disputandum est: There's no discussion of the tastes. :-) – Sebastiano Jun 20 at 21:10
  • 2
    Needless to translate – when I was a student, I helped some highschool students in Latin ;o) – Bernard Jun 20 at 21:16
5

one more alternative, with use of mathtools and nccmath:

\documentclass{article}
\usepackage{geometry}
\usepackage{mathtools, nccmath}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
    \begin{equation}
\medmath{
\begin{multlined}
\Delta (h)_{T+S}
    = \prod_{j=1}^{N} \Biggl[\frac{P(x^j,y^j\mid\theta_{\mathrm{paired}})}
                                 {P(x^j,y^j\mid\theta_{\mathrm{unpaired}})}\Biggr]\\
    \cdot \Biggl[\frac{P(bp)_{x^j,y^j} P(bp_{x^j,y^j}\mid pbp_{x^{j-1},y^{j+1}}) P(dl_{x^j}) P(dl_{x^j}\mid pdl_{x^{j-1}})P(dr_{y^j})P(dr_{y^j}|pdr_{y^{j+1}})}
                     {P(sl) P(dl\mid sl) P(sr) P(dr\mid sr)}\Biggr]
\end{multlined}
        }
    \end{equation}
\end{document}

enter image description here

  • 1
    Fast as lightning...:-) +1. – Sebastiano Jun 20 at 20:51
4

Here's a multlined-based solution. It also uses \mid rather than | to denote conditioning, and it "snugs up" the subscript terms to dr.

enter image description here

\documentclass{article}
\usepackage[a4paper,margin=2.5cm]{geometry} % make suitable page and margin choices
\usepackage{mathtools} % for 'multlined' environment

\begin{document}

\begin{equation}
\renewcommand{\!}{\mkern-2mu} % default: \mkern-3mu
\begin{multlined}
\Delta(h)_{T+S} = \prod_{j=1}^{N} \biggl[
\frac {P(x^j\!,y^j\mid \theta_{\mathrm{paired}})}{%
P(x^j\!,y^j\mid \theta_{\mathrm{unpaired}})}\\
\times
\frac{P(bp)_{x^j\!,y^j}
P(bp_{x^j\!,y^j}\mid pbp_{x^{j-1}\!,y^{j+1}}) 
P(dl_{x^j}) P(dl_{x^j}\mid pdl_{x^{j-1}})
P(dr_{\!y^j})P(dr_{\!y^j}\mid pdr_{\!y^{j+1}})}{%
P(sl) P(dl\mid sl) P(sr) P(dr\mid sr)} \biggr]
\end{multlined}
\end{equation}
\end{document}
4

With multiline one can insert \\ at the locations where the line should be broken.

Multiletter subscripts ought not be set in math italics, the kerning is wrong. I suggest to warp them in \mathrm{}

The fontsize change needs to be outside the equation and without {} following it. \small was still a bit to large, but with \footnotesize the equation fits even without cheating and changing the margin sizes.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

{
\footnotesize
\begin{multline}
\Delta (h)_{T+S} =
\prod_{j=1}^{N} \left[\frac {P(x^j,y^j|\theta_{\mathrm{paired}})} 
{P(x^j,y^j|\theta_{\mathrm{unpaired}})}\right]\cdot\\
\left[\frac{P(bp)_{x^j,y^j} 
P(bp_{x^j,y^j}|pbp_{x^{j-1},y^{j+1}}) P(dl_{x^j})  
P(dl_{x^j}|pdl_{x^{j-1}})P(dr_{y^j})P(dr_{y^j}|pdr_{y^{j+1}})}{P(sl) 
P(dl|sl) P(sr) P(dr|sr)}\right]
\end{multline}
}

\end{document}

enter image description here

  • 1
    Thanks you so much, this works fine as well. – User Jun 20 at 20:15
  • @ShilpaJanarthanan Was my pleasure! – gigi Jun 20 at 20:15
  • Can you please tell me, how to add \cdot in the above code, to show the continuity of the equation? – User Jun 20 at 20:24
  • @ShilpaJanarthanan Please check now. Also please don't have whole words in math italic. – gigi Jun 20 at 20:30

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.