12

enter image description here

I'm just trying to build the formula shown below in Latex. My approach would be the following: prob[ \tilde{n}=n \mid \tilde{s}=s] However, the first two n's are not displayed correctly. Does anyone know what is wrong about my approach? (absolute Latex beginner)

  • 3
    $\operatorname{prob}[\tilde{n} = n \mid \tilde{s} = n] = p > \frac{1}{2}$ with package amsmath (screenshot). – Henri Menke Apr 22 '18 at 21:32
  • 1
    What's wrong with your ns? The formula you've given is different than your attempt. Also, it's helpful if you give a complete minimal working example with your code, that starts with \documentclass and ends with end{document}. – Teepeemm Apr 23 '18 at 12:44
22
\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator\prob{prob}
\begin{document}
\(
\prob[\tilde{n}=n\mid\tilde{s}=n] =p > \frac{1}{2}
\)
\end{document}

enter image description here

  • 9
    The OP is using the correct \tilde{n} syntax; while \tilde n also works it's worse markup. – egreg Apr 22 '18 at 21:47
  • 1
    @egreg I find this highly subjective. – Konrad Rudolph Apr 23 '18 at 11:15
  • 3
    @KonradRudolph amsmath fixes no bug, it just reimplements all the math accents. Since the original \tllde command has no argument, the syntax \tilde x is not well defined. Look at page 291 of the TeXbook for the syntax of \mathaccent and page 289 for <math field> to discover why \tilde\notin fails. – egreg Apr 23 '18 at 12:24
  • 3
    Why does this simple answer get 17 votes? Sometimes, I don't understand the psychology of this site...but I'm not complainin' – Steven B. Segletes Apr 23 '18 at 13:45
  • 2
    @Steven: It's probably because the question showed up in the "Hot Network Questions" list for some reason, so it is getting a lot of traffic. – Rahul Apr 23 '18 at 18:28
11

With a code adapted from an example in mathtools documentation. The \prob macro can make the size of the brackets and midrule fit the contents of the macro using the starred version \prob*. Alternatively one can use an optional argument: \big, \Big, \bigg,\Bigg, which inserts a pair of implicit \bigl ... \bigr before the delimiters:

\documentclass{article}

\usepackage{mathtools, nccmath}
\providecommand\given{}
\DeclarePairedDelimiterXPP\prob[1]{\mathrm{prob}}[]{}{
\renewcommand\given{\nonscript\:\delimsize\vert\nonscript\:\mathopen{}}
#1}

\begin{document} %

\[ \prob[\big]{\tilde{n} = n\given\tilde{s} = n} = p > \mfrac12\]%

\end{document} 

enter image description here

8

An alternative that sizes the brackets and the vertical bar automatically to the content between them is to use \left, \middle and \right. This uses egreg’s trick for a vertical bar that grows.

\documentclass[preview,varwidth]{standalone}

\usepackage{amsmath}
\usepackage{unicode-math}

\DeclareMathOperator\prob{prob}

\ifdefined\Umiddle
  \newcommand{\relmiddle}{\Umiddle class 5 }
\else
  \newcommand{\relmiddle}[1]{\mathrel{}\middle#1\mathrel{}}
\fi

\begin{document}
\(
\prob \left[ \tilde{n} = \frac{n^{2^m}}{2} \relmiddle\vert \tilde{s} = n \right] = p > \frac{1}{2}
\)
\end{document}

Equation

This example will work with your font packages of choice, not just unicode-math. And you can still declare \prob with two arguments.

2

The following works for me very well even though Steven B. Segletes has a perfect answer. I have changed n to n/2 for better visibility on the height of the mid line.

\begin{equation}
\operatorname{prob} \left[\left. \tilde{n}=\frac{n}{2}  \right| \tilde{s}=n\right] =p > \frac{1}{2}
\end{equation}

enter image description here I have added \left. before the fraction to enforce the height of the mid line to be that of the height of the fraction.

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.