[Tex/LaTex] Underlining with dash-dotted line

formattinghighlightingline

How to underline a word with a dash-dotted line?

Actually there should be the dash-dotted line under the word and under this line here should be a dashed line.

Note: I know, that underlining shouldn't be done.

Example:

longword
._._._._
_ _ _ _

Best Answer

Heavily based on 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}

enter image description here


While the above solution is sensitive to the decent of the words to be underlined (e.g. if there are letters such as j in the words), the following will place the lines at the same position, regardless the characters.

 \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}