วิธีการเขียนคำหนึ่งคำในสองสีที่แตกต่างกัน?
ฉันมีคำเดียวและอยากจะเขียนเป็นสองสีที่ต่างกัน โดยปกติจะมีช่องว่างระหว่างสอง\textcolo
ส่วน
\textcolor{sectcol}{la}\textcolor{white}{tex}
ฉันสามารถ "ลบ" \hspace
พื้นที่ที่มีเชิงลบ
\textcolor{sectcol}{la}\hspace{-1mm}\textcolor{white}{tex}
มีวิธีที่ดีกว่านี้หรือไม่?
คำตอบ
เม็ดมีดสีที่เรียกว่าwhatits
และสิ่งนี้จะป้องกันไม่ให้เกิดปัญหา:
\documentclass{article}
\usepackage{color}
\begin{document}
VA
\textcolor{red}{V}\textcolor{blue}{A}
\end{document}

คุณสามารถทำอะไรได้ไม่มากนัก (นอกเหนือจากการใส่ช่องว่างเชิงลบ) วิธีเดียวที่จะหลีกเลี่ยงได้จริงๆคือใช้เครื่องยนต์ lualatex และแพ็คเกจ luacolor:
\documentclass{article}
\usepackage{luacolor}
\begin{document}
VA
\textcolor{red}{V}\textcolor{blue}{A}
\end{document}

ตัวอย่างของคุณไม่ดีนักเนื่องจากไม่มีความสำคัญระหว่าง“ a” และ“ t” ในแบบอักษรมาตรฐาน
หากคุณติดขัดpdflatex
และไม่สามารถใช้ LuaTeX ได้คุณสามารถคำนวณข้อมูลที่จำเป็นได้ด้วยตนเอง
\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}
แต่ละตัวอย่างมีการตรวจสอบว่าสีไม่รั่วไหล อย่างไรก็ตามด้วยความละเอียดขนาดเล็ก rasterer อาจแสดงสิ่งประดิษฐ์ ภาพด้านล่างถ่ายด้วยความละเอียดค่อนข้างสูง
ข้อ จำกัด : หากรายการสุดท้ายในส่วนแรกหรือรายการแรกในส่วนที่สองเป็นตัวอักษรเน้นเสียงให้รั้ง (หรือพวกเขา)
