给 \LaTeX word 中的每个字母上色

给 \LaTeX word 中的每个字母上色

我如何为以花式形式书写的单词“LaTex”的字母分配特定的颜色?

我尝试通过这种形式对其进行编码\textcolor{red}{\LaTeX},但是整个单词将是红色的,而我希望每个字母都有不同的颜色。

答案1

\TeX\LaTeX和的定义\LaTeXe可以在 中找到latex.ltx,因此只需复制定义并\textcolor{...}{...}为相关字母添加一些语句。

所选颜色仅作为示例。

\documentclass{article}

\usepackage{xcolor}
\makeatletter


\def\TeXColored{\textcolor{yellow}{T}\kern-.1667em\lower.5ex\hbox{\textcolor{green}{E}}\kern-.125em\textcolor{brown}{X}\@}

\DeclareRobustCommand{\CLaTeX}{\textcolor{red}{L}\kern-.36em%
        {\sbox\z@ T%
         \vbox to\ht\z@{\hbox{\check@mathfonts
                              \fontsize\sf@size\z@
                              \math@fontsfalse\selectfont
                              \textcolor{blue}{A}}%
                        \vss}%
        }%
        \kern-.15em%
        \TeXColored}
\DeclareRobustCommand{\CLaTeXe}{\mbox{\m@th
  \if b\expandafter\@car\f@series\@nil\fi
  \CLaTeX\kern.15em\textcolor{gray}{2}$_{\color{violet}\textstyle\varepsilon}$}}
\makeatother

\begin{document}

\CLaTeX\ or \LaTeX

\CLaTeXe\ or \LaTeXe

Huge:\huge

\CLaTeX\ or \LaTeX

\CLaTeXe\ or \LaTeXe


\end{document}

在此处输入图片描述

以下是颜色外部规范的更新:

\documentclass{article}

\usepackage{xcolor}
\newcommand{\ALetterColor}{blue}
\newcommand{\LLetterColor}{red}
\newcommand{\ChiLetterColor}{green}
\newcommand{\TwoDigitColor}{gray}
\newcommand{\EpsilonLetterColor}{violet}
\newcommand{\ELetterColor}{brown}
\newcommand{\TLetterColor}{yellow}

\makeatletter



\def\TeXColored{\textcolor{\TLetterColor}{T}\kern-.1667em\lower.5ex\hbox{\textcolor{\ELetterColor}{E}}\kern-.125em\textcolor{\ChiLetterColor}{X}\@}

\DeclareRobustCommand{\CLaTeX}{\textcolor{\LLetterColor}{L}\kern-.36em%
        {\sbox\z@ T%
         \vbox to\ht\z@{\hbox{\check@mathfonts
                              \fontsize\sf@size\z@
                              \math@fontsfalse\selectfont
                              \textcolor{\ALetterColor}{A}}%
                        \vss}%
        }%
        \kern-.15em%
        \TeXColored}
\DeclareRobustCommand{\CLaTeXe}{\mbox{\m@th
  \if b\expandafter\@car\f@series\@nil\fi
  \CLaTeX\kern.15em\textcolor{\TwoDigitColor}{2}$_{\color{\EpsilonLetterColor}\textstyle\varepsilon}$}}
\makeatother

\begin{document}

\CLaTeX\ or \LaTeX

\CLaTeXe\ or \LaTeXe

Huge:\huge

\CLaTeX\ or \LaTeX

\CLaTeXe\ or \LaTeXe


\end{document}

相关内容