可断开下划线,不会造成换行混乱

可断开下划线,不会造成换行混乱

中文单词之间没有空格,所以相邻的下划线会连在一起。xeCJK包中提供了CJKunderline-命令,但是生成的下划线不对称(左端往往太短),而且不能直接自定义。

一个旧的解决方案提供了替代解决方案中国邮政下划线看起来不错,但不幸的是会干扰换行:

\documentclass[a4paper, 10pt]{article}

\usepackage{xcolor, indentfirst}
\usepackage[
  left=3.2cm, right=3.2cm,
  top=3.8cm, bottom=3.8cm,
]{geometry}

\usepackage[quiet]{fontspec}
\usepackage{xeCJK}
\setCJKmainfont{SimSun}

\setlength{\parindent}{2em}
\renewcommand{\baselinestretch}{1.3}

\usepackage[normalem]{ulem}

% How to make \myuline not mess with line breaking?
\newcommand{\basiculine}{\bgroup\markoverwith{\textcolor{gray}{\rule[-0.32em]{1pt}{0.54pt}}}\ULon}
\newcommand{\myuline}[1]{\hskip0.1em\basiculine{\kern-0.1em\hbox{#1\kern-0.1em}}\hskip0.1em}

\begin{document}

进得诏便行。\myuline{主簿}\myuline{陈琳}谏曰:“太后此诏,必是十常侍之谋,切不可去。去必有祸,\myuline{不骗你呀}。”进曰:“\myuline{太后}\myuline{诏我},有何祸事?”

\end{document}

下划线推开了标点符号。

第一行的最后一条下划线将标点符号推到下一行的开头。我对 TeX 构造一点也不熟悉。请问如何改进?

答案1

TeX 总是允许在 处断行\hskip,除非明确指示不要这样做:

\documentclass[a4paper, 10pt]{article}

\usepackage{xcolor, indentfirst}
\usepackage[
  left=3.2cm, right=3.2cm,
  top=3.8cm, bottom=3.8cm,
]{geometry}

\usepackage[quiet]{fontspec}
\usepackage{xeCJK}
\setCJKmainfont{SimSun}

\setlength{\parindent}{2em}
\renewcommand{\baselinestretch}{1.3}

\usepackage[normalem]{ulem}

% How to make \myuline not mess with line breaking?
\newcommand{\basiculine}{%
  \bgroup\markoverwith{\textcolor{gray}{\rule[-0.32em]{1pt}{0.54pt}}}\ULon
}
\newcommand{\myuline}[1]{%
  \hspace{0.1em}%
  \basiculine{\kern-0.1em\hbox{#1\kern-0.1em}}%
  \nobreak % <----- no line break before the space
  \hspace{0.1em}%
}

\begin{document}

进得诏便行。\myuline{主簿}\myuline{陈琳}谏曰:“太后此诏,必是十常侍之谋,切不可去。去必有祸,\myuline{不骗你呀}。”进曰:“\myuline{太后}\myuline{诏我},有何祸事?”

\end{document}

在此处输入图片描述

相关内容