# How to patch a starred environment

I would like to translate my approach to center all figure environments to figure* environments. How?

\documentclass[peerreview]{ieeetran}
\usepackage{xpatch}
% \def\figure{\def\@floatboxreset{\reset@font\normalsize\@setminipage\@IEEEfiguretopskipspace}\@float{figure}}
\patchcmd{\figure}{\normalsize}{\normalsize\centering}{}{error}
% \@namedef{figure*}{\def\@floatboxreset{\reset@font\normalsize\@setminipage\@IEEEfiguretopskipspace}\@dblfloat{figure}}
% \patchcmd{\figure*}{\normalsize}{\normalsize\centering}{}{error}
\begin{document}
\begin{figure}[t]
centered!
\end{figure}
\begin{figure*}[t]
not centered!
\end{figure*}
\end{document}


The straightforward approach up there does not work, probably due to the use of \@namedef instead of \def.

• The reference to \@nameref is completely irrelevant, in my point of view – user31729 Jan 15 '16 at 21:54
• Yes, I changed the title of the question already. Thanks! – bers Jan 15 '16 at 21:56
• Actually I meant the reference to \@nameref in the new title ;-) – user31729 Jan 16 '16 at 9:12
• actually, a better title would be "how to patch a starred environment". – barbara beeton Jan 16 '16 at 16:59

In order to patch an environment such as figure* you can do

\expandafter\patchcmd\csname figure*\endcsname{....}{...}{}{}


This method is ineffective with commands such as \section*, which are defined in a completely different way.

On the other hand, if you just want to add \centering to all floats, you can just add \centering to \@floatboxreset:

\makeatletter
\appto{\@floatboxreset}{\centering}
\makeatother


This will influence also table and other floats, though.

• Thanks! Knowing now that the star may be the culprit, I wonder how long it takes until someone shows me dozens of duplicates for this simple question... – bers Jan 15 '16 at 21:54
• You could probably mention that this method only works for starred environments like the example of figure* even though the question title talks of commands (\section* for example is rather different, as you know:-) – David Carlisle Jan 15 '16 at 22:03
• @DavidCarlisle I was from the phone. – egreg Jan 15 '16 at 23:29