均勻地為格式化文字添加下劃線,以便下行部分(如“y”)與該行重疊

均勻地為格式化文字添加下劃線,以便下行部分(如“y”)與該行重疊

我正在嘗試為格式化文字添加下劃線。

我想做的是:

\usepackage{xcolor}
\usepackage{tikz}

\newcommand{\udensdot}[1]{%
    \tikz[baseline=(todotted.base)]{
        \node[inner sep=1pt,outer sep=0pt] (todotted) {#1};
        \draw[densely dotted] (todotted.south west) -- (todotted.south east);
    }%
}%

\newcommand{\ans}[1]{\udensdot{    
        \textcolor{blue}{\fontfamily{pzc}\selectfont{~#1~}}
    }
}
\begin{document}
I go to \ans{the} cinema in \ans{the} evening \ans{eventually}.
\end{document}

我得到以下結果,其中最後一行位於其他行下方:

結果線

我希望所有線條都處於同一水平,以便下降部分(如此處的“y”)與下劃線重疊,但我不知道如何實現這一點。

有什麼建議麼?

答案1

您是否希望黑點覆蓋文字短語的藍色,如圖所示?

在此輸入影像描述

如果沒有,但您希望點位於文字行的基線上,並且文字短語的藍色覆蓋點的黑色,您可以使用 來建立一個節點,\phantom繪製線條,然後建立一個節點以文字取代\phantom

\documentclass[border=6pt]{standalone}
\usepackage{xcolor}
\usepackage{tikz}

\newcommand{\udensdot}[1]{%
    \tikz[baseline=(todotted.base)]{
        \node[inner sep=1pt,outer sep=0pt] (todotted) {\phantom{\mbox{#1}}};
        \draw[densely dotted] (todotted.base west) -- (todotted.base east);
        \node at (todotted) [inner sep=1pt,outer sep=0pt] {\mbox{#1}};
    }%
}

\newcommand{\ans}[1]{\udensdot{%
        \textcolor{blue}{\fontfamily{pzc}\selectfont{~#1~}}%
    }%
}
\begin{document}
I go to \ans{the} cinema in \ans{the} evening \ans{eventually}.
\end{document}

在此輸入影像描述

在此輸入影像描述

答案2

您可以使用類似以下的包,而不是在 TikZ 中創建自己的下劃線lua-ul

% !TeX TS-program = lualatex
\documentclass{article}
\usepackage{lua-ul}
\usepackage{xcolor}

\usepackage{fontspec}
\newfontfamily{\zapf}{Zapf Chancery}

\makeatletter
\newunderlinetype\beginUnderDot{\cleaders\hb@xt@ .44em{\hss\raisebox{-0.5ex}{.}\hss}}
\makeatother
\NewDocumentCommand\underDot{+m}{{\beginUnderDot#1}}

\newcommand{\ans}[1]{%
  {\zapf\underDot{~\textcolor{blue}{#1}~}}%
}
\begin{document}
I go to \ans{the} cinema in \ans{the} evening \ans{eventually}.
\end{document}

在此輸入影像描述

或者ulem

\documentclass{article}
\usepackage[normalem]{ulem}
\usepackage{xcolor}

\newcommand{\ans}[1]{%
  {\fontfamily{pzc}\selectfont\dotuline{~\textcolor{blue}{#1}~}}%
}
\begin{document}
I go to \ans{the} cinema in \ans{the} evening \ans{eventually}.
\end{document}

在此輸入影像描述

答案3

解決方案是在命令中使用base westand 。base east\udensdot

在此輸入影像描述

\documentclass[border=6pt]{standalone}
\usepackage{xcolor}
\usepackage{tikz}

\newcommand{\udensdot}[1]{%
    \tikz[baseline=(todotted.base)]{
        \node[inner sep=1pt,outer sep=0pt] (todotted) {#1};
        \draw[densely dotted] (todotted.base west) -- (todotted.base east);
    }%
}

\newcommand{\ans}[1]{\udensdot{%
        \textcolor{blue}{\fontfamily{pzc}\selectfont{~#1~}}%
    }%
}
\begin{document}
I go to \ans{the} cinema in \ans{the} evening \ans{eventually}.
\end{document}

相關內容