我想更改自定义命令中单个字母的颜色\spacedallcaps
。此命令将指定的文本变为大写并更改字母间距。
当我引入时,\textcolor{color}{letter}
它根本不起作用。
此外,只有当指定字母位于单词末尾或开头时,才能从文本中删除该字母\spacedallcaps
。但是当该字母位于单词中间时,我该怎么做呢?
我尝试了以下操作:
\documentclass{article}
\usepackage{color}
\usepackage{textcase} % for \MakeTextUppercase
\usepackage{soul} % for letterspacing
\sodef\allcapsspacing{\upshape}{0.25em}{0.8em}{0.6em} % : {space between letters}{space between words}{0.6em}
\DeclareRobustCommand{\spacedallcaps}[1]{\MakeTextUppercase{\allcapsspacing{#1}}} % all caps with better spacing
\begin{document}
\spacedallcaps{One single colored letter}\\
\spacedallcaps{One single col}\hspace{0.25em}\textcolor{red}{O}\spacedallcaps{red letter}\\
\spacedallcaps{One single col}\hspace{0.25em}\textcolor{red}{O}\hspace{0.25em}\spacedallcaps{red letter}
\end{document}
但结果却不太好:
人们总是可以使用这个\hspace
功能,但它非常繁琐,因为它需要无休止的尝试。
如何才能自动实现这一目标?
答案1
使用xcolor
而不是color
和问题
\colorlet{RED}{red}
因为里面\MakeTextUppercase
也有“大写” 。red
\textcolor
此时(注意\textcolor
括号内)
\spacedallcaps{One single col{\textcolor{red}{O}}red letter}
就足够了。
平均能量损失
\documentclass{article}
\usepackage{xcolor}
\usepackage{textcase} % for \MakeTextUppercase
\usepackage{soul} % for letterspacing
\sodef\allcapsspacing{\upshape}{0.25em}{0.8em}{0.6em} % : {space between letters}{space between words}{0.6em}
\DeclareRobustCommand{\spacedallcaps}[1]{\MakeTextUppercase{\allcapsspacing{#1}}} % all caps with better spacing
\colorlet{RED}{red}
\begin{document}
\spacedallcaps{One single col{\textcolor{red}{O}}red letter}
\end{document}
输出
我想补充一条建议克里斯托弗用于调整字母之间的间距。
\documentclass{article}
\usepackage{xcolor}
\usepackage[letterspace=150]{microtype}
\DeclareRobustCommand{\spacedallcaps}[1]{\MakeUppercase{\textsc{#1}}} % all caps with better spacing
\colorlet{RED}{red}
\begin{document}
\spacedallcaps{\lsstyle One single col\textcolor{red}{O}red letter}
\end{document}
答案2
您可以注册以下命令soul
:
\documentclass{article}
\usepackage{color}
\usepackage{textcase} % for \MakeTextUppercase
\usepackage{soul} % for letterspacing
\sodef\allcapsspacing{\upshape}{0.25em}{0.8em}{0.6em} % : {space between letters}{space between words}{0.6em}
\DeclareRobustCommand{\spacedallcaps}[1]{%
\MakeTextUppercase{\allcapsspacing{#1}}%
} % all caps with better spacing
\DeclareRobustCommand{\makered}[1]{\textcolor{red}{#1}}
\soulregister{\makered}{1}
\begin{document}
\spacedallcaps{One single col{\makered{o}}red letter}
\end{document}
答案3
只是想看看这是否适用于我的\spaceout
宏,而不是使用soul
。
已编辑,以提供单独的词间间距。
提供定义\theLetterSpace
和\theWordSpace
默认的字母间和单词间间距(\theWordSpace
注意此外\
单词换行时的自然间距)。默认情况下,我将其设置\theWordSpace
为 1.5 倍的本地字母间距,并根据\theLetterSpace
变化动态调整。也可以使用可选参数更改字母间距的本地值\spaceout
,如 MWE 中所示。
\documentclass{article}
\usepackage{xcolor}
\def\theLetterSpace{0.5pt}
\def\theWordSpace{1.5\LocalLetterSpace}
\newlength\LocalLetterSpace
\newcommand\spaceout[2][\theLetterSpace]{%
\setlength\LocalLetterSpace{#1}\expandafter\spaceouthelpA#2 \relax\relax}
\def\spaceouthelpA#1 #2\relax{%
\spaceouthelpB#1\relax\relax%
\ifx\relax#2\else\ \kern\theWordSpace\spaceouthelpA#2\relax\fi
}
\def\spaceouthelpB#1#2\relax{%
#1%
\ifx\relax#2\else
\kern\LocalLetterSpace\spaceouthelpB#2\relax%
\fi
}
\parskip 1ex
\colorlet{RED}{red}
\begin{document}
test \uppercase{\spaceout[5pt]{one single col{\textcolor{red}{o}}red letter}} with 5pt added spacing
test \uppercase{\spaceout[3pt]{one single col{\textcolor{red}{o}}red letter}} with 3pt added spacing
test \uppercase{\spaceout[1pt]{one single col{\textcolor{red}{o}}red letter}} with 1pt added spacing
\def\theWordSpace{5\LocalLetterSpace}Change the inter-word spacing to 5 x local letter spacing.
test \uppercase{\spaceout[1pt]{one single col{\textcolor{red}{o}}red letter}} with 1pt added spacing
\end{document}