4

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.

bers
  • 5,404

1 Answers1

4

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.

egreg
  • 1,121,712
  • 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