41

I want to write an equation with $\mid$, but it is too small, can i make it bigger in any way?

I am kinda new to TeX so i have no idea how to do it.

yo'
  • 51,322
user93089
  • 2,369

4 Answers4

27

2017 Update: Since \mid is a relation, under normal circumstances the spaces manually inserted around \middle| should be thick \; instead of thin \,. See table on p.170 of the TEXbook.


Instead of \mid, you can use \middle command to enlarge vertical delimiter and insert spaces manually, here is an example:

\documentclass{article}

\usepackage{mathtools}

\begin{document}
\[S=\left(\frac{\sum_{i=1}^{n}X_i}{n}\;\middle|\;X_i\sim\chi^2(k)\right)\]
\[\left.\frac{\sum_{i=1}^{n}X_i+Y_i}{n}\;\middle|\;X\sim\chi^2_k\;\middle|\;Y\sim\mathcal{N}(\mu,\sigma^2)\right.\]

\end{document}

Result:

enter image description here

Better yet, we can make a custom command for our conveniences:

\makeatletter
\newcommand{\@giventhatstar}[2]{\left(#1\;\middle|\;#2\right)}
\newcommand{\@giventhatnostar}[3][]{#1(#2\;#1|\;#3#1)}
\newcommand{\giventhat}{\@ifstar\@giventhatstar\@giventhatnostar}
\makeatother

It works sorta like \DeclarePairedDelimiter in mathtools, for example:

\[\giventhat{f(x)=\frac{x^2}{2}}{x=1,2,3,\dotsc}\]
\[\giventhat[\big]{f(x)=\frac{x^2}{2}}{x=1,2,3,\dotsc}\]
\[\giventhat[\Big]{f(x)=\frac{x^2}{2}}{x=1,2,3,\dotsc}\]
\[\giventhat*{f(x)=\frac{x^2}{2}}{x=1,2,3,\dotsc}\]

will give you:

Francis
  • 6,183
  • 2
    \cdots is not the proper dots to use here – daleif Nov 01 '13 at 07:30
  • See also my addition – daleif Nov 01 '13 at 07:41
  • 1
    Really helpfull, thanks. However, when adding the commands at the beginning of the document I had to make some changes and include the \ensuremath{...} command:

    \usepackage{mathtools} \makeatletter \newcommand{@giventhatstar}[2]{\ensuremath{\left({#1};\middle|;{#2}\right)}} \newcommand{@giventhatnostar}[3][]{#1(#2;#1|;#3#1)} \newcommand{\giventhat}{@ifstar@giventhatstar@giventhatnostar} \makeatother

    – David Alvarez Aug 15 '18 at 11:47
23

Sounds like conditional probability. In that case I usually recommend our students to use something similar to

\newcommand\given[1][]{\:#1\vert\:}

Which will be manually scalled via, say

\given[\Big] 

Then the code makes sense when read


ADDITION. Building further on Francis' suggestion \given can be build into his macros such that the macros only takes one argument.

\documentclass[a4paper]{memoir}
\usepackage{mathtools}
\newcommand\givenbase[1][]{\:#1\lvert\:}
\let\given\givenbase
\newcommand\sgiven{\givenbase[\delimsize]}
\DeclarePairedDelimiterX\Basics[1](){\let\given\sgiven #1}
\newcommand\Average{E\Basics}
\begin{document}
\begin{align*}
  \Basics{X} \qquad \Basics[\Big]{ X \given Y}\\
  \Average{X} \qquad \Average[\Big]{ X \given Y}\\
\end{align*}
\end{document}

enter image description here

David Carlisle
  • 757,742
daleif
  • 54,450
  • Maybe \operatorname{E} instead of E? – Francis Nov 01 '13 at 08:54
  • 2
    It might be yes. Though I think most people think of it in the same manner as f(x), i.e. just a function. Some people use an upright E, some people even use \mathbb{E}. Depends on the tradition. – daleif Nov 01 '13 at 09:45
5

This uses features of the scalerel package.

\documentclass{article}
\usepackage{scalerel}
\begin{document}
\noindent You can stretch it to a size:\\
$A \mid 
\mathrel{\stretchto{\mid}{3ex}} 
\mathrel{\stretchto{\mid}{4ex}}
B$\\
or you can stretch it to fit something else:\\
$ \stretchrel{\mid}{\displaystyle\frac{A}{B}} $\\
\end{document}

enter image description here

David Carlisle
  • 757,742
1

Use \left.\right|

For example $$\mathbb{E}(Y^3) = \left.\frac{d^3 M_Z(t)}{d t^3}\right|_{t=0}$$

enter image description here