为了定义文档中的标题颜色,我使用
\usepackage{caption}
\usepackage[font={small,color=ocre}]{caption}
其运行完美,但目前面临以下两个问题:
- 字幕没有颜色(我使用的是子图包,所以我不能使用与上面相同的代码)
- 当图形标题中包含引用时,它不带有颜色。
有人有解决方案或提示吗?
请求之后,这是一个最小工作示例:
\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage[numbers,square]{natbib}
%The following is uesd to make the caption colored
\usepackage{xcolor}
\definecolor{ocre}{RGB}{1,160,233}
\usepackage{caption}
\usepackage[font={small,color=ocre}]{caption}
\usepackage{graphicx,subfigure}
\usepackage[hidelinks]{hyperref} % hyperlinks
\usepackage[hidelinks]{hyperref} % hyperlinks
\hypersetup{
colorlinks=true,
allcolors=black,
citecolor=black,
linkcolor=black,
}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@book{Knu86,
author = {Knuth, Donald E.},
year = {1986},
title = {The \TeX book},
}
\end{filecontents*}
\bibliography{\jobname} % if you’re using BibTeX
\begin{document}
\begin{figure}[hb]
\centering %%% not \center
\boxed{\subfigure[Subfigure One]{\label{fig:SubfigureOne}\includegraphics[width=0.4\textwidth]{../../Desktop/StackExchange/Test.pdf}}}
\boxed{\subfigure[Subfigure Two]{\label{fig:SubfigureTwo}\includegraphics[width=0.4\textwidth]{../../Desktop/StackExchange/Test.pdf}}}
\caption{Comparison between Subfigure One and Subfigure Two. \autoref{fig:SubfigureOne} shows the difference for the complete data range, and \autoref{fig:SubfigureTwo} as displayed in \cite{Knu86}}
\label{fig:OverAllFigure}
\end{figure}
\end{document}
答案1
代码
\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage[numbers,square]{natbib}
%The following is uesd to make the caption colored
\usepackage{xcolor}
\definecolor{ocre}{RGB}{1,160,233}
\usepackage{caption}
\usepackage[font={small,color=ocre}]{caption}
\usepackage{graphicx,subfigure}
\usepackage[hidelinks]{hyperref} % hyperlinks
\usepackage[hidelinks]{hyperref} % hyperlinks
\hypersetup{
colorlinks=true,
allcolors=black,
citecolor=black,
linkcolor=black,
}
\usepackage{etoolbox}
\AtBeginEnvironment{figure} {
\hypersetup{
colorlinks=true,
allcolors=ocre,
citecolor=ocre,
linkcolor=ocre,
}
}
\newcommand{\boxedcolor}[2]{%
\boxed{\color{#1}#2}%
}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@book{Knu86,
author = {Knuth, Donald E.},
year = {1986},
title = {The \TeX book},
}
\end{filecontents*}
\bibliography{\jobname} % if you’re using BibTeX
\begin{document}
\begin{figure}[hb]
\centering %%% not \center
\boxedcolor{ocre}{\subfigure[Subfigure One]{\label{fig:SubfigureOne}\includegraphics[width=0.4\textwidth]{exercises.png}}}
\boxedcolor{ocre}{\subfigure[Subfigure Two]{\label{fig:SubfigureTwo}\includegraphics[width=0.4\textwidth]{exercises.png}}}
\caption{Comparison between Subfigure One and Subfigure Two. \autoref{fig:SubfigureOne} shows the difference for the complete data range, and \autoref{fig:SubfigureTwo} as displayed in \cite{Knu86}}
\label{fig:OverAllFigure}
\end{figure}
Another reference to Figure~\ref{fig:OverAllFigure} with a black hyperling.
\end{document}
文档
解释
问题是,您使用 为超链接定义了黑色
\hypersetup
。您可以更改链接颜色本地\hypersetup
在每个环境开始时再次使用figure
。我认为最舒服的方法是使用\AtBeginEnvironment
包etoolbox
。为了更改子图标题的颜色,我定义了一个新命令
\boxedcolor
。它允许您更改框内的颜色,并影响子图标题。根据您是否始终希望使用ocre
颜色,您还可以\boxedcolor
使用一个参数来定义它\newcommand{\boxedcolor}[1]{% \boxed{\color{ocre}#1}% }
这导致使用时间更短:
\boxedcolor{...}
。或者,您可以像我之前那样使用附加
\color{ocre}
功能。这将是最舒适的解决方案,但它也会导致出现彩色框(我认为这不是我想要的)。figure
\AtBeginDocument
hypersetup
答案2
只需加上括号
\textcolor{white}{{Subfigure 1}}