4

更换模板后Latex部分包失效问题的一个解决思路(如xcolor,algorithm2e)

 2 years ago
source link: https://blog.csdn.net/yanxiangtianji/article/details/120632136
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

更换模板后Latex部分包失效问题的一个解决思路(如xcolor,algorithm2e)

专栏收录该内容
8 篇文章 1 订阅

有些Latex模板,比如新版本的ACM模板,自己会做很多工作,比如以默认方式导入很多包,如xcolor,graphicx等。此时如果需要带参数导入这些包,就会出错,或者这些参数不起作用。

比如使用\usepackage[dvipsnames]{xcolor}导入xcolor包之后,我们可以在基础的19种颜色名称之外还可以使用dvips预定义的另外68种标准颜色名称而不需要自行使用它们的RGB值定义它们,比如OliverGreen、Maroon等。这个功能对使用listing包导入代码时非常有用,可以将关键字和注释定义成看起来舒服的颜色。具体名称和颜色可以参见https://en.wikibooks.org/wiki/LaTeX/Colors。又比如使用\usepackage[vlined,ruled,linesnumbered]{algorithm2e}导入algorithm2e包时,我们希望在缩进的同时显示垂直线和行号。

但是使用某些模板之后,这些参数会失效。表现为诸如Package xcolor Error: Undefined color 'ForestGreen'一类错误或者算法没用显示垂直线和行号。

解决方法:
可以在应用模板这一行之前使用\PassOptionsToPackage命令提前预约好给特定的包传入的参数。
比如:

\PassOptionsToPackage{dvipsnames}{xcolor} % for ACM
\PassOptionsToPackage{vlined,ruled,linesnumbered}{algorithm2e} % for ACM
\documentclass[format=sigconf, review, screen]{acmart}

这样就没有问题了。

对于ACM模板,可以查看参考资料[1]的2.1 Installation来看看它到底依赖了哪些包。

参考资料:
[1] https://www.acm.org/binaries/content/assets/publications/consolidated-tex-template/acmart.pdf
[2] https://tex.stackexchange.com/questions/288915/package-xcolor-error-undefined-color-forestgreen


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK