General ⇒ vertical bar for conditional expectation
vertical bar for conditional expectation
E \left( Y \vert X \right)
...the complication is that frequently Y (sometimes X) is a tall expression, like a fraction, and I would like \vert to comform to the size of the taller of Y or X.
I was surprised that I couldn't find anything on the web for this since many people must have run into it. Any suggestions? Or pre-existing commands in amslatex that I'm not aware of? Thanks!
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
vertical bar for conditional expectation
Code: Select all
E\left(X \left\vert \dfrac{X}{Z} \right. \right)- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
vertical bar for conditional expectation
Code: Select all
\left\vert\right.Code: Select all
\left\vert\vphantom{\frac{1}{1}}\right.Code: Select all
\newcommand{\xcmd}[2]{\left(#1\,\left\vert\vphantom{#1#2}\right. #2\right)}Test the new command by inserting a normal expression and a fracture or only two normal expressions as arguments. I'm sure there is better method to realise this but for the present it should the job.
Best regards
Thorsten
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
vertical bar for conditional expectation
Code: Select all
E\left(X \middle\vert \dfrac{X}{Z} \right)
E\left( \dfrac{X}{Z} \middle\vert Y \right)Re: vertical bar for conditional expectation
$E\left(X\middle\vertY\right)$
That construct is implemented in the braket package, which defines a\Set command. You might do the same to implement an \expectation command, to avoid typing the \left, \right and \middle primitives (or ask the author of braket, Donald Arseneau, to do so and add it to braket).
Regards,
B.A.
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
vertical bar for conditional expectation
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: vertical bar for conditional expectation
vertical bar for conditional expectation
- \bigl - \bigm - \bigr
- \Bigl - \Bigm - \Bigr
- \biggl - \biggm - \biggr
- \Biggl - \Biggm - \Biggr
There are many cases in which the above commands should replace the \left - \right ones, mainly when the latter yield too big delimiters and when there are several delimiters together. Just a simple example: I find better this
Code: Select all
\[ \lambda \bigl( (x_1,x_2) + (y_1,y_2)\bigr) = \lambda (x_1,x_2) + \lambda (y_1,y_2) \]Code: Select all
\[ \lambda ( (x_1,x_2) + (y_1,y_2) ) = \lambda (x_1,x_2) + \lambda (y_1,y_2) \]
\[ \lambda \left( (x_1,x_2) + (y_1,y_2)\right) = \lambda (x_1,x_2) + \lambda (y_1,y_2) \]
Code: Select all
\[ E ( X \vert Y ) \]Code: Select all
\[ E ( X \mid Y ) \]Code: Select all
\[ E\left( X \middle\vert \dfrac{X}{Z} \right) \quad
E\left( \dfrac{X}{Z} \middle\vert Y \right) \]Code: Select all
\[ E\biggl( X \biggm\vert \dfrac{X}{Z} \biggr) \quad
E\biggl( \dfrac{X}{Z} \biggm\vert Y \biggr) \]To be complete, there also exist the commands \big, \Big, \bigg and \Bigg, which can be used before any delimiter. Look at this:
Code: Select all
\[ E\bigg(X \bigg\vert \dfrac{X}{Z} \bigg) \quad
E \bigg( \dfrac{X}{Z} \bigg\vert Y \bigg) \]To help typesetting, I propose the following command:
Code: Select all
\newcommand{\expectation}[3][0]{%
\ifcase#1
E( #2 \mid #3 )
\or E \bigl( #2 \bigm\vert #3 \bigr)
\or E \Bigl( #2 \Bigm\vert #3 \Bigr)
\or E \biggl( #2 \biggm\vert #3 \biggr)
\or E \Biggl( #2 \Biggm\vert #3 \Biggr)
\else
E \left( #2 \;\middle\vert\; #3 \right)
\fi}
Here it is in action:
Code: Select all
\[ \expectation{X}{Y}\quad \expectation[1]{X}{Y^2} \quad \expectation[2]{X}{\dfrac{Y}{Z}}
\quad \expectation[3]{X}{\dfrac{Y}{Z}}\quad \expectation[5]{X}{\dfrac{Y}{Z}} \]