'Floor' and 'ceiling' functions

\usepackage{mathtools}
\DeclarePairedDelimiter{\ceil}{\lceil}{\rceil}

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.


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

xparse implementation of \ceil

\documentclass{article}
\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[..]{..}
}
\begin{document}
\[\ceil[\big]{x} \quad \ceil[\Big]{x} \quad \ceil[\bigg]{x} \quad \ceil[\Bigg]{x} \quad \ceil*[\big]{\frac{1}{2}}\]
\end{document}

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

Tags:

Symbols