如何改变一段文本的颜色?

如何改变一段文本的颜色?

我正在用 Emacs 编辑 LaTeX 论文。有时我想让一段文本不那么显眼(或不那么重要)。它们应该仍然在那里,而不是完全隐藏它们。有没有一种简单的方法可以将它们嵌入到某个东西中,使其改变颜色(例如变成灰色)?

顺便问一下,除了改变颜色之外,还有其他方法可以轻松地使一块文本看起来不那么重要吗?

答案1

您可以使用xcolor包裹(可通过 安装tlmgr install xcolor)。它提供\textcolor{<color>}{<text>}以及\color{<color>}切换某些给定文本的颜色,或切换组/环境的末尾的颜色。您可以使用black!x颜色获得不同的灰色阴影,其中x是 0 到 100 之间的数字,以百分比表示,100 为黑色。

\usepackage{xcolor}
\begin{document}

This is a sample text in black.
\textcolor{blue}{This is a sample text in blue.}

\end{document}

答案2

下面的做法似乎更简单一些:

\documentclass{amsproc}
\usepackage[colorlinks]{hyperref}
\begin{document}
    This is {\color{red} highlighted}, and this is not.
\end{document}

答案3

以上所有答案对于一般用途来说都是很好的

如果你想突出显示编程语言的语法,我们可以使用minted包,它提供了出色的彩色高亮文本。

要使用此包你需要有Python安装在你的系统上(你可以使用蟒蛇包这是一个不错的选择)除了一个包叫色素(安装此包使用pip install pygments)它是一个用于突出显示编程语言语法的 Python 库

我将给出一个简单的例子来说明如何使用它

\usepackage{minted}
\usemintedstyle{vim} %note here you can use different highlighting
                      %styles see the final note below

\begin{document}

\begin{minted}{python}
import matplotlib.pyplot as plt
import numpy as np

T=1
delta_T=T/200
alpha=0.5
fc=40/T
A_m=1
t=[i for i in np.arange(-5,5,1/200)]
t_arr=np.array(t)
N=len(t)

g_T=[]
for i in range(N):
    if (abs(t[i])!=(T/2*alpha)):
        g_T.append(np.sinc(t[i])*(np.cos(np.pi*alpha*t[i]/T)/
            (1- 4*alpha**2 *(t[i])**2 /(T**2))))
    else:
        g_T.append(0)
\end{minted}

\end{document}

此代码将产生以下内容这是上述代码的输出

笔记你需要在 LaTeX 或 pdfLaTeX 中启用“ -shell-escape ”选项

latex -shell-escape foo.tex

或者

pdflatex -shell-escape foo.tex

如果你想获得不同的亮点,在命令行上使用

pygmentize -L styles

您将获得不同风格的突出显示

干杯,希扎尼

答案4

使用包

\usepackage{xcolor}

然后立即写下下面这一行:

\newcommand{\myRed}[1]{\textcolor{red}{#1}}

现在,无论您想在何处突出显示某些文本,都可以使用\myRed{}

当你编译时,你将得到\myRed红色的文本。

相关内容