我调教Gemini,使用tikz给相邻两段中文绘制下划线或波浪线,下划线/波浪线不粘连了,也没有错误的中文字距的问题,但是产生一些新的问题,问得Gemini无解:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing, calc}
\usepackage{xcolor}
\usepackage{xeCJK}
\begin{document}
% 测量各个文本部分的宽度
\newlength{\widthA}
\newlength{\widthB}
\newlength{\widthC}
\newlength{\widthD}
\settowidth{\widthA}{史}
\settowidth{\widthB}{管子君臣}
\settowidth{\widthC}{中庸}
\settowidth{\widthD}{及}
% 定义一个新命令,用于绘制整行并精确对齐
\newcommand{\myWaveLine}[4]{
\begin{tikzpicture}[baseline=(c.base)]
% 将所有文本放在一个节点中
\node (c) [inner sep=0pt, at={(0,0)}, anchor=west] {#1#2#3#4};
% 绘制第一段波浪线
\draw[decorate, decoration={snake, amplitude=0.5pt, segment length=1.5pt}, line width=0.3pt]
($(c.south west)+(\widthA,-2pt)$) -- ($(c.south west)+(\widthA+\widthB,-2pt)$);
% 绘制第二段波浪线
\draw[decorate, decoration={snake, amplitude=0.5pt, segment length=1.5pt}, line width=0.3pt]
($(c.south west)+(\widthA+\widthB,-2pt)$) -- ($(c.south west)+(\widthA+\widthB+\widthC,-2pt)$);
% 使用白色矩形创建间隙,并遮盖不完美的波形
\fill [white, opacity=1.0] ($(c.south west)+(\widthA-0.2pt, -10pt)$) rectangle ($(c.south west)+(\widthA+0.2pt, 10pt)$);
\fill [white, opacity=1.0] ($(c.south west)+(\widthA+\widthB-0.4pt, -10pt)$) rectangle ($(c.south west)+(\widthA+\widthB+0.4pt, 10pt)$);
\end{tikzpicture}
}
\noindent
管子君臣中庸
\noindent
史管子君臣中庸及
\noindent
\myWaveLine{史}{管子君臣}{中庸}{及}
% 移除 tikzpicture 引入的额外间距
\vspace{-5pt}
\noindent
史管子君臣中庸及
\end{document}这段代码中,在使用noindent,绘制波浪线之后,无法左对齐;
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing, calc}
\usepackage{xcolor}
\usepackage{xeCJK}
\begin{document}
% 测量各个文本部分的宽度
\newlength{\widthA}
\newlength{\widthB}
\newlength{\widthC}
\newlength{\widthD}
\settowidth{\widthA}{史}
\settowidth{\widthB}{管子君臣}
\settowidth{\widthC}{中庸}
\settowidth{\widthD}{及}
% 定义一个新命令,用于绘制整行并精确对齐
\newcommand{\myWaveLine}[4]{
\begin{tikzpicture}[baseline=(c.base)]
% 将所有文本放在一个节点中
\node (c) [inner sep=0pt, at={(0,0)}, anchor=west] {#1#2#3#4};
% 绘制第一段直线
\draw[line width=0.3pt]
($(c.south west)+(\widthA,-2pt)$) -- ($(c.south west)+(\widthA+\widthB,-2pt)$);
% 绘制第二段直线
\draw[line width=0.3pt]
($(c.south west)+(\widthA+\widthB,-2pt)$) -- ($(c.south west)+(\widthA+\widthB+\widthC,-2pt)$);
% 使用白色矩形创建间隙,并遮盖不完美的直线
\fill [white, opacity=1.0] ($(c.south west)+(\widthA-0.2pt, -10pt)$) rectangle ($(c.south west)+(\widthA+0.2pt, 10pt)$);
\fill [white, opacity=1.0] ($(c.south west)+(\widthA+\widthB-0.4pt, -10pt)$) rectangle ($(c.south west)+(\widthA+\widthB+0.4pt, 10pt)$);
\end{tikzpicture}
}
\noindent
管子君臣中庸
\noindent
史管子君臣中庸及
\noindent
\myWaveLine{史}{管子君臣}{中庸}{及}
% 移除 tikzpicture 引入的额外间距
\vspace{-5pt}
\noindent
史管子君臣中庸及
\end{document}这段代码中,在使用noindent,绘制下划线之后,无法左对齐。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing, calc, positioning}
\usepackage{xcolor}
\usepackage{xeCJK}
\begin{document}
% 您原始的、能够工作的波浪线宏
\def\mywaveunderline#1{%
\tikz[baseline=(node.south)]{
\node[inner sep=0pt](node){#1};
\draw[decorate, decoration={snake, amplitude=0.5pt, segment length=1.5pt}, line width=0.3pt, overlay, shorten >=0pt, shorten <=0pt] ($(node.south west)+(0pt,-2pt)$) -- ($(node.south east)+(0pt,-2pt)$);
}%
}
% 测量各个文本部分的宽度
\settowidth{\dimen0}{史}
\settowidth{\dimen1}{管子君臣}
\settowidth{\dimen2}{中庸}
\settowidth{\dimen3}{及}
% --- 最终的、可靠的排版方法 ---
\noindent
管子君臣中庸
\noindent
史管子君臣中庸及
\noindent
史管子君臣中庸及
\noindent
% 使用一个 TikZ 环境来精确排版第二行
\begin{tikzpicture}[baseline=(c.base)]
% 放置所有文字,但使用 \hphantom 确保它们不占空间,以便我们可以手动定位波浪线
\node[inner sep=0pt, anchor=west] (c) at (0,0) {\hphantom{史}\mywaveunderline{管子君臣}\mywaveunderline{中庸}\hphantom{及}};
% 绘制“史”和“及”两个字,并确保它们的对齐
\node[anchor=west, inner sep=0pt] at (c.west) {史};
\node[anchor=west, inner sep=0pt, right=0pt of c.east]{及};
\end{tikzpicture}
\noindent
史管子君臣中庸及
\end{document}这段代码,尝试解决左对齐的问题,但是两段波浪线又连在一起,庸和及两字之间出现了不该有的空白,此后,就问得Gemini胡说了。有大佬基于此三段代码实现一个完美的解决方法吗?先在此谢谢了。

问 如何实现符合中文字距的下划线和下划波浪线?