TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a simple command which I use to write set comprehensions so that the braces automatically resize with respect to size of the enclosed arguments, e.g.

\newcommand{\set}[1]{\left\lbrace #1\right\rbrace}

\set{x \in X \mid x > \frac{1}{2}}  
% Produces something like: { x : X | x > 1/2 }

However, the \mid vertical bar wont resize like the braces { .. } do. How can I get the \mid to resize as well?

share|improve this question
up vote 46 down vote accepted

You can use \middle| instead of \mid like

\[ \left\{ x \in X \middle| x > \frac{1}{2}\right\} \]

or with better spacing

\[ \left\{ x \in X \,\middle|\, x > \frac{1}{2}\right\} \]

(I think this requires a somewhat modern TeX-distribution.)

share|improve this answer
@Andrew: It is an eTeX primitive (not included in the original TeX). But nowadays LaTeX always is run on the pdftex engine, which includes the eTeX stuff. – Paŭlo Ebermann Aug 15 '11 at 13:34

I think the best idea is to use the braket package, which provides markup for these sorts of constructions, for which the brackets and "pipes" expand where necessary.

share|improve this answer
Thanks. Leaving a comment here for future reference: Braket lets you write \Set{ x | 0<x<5} etc., expanding the | as necessary. – ShreevatsaR Jul 29 '10 at 12:28

There is the \middle command, it is like \left and \right but for the middle =)

However, LaTeX does not consider \mid to be a delimiter, so you have to use pipe instead (or vertical bar).

share|improve this answer

Here is a nice solution using mathtools, which is quite versatile and produces the right spacing (thin space withing braces, and thick space around the mid symbol):

\DeclarePairedDelimiterX\setc[2]{\{}{\}}{\,#1 \;\delimsize\vert\; #2\,}

Now if you use the starred version of the macro you get the desired result:

\setc*{x \in X}{x > \frac{1}{2}}

enter image description here

You can even adjust to a different size if you think that the braces are too big, with the syntax

\setc[\Big]{x \in X}{x > \frac{1}{2}}

enter image description here

share|improve this answer

This seems to work for me, possibly the horizontal spacing around the bar needs adjusting.



\newcommand{\my@set}[1]{\left\lbrace #1\right\rbrace}
 \left\lbrace #1\vphantom{#2}\right\vert%

\edef\my@start{\my@first #1|\relax}%
\edef\my@last{\my@second #1\relax}%


  \set{x \in X \int_0^1 | y \in Y} \; \set{x \in X \int_0^1 y \in Y}

\set{x | y} \set{a b}

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.