3

I'm trying to draw a line beneath a node. The macro is used to label parts of a sentence. Here is the code;

\documentclass{article}
\usepackage{tikz}


\newcommand{\LabelText}[3]{%
  \begin{tikzpicture}[baseline=(LabelText.base)]
    \node(a) [
      text width=width("{#1}"),
      text centered,
      draw=none,
      thick,
      rectangle,
      inner sep=0pt,
      outer sep=0pt,
      fill={#3},
    ] (LabelText) {#2};
    \path[draw=black, very thick] (a.south west) -- (a.south east);
  \end{tikzpicture}%
}



\newcommand{\padv}[1]{\LabelText{#1}{\strut Adv}{blue!30}}%

\begin{document}
  This is an \padv{adverb}
\end{document}

The \path statement is supposed to draw a line beneath the node, but I get the error "No shape named a is known". The code compiles perfectly without the \path statement, but unfortunately no line is drawn.

Any help appreciated.

1
  • Isn't the node name LabelText?
    – Rmano
    Apr 5, 2016 at 17:48

1 Answer 1

3

Use the current bounding box instead of naming the node. To do this, you can replace your \path command with \draw[very thick](current bounding box.south west) -- (current bounding box.south east);

\documentclass{article}
\usepackage{tikz}

\newcommand{\LabelText}[3]{%
  \begin{tikzpicture}[baseline=(LabelText.base)]
    \node[
      text width=width("{#1}"),
      text centered,
      draw=none,
      thick,
      rectangle,
      inner sep=0pt,
      outer sep=0pt,
      fill={#3},
    ] (LabelText) {#2};
    \draw[very thick](current bounding box.south west) -- (current bounding box.south east);
  \end{tikzpicture}%
}

\newcommand{\padv}[1]{\LabelText{#1}{\strut Adv}{blue!30}}%

\begin{document}
  This is an \padv{adverb}
\end{document}

enter image description here

0

You must log in to answer this question.

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