【转载请注明出处】http://www.cnblogs.com/mashiqi

2016/10/20

一年多没写博文了。今天写一个短的,记录一下使用LaTeX的一些经验。

有些时候,我们的latex文档是这样开头的

\documentclass[fleqn,leqno]{article}

其中 leqno 参数的作用是使得公式的编号显示在左边。当参数 fleqn 存在时,公式往往不能正确的居中。这时,我们就需要特别小心的使用equation、align、flalign、alignat等命令。下面详细讲讲。

1、多行公式在一个地方对齐
如何居中多行的公式呢?我试过很多种方法后,觉得下面这个最好用:

\begin{flalign*}
% In this way (this arrange of &), the equation will in the center and align at the third &. If use this method for 'split', equations will not be centered
% However, 'flalign' will give each line a separate number. It cannot number the whole equations in one number.
&& a & = b & \\
&& a & = b & \\
&& a & = b & \\
&& a & = b &
\end{flalign*}

其中的多个&符号是专门安排好的。只用往第二个和第三个&符号后面添加代码就行了,它们就能对齐 并且所有公式作为一个整体进行居中。但这里有个问题,就是编号的问题。这里没有公式的编号。如果把flalign后面的*号去掉的话,那么就有编号了,但是是每一行公式一个编号,有些情况下这不太合适。因此,为了编号,我们要对上述代码做如下更改:

\begin{flalign}
% In this way (this arrange of &), the equation will in the center and align at the third &. If use this method for 'split', equations will not be centered
% However, 'flalign' will give each line a separate number. It cannot number the whole equations in one number.
&& a & = b & \nonumber\\
&& a & = b & \\
&& a & = b & \nonumber\\
&& a & = b & \label{eq2}\\
&& a & = b & \nonumber
\end{flalign}
Now we refer equation (\ref{eq2}).

现在去掉了flalign后面的*号,那么给不想编号的行的结尾加上 \nonumber,给想加编号的行的后面 不添加任何东西 或者加上 \label{...} 。当 不添加任何东西 时,此行是有编号的,但这个编号将不能被引用到;当加上了 \label{...} 时,可以通过 \ref{...} 来引用这个编号。

下图就是上面两段代码的输出结果:

以上就基本解决了:多行公式、居中、对齐、加编号、引用编号这些问题。唯一的小缺点就是编号并不在整个公式的中间。不过这个小缺点可以容忍。

2、多行公式在多个地方对齐

为了达到多行公式在多个地方对齐的目的,我们必须取消最开始的 fleqn 命令。

有了上面使用 flalign 的经验之后,我们可以使用 \begin{alignat*}{·} 进行多行公式在多个地方对齐的操作。“alignat”后面的那个括号里的数字是每行的“&”符号的个数加1后除以2。举例如下:

\begin{alignat*}{2}
a & = b &\quad c & = d \\
a & = b & c & = d
\end{alignat*}

注意:为了让各个公式之间能有一个间隔,要在分隔各个公式的&符号之后加一个 \quad 。其实 flalign 也可以通过上面的方法实现多个地方对齐,但是当每一行的公式不多时,为了故意填满一整行,公式间的间距会很大。而 alignat 命令不会可以去填满一整行,而是会使得各个公式间尽量靠拢,所以各个公式间的水平距离会看起来更舒服一些。 alignat 和 flalign 之间的区别举例如下:

\begin{alignat*}{2}
a & = b &\quad c & = d \\
a & = b & c & = d
\end{alignat*} \begin{flalign*}
&& a & = b & c & = d && \\
&& a & = b & c & = d &&
\end{flalign*}

3、 其他命令加编号

另外,使用

$$...$$

命令也是可以加编号的,方法是使用 \eqno{...} 命令。举例如下:

$$a=b \eqno{()}$$

但这时的编号 () 要手动输入,而且不能被引用。

最新文章

  1. 如何远程关闭一个ASP.NET Core应用?
  2. 【原创】自己动手写工具----XSmartNote [Beta 3.0]
  3. Graph cuts图论分割
  4. 【转】Web应用的组件化开发(二)
  5. 字符设备 register_chrdev_region()、alloc_chrdev_region() 和 register_chrdev()
  6. easyui datagrid 多表头设置
  7. iOS的Mantle实战分析
  8. 在mysql中修改表名的sql语句
  9. bzoj1208 [HNOI2004]宠物收养所(STL,Treap)
  10. 浏览器文档播放Shockwave Flash 插件问题
  11. [leetcode-573-Squirrel Simulation]
  12. SpringMVC注解HelloWorld
  13. Rmq Problem/mex BZOJ3339 BZOJ3585
  14. 运用Zabbix实现内网服务器状态及局域网状况监控(2) —— 环境配置
  15. centos6.5环境openldap实战之ldap配置详解及web管理工具lam(ldap-account-manager)使用详解
  16. Visual Studio的NuGet包管理器无法加载
  17. Python学习(004)-字典{}
  18. caffe for python
  19. js-js的语句
  20. 用Java实现自己的ArrayList

热门文章

  1. Entity Framework – (复数)Plural and (单数)Singular 表名Table names
  2. 【图像处理】【SEED-VPM】5.uImage的烧写 & NFS烧写文件系统
  3. linux下关于Apache设置二级域名绑定二级目录的方法
  4. bzoj 4066: 简单题
  5. bzoj 3611: [Heoi2014]大工程
  6. 1476. Lunar Code
  7. (DFS、全排列)POJ-2718 Smallest Difference
  8. AAS代码第2章
  9. pyinstaller 用法
  10. c语言计算矩阵特征值和特征向量-1(幂法)