极光城

LaTeX修改交叉引用标号数字格式

问题

用的模板不好时,图例标号的交叉引用格式可能会怪异混乱。

比如使用了 subfig 包,引用一个图表里的子图时,可能会出现:

如图 4.1a 所示 如图 4.1b 所示 如图 4.1c 所示

然而比较好的格式应该是:

如图 4.1(a) 所示 如图 4.1(b) 所示 如图 4.1(c) 所示

方法

一篇博客文章中提到 用subcaption

http://www.peteryu.ca/tutorials/publishing/latex_captions

\usepackage[labelformat=parens]{subcaption}

但是 warning: cannot work with caption package

不好使。

另一种方法是在subfig里添加选项

subfig.pdf 官方文档第 33 页说:

option values
‘listofformat’ ‘empty’ Label format: (none)
  ‘simple’ Label format: ##
  ‘parens’ Label format: #(#)
  ‘subsimple’ Label format: #
  ‘subparens’ Label format: (#)

usepackage[listofforamt=parens]{subfig}

结果没有任何效果。

重新定义 \thesubfigure

来源: https://tex.stackexchange.com/questions/135358/changing-the-formatting-of-subcaption-for-reference

\renewcommand\thesubfigure{(\alph{subfigure})}

好用!

但是新的问题出现了,图表中的 (a) (b) ... 变成了 ((a)) ((b)) ...

这说明 thesubfigure 是在引用时渲染引用标识时使用的变量。 而图表中的表号格式却已经包含了括号

消除子图下方标号的双括号

根据 caption 包一贯的选项:

option values
‘labelformat’ ‘empty’ Label format: (none)
  ‘simple’ Label format: ##
  ‘parens’ Label format: #(#)
  ‘subsimple’ Label format: #
  ‘subparens’ Label format: (#)

在合适的位置插入以下语句,使得子图下方不再自动加入额外括号:

\captionsetup[subfigure]{labelformat=simple}

但是注意,一定要在各种配置各种宏语句之后,再写这代码,不然宏展开后有可能覆盖这个设定

比如:

错误::
\begin{document}
    ...
    \captionsetup[subfigure]{labelformat=simple} % 防止子图标题双括号
    \mainpagestyle
    \section[绪论] \label{sec:introduction}
正确::
\begin{document}
    ...
    \mainpagestyle
    \captionsetup[subfigure]{labelformat=simple} % 防止子图标题双括号
    \section[绪论] \label{sec:introduction}