如何用点划线给单词加下划线?
实际上,单词下方应该有一条点划线,而这条线下方应该是一条虚线。
注意:我知道,不应该加下划线。
例子:
longword
._._._._
_ _ _ _
答案1
主要基于https://tex.stackexchange.com/a/27260/36296
\documentclass{article}
\usepackage{tikz}
\newcommand{\mydash}[1]{%
\tikz[baseline=(todotted.base)]{
\node[inner sep=1pt,outer sep=0pt] (todotted) {#1};
\draw[dash dot] (todotted.south west) -- (todotted.south east);
\draw[dashed] ([yshift=-2pt]todotted.south west) -- ([yshift=-2pt]todotted.south east);
}%
}%
\begin{document}
\mydash{double line}
\end{document}
尽管上述解决方案对要加下划线的单词的位置很敏感(例如,如果j
单词中有字母),但以下解决方案会将线放在相同的位置,而不管字符是什么。
\documentclass{article}
\usepackage{tikz}
\usepackage{lipsum}
\newcommand{\mydash}[1]{%
\tikz[baseline=(todotted.base)]{
\node[inner sep=1pt,outer sep=0pt] (todotted) {\strut #1};
\draw[dash dot] ([yshift=3pt]todotted.south west) -- ([yshift=3pt]todotted.south east);
\draw[dashed] ([yshift=2pt]todotted.south west) -- ([yshift=2pt]todotted.south east);
}%
}%
\begin{document}
\mydash{doguble line}
\lipsum[2]
\mydash{double line}
\lipsum[2]
\end{document}
答案2
更新了虚线和虚线点。并且不再影响下行的间距。
输出
代码
\documentclass{article}
\usepackage{calc}
\newcommand{\underDotDash}[1]{%
\parbox[b][0pt][l]{0pt}{%
\raisebox{-.3ex}{%
\makebox[\widthof{#1}]{%
\xleaders\hbox{\rule{.8ex}{0.5pt}\,\rule{.5pt}{0.5pt}\,}\hfill}%
}
}%
\parbox[b][0pt][l]{0pt}{%
\raisebox{-.6ex}{%
\makebox[\widthof{#1}]{%
\xleaders\hbox{\rule{1ex}{0.5pt}\,}\hfill}%
}
}%
#1%
}
\begin{document}
Here is \underDotDash{some text}, doesn't it look wonderful? Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur imperdiet ante a turpis pulvinar, quis pharetra lorem finibus. Sed iaculis ritus sed molestie elementum. Duis porta maximus velit quis imperdiet. Sed nec lacis vitae nisl rutrum accumsan. Nam molestie purus hendrerit ex tempus volutpat. Donec luctus, nulla nec molestie eleifend, lectus sapien rhoncus nisl, id maximus diam ex sed metus. Present volutpat eu mi in vehicula. In lobortis vitae magna at finibus. Phasellus tempor urna eros, consequat blandit sem rhoncus a. Aliquam erat volutpat. Aliquam venenatis maximus felis, vel feugiat mauris tincidunt mattis. Maecenas accumsan metus nec tortor tempor maximus.
\end{document}