对LaTeX环境进行小的修改 [英] Making a small modification to a LaTeX environment
问题描述
我在整个LaTeX文档中一直使用\begin{figure} ... \end{figure}
,但是默认样式很难看.也就是说,这些数字都是左对齐的.有没有一种方法可以重新定义图"环境,以便它自动插入一些居中命令,例如:?
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}
当然,我可以使用\newenvironment
定义图"环境,但这是不可取的.我不想经历所有我的数字"更改为数字"(然后意识到我希望所有数字都右对齐,并且必须将它们全部重命名为"rfigures").
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").
我可以使用\renewenvironment
,但是随后我必须深入研究LaTeX源,以查找最初将图"环境定义为将其复制/粘贴到其中的情况.
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.
已修复.
\let\oldfigure\figure
\let\oldendfigure\endfigure
\def\figure{\begingroup \oldfigure}
\def\endfigure{\centering \oldendfigure \endgroup}
已修复2..它与任何选项和规则以及内部的\par
配合使用都很好.
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
这篇关于对LaTeX环境进行小的修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!