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

Is there a convenient way to typeset the floor or ceiling of a number, without needing to separately code the left and right parts? For example, is there some way to do $\ceil{x}$ instead of $\lceil x \rceil$?

share|improve this question
up vote 119 down vote accepted

The command \ceil will do; if called as \ceil*{x} it will add \left and \right; you can also call it as

\ceil[\big]{x} \ceil[\Big]{x} \ceil[\bigg]{x} \ceil[\Bigg]{x}

to state explicitly the size of the delimiters.

share|improve this answer
Even after more than 10 years of LaTeXing one still learns some new tricks! – yo' Jan 25 '12 at 17:32
Don't tell me! I learn new tricks even after 25 years! – egreg Jan 25 '12 at 17:34
@jamaicanworm There is, I believe also on this site. But I won't tell you: use \left and \right only when they are really needed. – egreg Apr 21 '12 at 17:50
@jamaicanworm Swap definition of starred and non-starred command discusses switching the starred with non-starred version. – Qrrbrbirlbel Nov 11 '12 at 1:36
To typeset the floor function, just replace "ceil" with "floor". This may be obvious, but it might save you the trouble of consulting documentation. – void-pointer Sep 30 '13 at 7:19

Here is a simple xparse implementation of \ceil, similar to that provided by mathtools' \DeclarePairedDelimiter:

xparse implementation of \ceil

\usepackage{xparse}% http://ctan.org/pkg/xparse
\NewDocumentCommand{\ceil}{s O{} m}{%
  \IfBooleanTF{#1} % starred
    {\left\lceil#3\right\rceil} % \ceil*[..]{..}
    {#2\lceil#3#2\rceil} % \ceil[..]{..}
\[\ceil[\big]{x} \quad \ceil[\Big]{x} \quad \ceil[\bigg]{x} \quad \ceil[\Bigg]{x} \quad \ceil*[\big]{\frac{1}{2}}\]

The optional argument is ignored in the starred version of \ceil*[..]{..}.

share|improve this answer
You could eliminate the \IfNoValueTF {\lceil#3\rceil} if you used {s O{} m}. Then the second arg #2 will be defined so only need #2\lceil#3#2\rceil. – Peter Grill Jan 25 '12 at 18:29
@PeterGrill: Schweeeet, thanks! – Werner Jan 25 '12 at 18:33

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.