Making a small modification to a LaTeX environment

前端 未结 3 1469
一整个雨季
一整个雨季 2020-12-28 15:25

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

相关标签:
3条回答
  • 2020-12-28 15:38

    As noted in another answer, you can't do the old trick of prepending commands to the end of the \figure macro because that will mess up the optional argument processing.

    If an environment doesn't have arguments then it will work fine, but otherwise there's no straightforward way of doing this.

    For your problem with the figures, try loading the floatrow package:

    \usepackage{floatrow}
    

    If will centre the content of your figures automatically.

    Update: If you don't want to load a package, here's some code that will also do it. Note that it's specific to the figure environment, but the basic theme is: copy the original definition, parsing arguments the same way, then add whatever code you need at the end.

    \makeatletter
    \renewenvironment{figure}[1][\fps@figure]{
      \edef\@tempa{\noexpand\@float{figure}[#1]} 
      \@tempa\centering
    }{
      \end@float
    }
    \makeatother
    

    The \edef is required to fully expand \fps@figure before it's passed to the \@float macro.

    0 讨论(0)
  • 2020-12-28 15:38

    How about:

    \newenvironment{centeredfigure}{\begin{figure}\begin{center}}{\end{center}\end{figure}}
    

    Note: untested.

    0 讨论(0)
  • 2020-12-28 15:47
    \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
    
    0 讨论(0)
提交回复
热议问题