对LaTeX环境进行小的修改 [英] Making a small modification to a LaTeX environment

查看:72
本文介绍了对LaTeX环境进行小的修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在整个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆