# How can I underline multiple parts of the same word using braces with TikZ?

UPDATE: I opened a related question here.

I work in the field of linguistics and I sometimes need to analyze prefixes, affixes, and suffixes in words. It would be nice to be able to add notes to various parts of words using TikZ. So far, I can do almost what I would like. The problem is that I cannot put multiple parts of a word into separate nodes without an awkward space in between (making it look like multiple words) e.g. taivaissa should be one word (I would like to underline taiva, the root word, and put an explanation underneath and underline the suffix -issa, and also have an explanation underneath.

Criteria:

• The solution should allow control over the distance from the bottom (or top depending on orientation) of the curly bracket (brace) to the description, in order to avoid potential overlapping when using long descriptions within the same word. (Ideally, the distance of the brace to word will also be variable as in the example below.)

• The solution does not need to include the dependency-tikz package, I just use it here because it is an easy way to clearly and literally translate individual words. It would be a plus, however!

The Code:

\documentclass[]{beamer}
\usepackage{fontspec}
\usepackage{tikz-dependency}
% Klammern in Formeln
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calc}
\usepackage{xparse}
\NewDocumentCommand{\tikzbrace}{O{-2.5ex} m m O{} O{}}{%
\tikz[remember picture]\coordinate (left brace coord);%
#2%
\tikz[remember picture]\coordinate (right brace coord);%
\begin{tikzpicture}[remember picture,overlay,
transform canvas={yshift=#1}]
\draw [decoration={amplitude=1ex,brace},decorate,#4] %
(right brace coord) -- (left brace coord)
node [midway,below=1ex,font=\scriptsize,#5] {#3};
\end{tikzpicture}
}

\begin{document}
\begin{frame}{Satz 1}
\begin{dependency}[edge style={red,densely dotted}]
\begin{deptext}
\tikzbrace[-1ex]{Isae}{Vater} \& meidän, \& joka \& \tikzbrace[-1ex]{olet}{2Psg} \& \tikzbrace[-5ex]{taiva}{-\emph{issa}=pl (sg -\emph{ssa}) Inessiv, ähnlich Lokativ, e.g. talossa "in dem Haus"}issa,\\
\end{deptext}
\deproot[edge unit distance=1ex]{1}{Vater}
\deproot[edge unit distance=1ex]{2}{unserer}
\deproot[edge unit distance=1ex]{3}{wer}
\end{dependency}
\end{frame}
\end{document}

-

There is a "leaking space" in the definition of \tikzbrace, just after \end{tikzpicture}. The solution is thus to put a percent sign after it, like this:

\NewDocumentCommand{\tikzbrace}{O{-2.5ex} m m O{} O{}}{%
\tikz[remember picture]\coordinate (left brace coord);%
#2%
\tikz[remember picture]\coordinate (right brace coord);%
\begin{tikzpicture}[remember picture,overlay,
transform canvas={yshift=#1}]
\draw [decoration={amplitude=1ex,brace},decorate,#4] %
(right brace coord) -- (left brace coord)
node [midway,below=1ex,font=\scriptsize,#5] {#3};
\end{tikzpicture}%
}

-
great! I would like to get my criteria met, however! See description above. It is pointless to underline taiva and issa if I can't control the distance of the descriptions from the braces (to avoid overlap). –  macmadness86 Apr 2 '13 at 7:48
I've marked your answer correct as a minimum answer. Maybe you or someone else will choose to elaborate a bit. In the meantime, I am going to open a new question with a few more specifics. Really useful tip, thanks! –  macmadness86 Apr 2 '13 at 8:33