Colour and links
此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
添加颜色
xcolor宏包让你给文字上色。加载它,然后把词包起来:
\usepackage{xcolor}
...
\textcolor{red}{This is red} and \textcolor{blue}{this is blue}.
- 内置的颜色名包括
red、blue、green、orange、gray等。
高亮与自定义颜色
\colorbox{yellow}{text}会在文字背后加上高亮。- 你甚至可以自己调配:
\textcolor{red!60}{...}表示 60% 的红色(更浅)。
可点击的链接
hyperref宏包能把交叉引用和网址变成可点击的链接:
\usepackage{hyperref}
...
Visit \href{https://ctan.org}{CTAN} for packages.
- 在导言区把
hyperref放在最后加载 —— 它喜欢拥有“最终决定权”。
常见错误
\textcolor缺少xcolor。 LaTeX 会在! Undefined control sequence.处停止。- 拼写错误的颜色名称。
\textcolor{rd}{...}会导致输出! Package xcolor Error: Undefined color 'rd'.。 - 过早加载
hyperref。 其他宏包可能会破坏其链接功能。应在导言区中最后加载它。
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
负载 xcolor, then make the word warning red with \textcolor{red}{warning}. You need both the package and the command.
点击“运行”编译并预览 PDF。
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
Make a clickable link. Load hyperref, then turn the word CTAN into a link with \href{https://ctan.org}{CTAN}. Load hyperref last in the preamble.
点击“运行”编译并预览 PDF。
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
Highlight the word Note with a yellow background using \colorbox{yellow}{Note}. xcolor is already loaded.
点击“运行”编译并预览 PDF。