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.
\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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With