【问题标题】:Latex highlighting \citation and \ref using different backgrond colors乳胶使用不同的背景颜色突出 \citation 和 \ref
【发布时间】:2020-04-15 13:18:49
【问题描述】:

您好,我正在写一篇修改后的文章。我用不同的背景颜色突出显示修改后的文本的背景。我成功地突出了它们,但我无法突出底部参考中的引用。

\documentclass[journal]{IEEEtran}
\ifCLASSINFOpdf
\else
\fi
%% Following for different color highlight using \textcolor{r1}{text}
\usepackage[dvipsnames]{xcolor}
\usepackage{soul}
\colorlet{r1}{ForestGreen!20}
\colorlet{r2}{Red!20}
\colorlet{r3}{RoyalPurple!20}
\newcommand{\Hl}[2][\empty]{%
\ifx#1\empty
\else
\sethlcolor{#1}%
\fi
\hl{#2}}
\usepackage{soul,color}
\soulregister\Hl{7}
\soulregister\ref7
\soulregister\pageref7

\begin{document}

 \Hl[r2]{I wanted to highlight this \cite{miguel14anestimator}. It was  
 successful highlighted in the main text. But the problem is it was not  
 highlighted in the Bottom References?} 

   @ARTICLE{miguel14anestimator,
    author={M. {Carrasco} and F. {Mancilla-David} and R. {Ortega}},
    journal={IEEE Trans. Ind. Electron.},
    title={An Estimator of Solar Irradiance in Photovoltaic Arrays With Guaranteed Stability Properties},
    year={2014},
    volume={61},
    number={7},
    pages={3359-3366},} 
\end{document}

【问题讨论】:

  • 您附上的图片有很多错误。检查它们,也许解决它们有助于解决您的问题。
  • @Eddymage 没错。当\cite 包含在突出显示中时,错误就出现了。
  • 好的,那么请发布错误,以便尝试了解发生了什么
  • 你能发一个minimal reproducible example 让我们重现问题吗?
  • @samcarter_is_at_topanswers.xyz 我更新了我的问题。现在我缩短了我的问题。

标签: latex pdflatex


【解决方案1】:

\ref 已经使用您的代码开箱即用。要使\cite也兼容,您可以添加\soulregister\cite7

\documentclass[journal]{IEEEtran}
\ifCLASSINFOpdf
\else
\fi
%\usepackage[left=0.5in, right=0.5in,top=0.1in,bottom=0.1in]{geometry}
\usepackage{graphicx}
\usepackage{float}
\usepackage[skip=2pt,font=scriptsize]{caption} %\usepackage{caption}
\usepackage{subcaption}
\usepackage{array}
\usepackage{mdwmath}
\usepackage{mdwtab}
\usepackage{multirow}
\usepackage{amsmath}
\usepackage{siunitx}
%\usepackage{xcolor, soul}
%\sethlcolor{lightgray}
\usepackage{cancel}
\usepackage{amssymb}% http://ctan.org/pkg/amssymb
\usepackage{pifont}% http://ctan.org/pkg/pifont
%\usetikzlibrary{calc,matrix}
\usepackage{color,soul}
\usepackage{cite}
\newtheorem{theorem}{Theorem}{}
\newtheorem{corollary}{Corollary}{}
\newtheorem{remark}{Remark}{}
\hyphenation{op-tical net-works semi-conduc-tor}
%% Following for different color highlight using \textcolor{r1}{text}
\usepackage[dvipsnames]{xcolor}
\usepackage{soul}
\colorlet{r1}{ForestGreen!20}
\colorlet{r2}{Red!20}
\colorlet{r3}{RoyalPurple!20}
\newcommand{\Hl}[2][\empty]{%
\ifx#1\empty
\else
\sethlcolor{#1}%
\fi
\hl{#2}}
\usepackage{soul,color}
\soulregister\Hl{7}
\soulregister\ref7
\soulregister\cite7
\soulregister\pageref7

\begin{document}

\section{title}
\label{key}

\Hl{\ref{key}}

\Hl{\cite{knuth:ct:a}}

\bibliographystyle{plain}
\bibliography{biblatex-examples}

\end{document}


同时突出显示 bititem:

\documentclass[journal]{IEEEtran}
\ifCLASSINFOpdf
\else
\fi
%\usepackage[left=0.5in, right=0.5in,top=0.1in,bottom=0.1in]{geometry}
\usepackage{graphicx}
\usepackage{float}
\usepackage[skip=2pt,font=scriptsize]{caption} %\usepackage{caption}
\usepackage{subcaption}
\usepackage{array}
\usepackage{mdwmath}
\usepackage{mdwtab}
\usepackage{multirow}
\usepackage{amsmath}
\usepackage{siunitx}
%\usepackage{xcolor, soul}
%\sethlcolor{lightgray}
\usepackage{cancel}
\usepackage{amssymb}% http://ctan.org/pkg/amssymb
\usepackage{pifont}% http://ctan.org/pkg/pifont
%\usetikzlibrary{calc,matrix}
\usepackage{color,soul}
\usepackage{cite}
\newtheorem{theorem}{Theorem}{}
\newtheorem{corollary}{Corollary}{}
\newtheorem{remark}{Remark}{}
\hyphenation{op-tical net-works semi-conduc-tor}
%% Following for different color highlight using \textcolor{r1}{text}
\usepackage[dvipsnames]{xcolor}
\usepackage{soul}
\colorlet{r1}{ForestGreen!20}
\colorlet{r2}{Red!20}
\colorlet{r3}{RoyalPurple!20}
\newcommand{\Hl}[2][\empty]{%
\ifx#1\empty
\else
\sethlcolor{#1}%
\fi
\hl{#2}}
\usepackage{soul,color}
\soulregister\Hl{7}
\soulregister\ref7
\soulregister\cite7
\soulregister\pageref7

\usepackage{etoolbox}
\makeatletter 
\pretocmd\@bibitem{\csname keycolor#1\endcsname}{}{\fail}
\newcommand\citecolor[2][yellow]{\@namedef{keycolor#2}{\hspace*{-\labelwidth}\hspace*{-\labelsep}{\color{#1}\rule[-0.3em]{\dimexpr\linewidth+\labelwidth+\labelsep\relax}{1\baselineskip}}\vspace*{\itemsep}\vspace*{-\baselineskip}}}
\makeatother
\citecolor{knuth:ct:a}
\citecolor[red]{knuth:ct:c}

\begin{document}

\section{title}
\label{key}

\Hl{\ref{key}}

\Hl[red]{\cite{knuth:ct:c}}
\Hl[yellow]{\cite{knuth:ct:a}}
\cite{knuth:ct:b}

\bibliographystyle{plain}
\bibliography{biblatex-examples}

\end{document}

(如果引用超过一行,则相应增加1\baselineskip

【讨论】:

  • 谢谢。是的!你的代码有效。我还有两个问题。 1. 如何在参考文献中突出显示[1]? 2. 请看我发布的屏幕截图。令人惊讶的是,[19] 被成功引用,但在同一文本中第二次失败。这里有什么问题?
  • @Mainland 请不要发布代码截图。我不打算重新输入它们以调查问题可能是什么。创建minimal reproducible example 并将其作为文本添加到您的问题中。
  • 现在我通过删除屏幕截图来编辑我的问题。感谢您的帮助。
  • 在你的回答中,[1]在正文中被成功引用。但是如何在底部的引用中突出显示呢?
  • 我的代码执行没有错误,但它没有突出显示参考部分中的新引用?您的答案中引用的代码部分是\usepackage{etoolbox} \makeatletter \pretocmd\@bibitem{\csname keycolor#1\endcsname}{}{\fail} \newcommand\citecolor[1]{\@namedef{keycolor#1}{\hspace*{-\labelwidth}\hspace*{-\labelsep}{\color{yellow}\rule[-0.3em]{\linewidth}{1\baselineskip}}\vspace*{\itemsep}\vspace*{-\baselineskip}}} \makeatother
猜你喜欢
  • 2011-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-13
相关资源
最近更新 更多