我正在尝试为格式化的文本添加下划线。
我想要做的事情如下:
\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 west
和。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}