1

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
._._._._
_ _ _ _
4

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}
  • this seems to affect the linespread. – Runar Sep 5 '16 at 18:55
  • @RunarTrollet That depends. As far as I can see, the linespread is affected in case the lines take more space than the gap between the lines. But isn't this good? The alternative would be the lines interfering with the next line? i.stack.imgur.com/BKf1J.png – user36296 Sep 5 '16 at 19:07
  • Yes, I agree that in the case one uses a too big underline, that should happen to give a clear indication that the underlining is too big. But in my opinion one shouldn't make a underling that streches below the lowest part of characters, like g,y and such. Don't know the typographical name for this in English. – Runar Sep 5 '16 at 19:17
  • @RunarTrollet I think they are called "decent". And you're right, I just tried my example with a decenting character and it looks horrible. I think I know why I use underlining only in handwritten text :) – user36296 Sep 5 '16 at 19:31
  • Thank you. There was a post here somewhere with some underlining which did not go into the descendants but left a bit of space around it, which made underlining almost beautiful. Cannot find it at the moment though. – Runar Sep 5 '16 at 19:36
4

Updated with the dashing and dashdot. Also doesn't effect spacing on the line below anymore.

Output

enter image description here

Code

\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}
  • The first line should be dash-dotted and the second one dashed. See my added example – Ben Sep 4 '16 at 18:44
  • Using . and _ aren't at the same high, so .\_ doesn't really produce a line – Ben Sep 4 '16 at 19:09
  • @Ben I just made some minor changes, so it should now give the requested output. – Runar Sep 5 '16 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.