Making a small modification to a LaTeX environment

latex

I've been using \begin{figure} ... \end{figure} throughout my LaTeX document, but the default styling is ugly; namely, the figures are all left-aligned. Is there a way to redefine the "figure" environment so it automatically inserts some centering commands such as like this?:

\begin{figure} \begin{center}
\end{center} \end{figure}

Sure, I could use \newenvironment to define a "cfigure" environment, but that's undesirable. I don't want to go through and change all my "figures" to "cfigures" (and then later realise I wanted all the figures to be right-aligned and have to rename them all to "rfigures").

I could use \renewenvironment, but then I'd have to dig through the LaTeX source to find what the "figure" environment was originally defined as copy/paste it in.

I almost found what I wanted at this blog post, but the example there was for a command, not an environment.

Best Answer

\let\oldfigure\figure
\def\figure{\oldfigure\centering}

Another solution which works with the optional arguments.

Fixed.

\let\oldfigure\figure
\let\oldendfigure\endfigure
\def\figure{\begingroup \oldfigure}
\def\endfigure{\centering \oldendfigure \endgroup}

Fixed 2. It does work well with any options and any rules and \par inside.

\makeatletter
\let\oldfigure\figure
\def\figure{\@ifnextchar[\figure@i \figure@ii}
\def\figure@i[#1]{\oldfigure[#1]\centering}
\def\figure@ii{\oldfigure\centering}
\makeatother