Como escrever uma palavra em duas cores diferentes?
Tenho uma palavra e gostaria de escrevê-la em duas cores diferentes. Normalmente, haverá um espaço entre as duas \textcolo
seções
\textcolor{sectcol}{la}\textcolor{white}{tex}
Posso "remover" o espaço com um negativo \hspace
.
\textcolor{sectcol}{la}\hspace{-1mm}\textcolor{white}{tex}
Existe uma maneira melhor de fazer isso?
Respostas
inserções de cores chamadas whatits
, e isso impedirá o kerning:
\documentclass{article}
\usepackage{color}
\begin{document}
VA
\textcolor{red}{V}\textcolor{blue}{A}
\end{document}

Não há muito que você possa fazer sobre isso (além de inserir espaço negativo). A única maneira de realmente evitá-lo é usar o motor lualatex e o pacote luacolor:
\documentclass{article}
\usepackage{luacolor}
\begin{document}
VA
\textcolor{red}{V}\textcolor{blue}{A}
\end{document}

Seu exemplo não é bom, porque não há kerning entre “a” e “t” nas fontes padrão.
Se você pdflatex
não consegue usar o LuaTeX, pode calcular manualmente o kerning necessário.
\documentclass{article}
\usepackage{xcolor,xparse}
\ExplSyntaxOn
\NewDocumentCommand{\twocolors}{mmmm}
{% #1 = color for the first part
% #2 = first part
% #3 = color for the second part
% #4 = second part
\egreg_twocolors:nnnn { #1 } { #2 } { #3 } { #4 }
}
\box_new:N \l__egreg_twocolors_kern_box
\box_new:N \l__egreg_twocolors_nokern_box
\cs_new_protected:Nn \egreg_twocolors:nnnn
{
\hbox_set:Nn \l__egreg_twocolors_kern_box
{
\tl_item:nn { #2 } { -1 }
\tl_item:nn { #4 } { 1 } % could just be \tl_head:n
}
\hbox_set:Nn \l__egreg_twocolors_nokern_box
{
\hbox:n { \tl_item:nn { #2 } { -1 } }
\hbox:n { \tl_item:nn { #4 } { 1 } } % could just be \tl_head:n
}
\textcolor{#1}{#2}
\skip_horizontal:n
{
\box_wd:N \l__egreg_twocolors_kern_box - \box_wd:N \l__egreg_twocolors_nokern_box
}
\textcolor{#3}{#4}
}
\ExplSyntaxOff
\begin{document}
\twocolors{green!50!blue}{two}{red!30}{color}
twocolor
\makebox[0pt][l]{twocolor}\twocolors{green!50!blue}{two}{red!30}{color}
\makebox[0pt][l]{\twocolors{green!50!blue}{two}{red!30}{color}}twocolor
\twocolors{green!50!blue}{la}{red!30}{tex}
latex
\makebox[0pt][l]{latex}\twocolors{green!50!blue}{la}{red!30}{tex}
\makebox[0pt][l]{\twocolors{green!50!blue}{la}{red!30}{tex}}latex
\twocolors{green!50!blue}{V}{red!30}{A}
VA
\makebox[0pt][l]{VA}\twocolors{green!50!blue}{V}{red!30}{A}
\makebox[0pt][l]{\twocolors{green!50!blue}{V}{red!30}{A}}VA
\end{document}
Cada exemplo tem a verificação de que as cores não vazam. No entanto, em resoluções pequenas, o rasterizador pode mostrar artefatos. A imagem abaixo foi tirada em alta resolução.
Limitação: se o último item da primeira parte ou o primeiro item da segunda parte for uma letra acentuada, coloque uma chave (ou eles).
