一文解决latex附录重新编号问题,解决Algorithm的编码,以及重新编号后引用链接错误问题

写论文的时候,附录需要重新编号为A.1,A.2怎么办?
这里有两个坑会踩:

  1. Algorithm的重新编码
  2. 正文引用附录链接错误,跳转到正文

第1个问题
我在正文中用的是\usepackage[ruled,linesnumbered]{algorithm2e}
不要setcounter{algorithm},要用{algocf},见下:

解决方案:

\appendix
\section{Appendix}

\setcounter{table}{0}   %从0开始编号,显示出来表会A1开始编号
\setcounter{figure}{0}
\setcounter{section}{0}
\setcounter{equation}{0}
\setcounter{algocf}{0}  % 注意重新编码algorithm的用法!!!

%定义编号格式,在数字序号前加字符“A."
\renewcommand\thetable{A.\arabic{table}}
\renewcommand\thefigure{A.\arabic{figure}}
\renewcommand\thesection{A\arabic{section}}
\renewcommand\theequation{A.\arabic{equation}}
\renewcommand\thealgocf{A.\arabic{algocf}}  % 注意重新编码algorithm的用法!!!

这个时候问题2来了:

我们发现正文引用附录Appendix表格的时候,如:

Figure \ref{app:fig}

会出现问题:即Figure A1链接到的是正文中的Figure 1

怎么解决这个问题?

继续添加代码:

\appendix
\section{Appendix}

\setcounter{table}{0}   
\setcounter{figure}{0}
\setcounter{section}{0}
\setcounter{equation}{0}
\setcounter{algocf}{0}

\renewcommand\thetable{A.\arabic{table}}
\renewcommand\thefigure{A.\arabic{figure}}
\renewcommand\thesection{A\arabic{section}}
\renewcommand\theequation{A.\arabic{equation}}
\renewcommand\thealgocf{A.\arabic{algocf}}

################ 新增代码 ################
\renewcommand*{\theHtable}{\thetable}
\renewcommand*{\theHfigure}{\thefigure}
\renewcommand*{\theHequation}{\theequation}
\renewcommand*{\theHsection}{\thesection}
\renewcommand*{\theHalgocf}{\thealgocf}
################ 新增代码 ################

添加完了这个代码以后,就发现即Figure A.1链接定位到了的是附录中的Figure A.1

成功!

参考了多个链接
基本框架:基本框架
问题2解决:问题2解决参考
问题1解决:问题1解决

  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值