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.

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

1 Answer 1

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.

3
  • 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
    Commented Jan 15, 2016 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:-) Commented Jan 15, 2016 at 22:03
  • @DavidCarlisle I was from the phone.
    – egreg
    Commented Jan 15, 2016 at 23:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .