# Adjust the height of the “|” in a mathematical term

I have a mathematical term produced by two different pieces of code:

\displaystyle H\left(\frac{1}{2},\frac{1}{2}\left|_{C_{k}=1}\right.\right)


\displaystyle H\left(\frac{1}{2},\frac{1}{2}\Big|_{C_{k}=1}\right)


What I was trying to achieve (and that is why I tried many approaches) is produce the vertical line with the same height as the fraction.

As you can see with the first piece of code the line is by far shorter and with the second, although it is better, it is still short.

By trying out the previous approaches I am confused as to why the first approach didn't produce a line of the same height as the \left(,[ etc produces a symbol in the same height as the expression (correct me if I am wrong).

Also my initial concern was how to produced a line with the specifications I mentioned?

Your first line of code produces a line with normal height since it surrounds \left|_{C_{k}=1}\right. not he fraction. So you have to use \left.\kern-\nulldelimiterspace\frac{1}{2}\right|. As far, \Big| is concerned the size is not suitable, use \bigg|

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\displaystyle H\left(\frac{1}{2},\left.\kern-\nulldelimiterspace\frac{1}{2}\right|_{C_{k}=1}\right)$

$\displaystyle H\left(\frac{1}{2},\frac{1}{2}\bigg|_{C_{k}=1}\right)$
\end{document}


I'd use \bigg and friends; with \left and \right the parentheses turn out to be too big.

\documentclass{article}
\usepackage{mleftright}
\newcommand{\fakeleft}{\mleft.\kern\nulldelimiterspace}
\begin{document}
$H\mleft(\fakeleft\frac{1}{2},\frac{1}{2}\mright|_{C_{k}=1}\mright)$
$H\biggl(\frac{1}{2},\frac{1}{2}\bigg|_{C_{k}=1}\,\biggr)$
\end{document}


Unfortunately, \middle wouldn't work in this context, because it's implemented like \left, so it doesn't take a subscript.

The following solution simply uses \vrule, which gives exact height and depth of the fraction. (On the other hand, \left...\right doesn't give exact height.) No additional package is needed.

$$H\left(\frac{1}{2},{\frac{1}{2}\,\vrule\,}_{C_{k}=1}\right)$$


• Best and simplest solution so far! I've edited your posting to add a screenshot -- hope you're OK with that. – Mico Dec 18 '14 at 9:30
• Thank you it is a great solution and I will consider it for future use. Also it is quite elegant. I had to accept the other answer though as it was answering specifically to my question. – Adam Dec 19 '14 at 4:46
• @Adam Note, that various solutions here differ by the size of the outer brackets. If the inner line is solved (internally) as new internal \left...\right then the outer brackets are greater. – wipet Dec 19 '14 at 7:07

just to cover one approach that hasn't yet been mentioned, but is the approach presented in the texbook, wrap \left. ... \right| around the taller portion of the expression:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$H\biggl(\left.\frac{1}{2},\frac{1}{2}\right|_{C_{k}=1}\,\biggr)$
\end{document}


To make the vertical bar extent exactly the height of the fraction (as requested by the OP), the scalerel package can help.

\documentclass{article}
\usepackage{scalerel}
\begin{document}
$\displaystyle H\left(\frac{1}{2},\frac{1}{2} {\stretchrel*{\vert}{\frac{1}{2}}}_{C_{k}=1}\right)$
\end{document}


• Thank you for your answer. This is a useful package indeed. – Adam Dec 19 '14 at 4:49

The straightforward way to do this is with \middle, which works just like \left and \right. Unfortunately, the index doesn't get placed correctly. To get placed low enough, I inserted a fake fraction with \vphantom{\frac12}:

\documentclass{article}
\begin{document}
$H \left(\frac{1}{2},\frac{1}{2} \middle| {\vphantom{\frac12}}_{C_{k}=1} \right)$
\end{document}


A sidenote: This solution is probably "semantically" not really correct, since it is more for things like bra-ket notation where you have a left and a right part (\left\langle \Psi \middle| \xi\right\rangle becomes ⟨ψ|ξ⟩). Your example looks a bit like the "evaluate under this condition" notation (\left. \frac{\partial f}{\partial x} \right|_{x=0}), for example:

In this case, the subscript is a bit lower relative to the vertical line. I guess since your formula is neither of these two standard cases （vertical line splits the bracket vs. vertical line makes a comment on the second fraction), you get to choose your own typography, so I'd just choose what looks good.