\linebreak 之后的 \kern 不起作用

\linebreak 之后的 \kern 不起作用

梅威瑟:

\documentclass[a4paper]{article}
\usepackage[margin=30mm]{geometry}
\usepackage{xcolor}
\begin{document}
\noindent this is good that is food this is good that is food this is good that
is food this is good that is food\linebreak\kern-2em\color{red}\relax this is
good that is food \kern-2em\color{blue}\relax this is good that is food this is
good that is food this is good that is food
\end{document}

第二个\kern按预期工作,但第一个不工作。这是因为文本被其左边界阻挡了吗?有没有办法让它\kern在之后工作\linebreak

在此处输入图片描述

答案1

紧排(像胶水一样)是可丢弃因此它们在换行符处被删除(出于同样的原因,它们\hspace会被删除,但是 latex 提供了\hspace*

因此,您可以使用\hspace*{-2em},或者如果您因为某种原因确实想要使用 kern,那么\linebreak\hbox{}\kern-2em将在 kern 之前放置一个不可丢弃的框,以防止它被丢弃。

在此处输入图片描述

\documentclass[a4paper]{article}
\usepackage[margin=30mm]{geometry}
\usepackage{xcolor}
\begin{document}
\noindent this is good that is food this is good that is food this is good that
is food this is good that is food\linebreak\kern-2em\color{red}\relax this is
good that is food \kern-2em\color{blue}\relax this is good that is food this is
good that is food this is good that is food

\noindent this is good that is food this is good that is food this is good that
is food this is good that is food\linebreak\hspace*{-2em}\color{red}\relax this is
good that is food \hspace*{-2em}\color{blue}\relax this is good that is food this is
good that is food this is good that is food

\noindent this is good that is food this is good that is food this is good that
is food this is good that is food\linebreak\hbox{}\kern-2em\color{red}\relax this is
good that is food \hbox{}\kern-2em\color{blue}\relax this is good that is food this is
good that is food this is good that is food




\end{document}

相关内容