我正在尝试创建这种效果:
(没有红色下划线,我用 Word 做了这个例子,用红色强调了他不认识的单词)。
我使用了该包艾特特这:
\begin{alltt}
text 1: Quicq fyre | text 1: Slow fool
text 2: Quick fire | text 2: Quick fire
Diff: Quic\colorbox{lightred}{q}\colorbox{lightgreen}{k} f\colorbox{lightred}{y}\colorbox{lightgreen}{i}re | Diff: SlowQuick foolire
Split: Quic\colorbox{lightred}{q}\colorbox{lightgreen}{k}\colorbox{lightred}{ f}\colorbox{lightgreen}{ f}\colorbox{lightred}{y}\colorbox{lightgreen}{i}re | Split: SlowQuick f foolire
Merge: Quic\colorbox{lightred}{q fy}\colorbox{lightgreen}{k fi}re | Merge: Slow foolQuick fire
\end{alltt}
结果是:
如你所见,下划线是交错的。因此结果并不像预期的那样。
我该如何使用才能获得更像第一张图片的东西?我没有使用包清单因为我已经将它用于一些格式与本文格式不同的代码。
答案1
我建议您删除添加的填充\colorbox
;可以通过添加带有上升部和下降部的幻影来解决交错问题。
\documentclass{article}
\usepackage{xcolor,alltt}
\colorlet{lightgreen}{green!30}
\colorlet{lightred}{red!30}
\newcommand{\?}[2]{%
\begingroup\setlength{\fboxsep}{0pt}%
\colorbox{#1}{\vphantom{fg}#2}%
\endgroup
}
\begin{document}
\begin{alltt}
text 1: Quicq fyre | text 1: Slow fool
text 2: Quick fire | text 2: Quick fire
Diff: Quic\?{lightred}{q}\?{lightgreen}{k} f\?{lightred}{y}\?{lightgreen}{i}re | Diff: SlowQuick foolire
Split: Quic\?{lightred}{q}\?{lightgreen}{k}\?{lightred}{ f}\?{lightgreen}{ f}\?{lightred}{y}\?{lightgreen}{i}re | Split: SlowQuick f foolire
Merge: Quic\?{lightred}{q fy}\?{lightgreen}{k fi}re | Merge: Slow foolQuick fire
\end{alltt}
\end{document}
可以通过将位存储在框中,然后在打印项目后套印规则来实现删除线或下划线。
\documentclass{article}
\usepackage{xcolor,alltt}
\colorlet{lightgreen}{green!30}
\colorlet{lightred}{red!30}
\newsavebox{\RGbox}
\newcommand{\R}[1]{%
\begingroup\setlength{\fboxsep}{0pt}%
\sbox{\RGbox}{\colorbox{lightred}{\vphantom{fg}#1}}%
\usebox{\RGbox}%
\makebox[0pt][r]{\vrule width \wd\RGbox height .5ex depth -\dimexpr.5ex-0.4pt\relax}%
\endgroup
}
\newcommand{\G}[1]{%
\begingroup\setlength{\fboxsep}{0pt}%
\sbox{\RGbox}{\colorbox{lightgreen}{\vphantom{fg}#1}}%
\usebox{\RGbox}%
\makebox[0pt][r]{\vrule width \wd\RGbox height -\dimexpr\dp\RGbox-0.4pt\relax depth \dp\RGbox}%
\endgroup
}
\begin{document}
\begin{alltt}
text 1: Quicq fyre | text 1: Slow fool
text 2: Quick fire | text 2: Quick fire
Diff: Quic\R{q}\G{k} f\R{y}\G{i}re | Diff: SlowQuick foolire
Split: Quic\R{q}\G{k}\R{ f}\G{ f}\R{y}\G{i}re | Split: SlowQuick f foolire
Merge: Quic\R{q fy}\G{k fi}re | Merge: Slow foolQuick fire
\end{alltt}
\end{document}
放大彩色条目