[Tex/LaTex] How to write ceil and floor in latex?

math-mode

Is there a macro in latex to write ceil(x) and floor(x) in short form? The long form

\left \lceil{x}\right \rceil 

is a bit lengthy to type every time it is used.

Best Answer

Using \DeclarePairedDelimiter from mathtools, you could define macros \ceil and \floor, which will scale the delimiters properly (if starred):

\documentclass{minimal}
\usepackage{mathtools}
\DeclarePairedDelimiter\ceil{\lceil}{\rceil}
\DeclarePairedDelimiter\floor{\lfloor}{\rfloor}

\begin{document}
  \begin{equation*}
    \floor*{\frac{x}{2}} \leq \frac{x}{2} \leq \ceil*{\frac{x}{2}}
  \end{equation*}
\end{document}

Result:

example of using floor and ceiling

Related Question