2

Is it possible to underline node-text as a style?

I tried something like

\documentclass[]{book}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[
execute at begin node={\underline{ },
execute at end node={ } },
]{Some text that should be underlined.};
\end{tikzpicture}  
\end{document}

but this gives not a good result:
enter image description here

2 Answers 2

4

Like this ?

Edit: with hpekristiansen'comment

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\begin{document}
\tikzset{
  % soul/.style args={#1}{label={\underline{#1}},node contents=},%<-- bof   
  soul/.style args={#1}{node contents={\underline{#1}}},%<-- with  hpekristiansen'comment  
  }
\begin{tikzpicture}
  \node[soul=Some text that should be underlined.];
\end{tikzpicture}  
\end{document}

enter image description here

2
  • 2
    I do not understand the use of the label and deleting contents. It makes other labels difficult and the spacing wrong. Simply do this: soul/.style args={#1}{node contents=\underline{#1}}. Feb 25 at 15:56
  • @hpekristiansen indeed, what you propose is much better, I modified the answer
    – pascal974
    Feb 27 at 12:40
4

You could use the same trick as in @Skillmon's great answer https://topanswers.xyz/tex?q=6276#a6152

(compile with TL2023, there seems to be a problem with TL2024)

% !TeX TS-program = lualatex
\documentclass[]{book}
\usepackage{tikz}
\usepackage{lua-ul}

\makeatletter
\NewDocumentCommand\myunderline{}{
  \@underLine
}
\makeatother

\begin{document}
\begin{tikzpicture}
\node[font=\myunderline]{Some text that should be underlined.};
\end{tikzpicture}  
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .