I would like to use underbrace in order to clarify some text and after some searching I found a solution using the Tikz package. However I am having some trouble with the vertical alignment. Here is a MWE of illustrating my problem:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usetikzlibrary{decorations.pathreplacing}
\tikzstyle{underbrace style}=[decorate,decoration={brace,raise=0.5mm,amplitude=3pt,mirror,pre=moveto,pre length=1pt,post=moveto,post length=1pt}]
\tikzstyle{underbrace text style}=[font=\tiny, below, pos=.5, yshift=-1mm]
\newcommand{\tikzunderbrace}[2]{\draw [underbrace style] (#1.south west) -- (#1.south east) node [underbrace text style] {#2};}
\begin{document}
Begining text
\begin{tikzpicture}
\matrix[matrix of nodes, inner sep=0pt, column sep=0pt, nodes={anchor=south}, text height=1.5ex,text depth=.25ex]{
\node (text) {some underlined text};\
};
\tikzunderbrace{text}{explanation}
\end{tikzpicture}
and some more text
\end{document}
Here is the result that I get:
As you can see, the text is vertically not aligned. After searching some more, I realized that I have to add an option to the tikzpicture environment.
I tried the following option [baseline={(text.south)}] which gave me the following result:
as well as [baseline={([yshift={-\ht\strutbox}]text.north)}], which gave me the following result:
As you can see, in both cases the alignment is not good. I would like the entire text to appear on the same line.
Could someone please help me out with what parameters I need to use in order to achieve proper vertical alignment? Thank you very much in advance.
PS. I am using the matrix environment because my actual document is more complicated than what I am showing here. I've just stripped it down for the case of a MWE.






baseline={(text.base)}– Wulle Mar 25 '21 at 17:01tikzpictureenvironment? Otherwise theamsmathpackage andunderbracewill do the job. – Excelsior Mar 25 '21 at 17:04underbracecommand in theamsmathmodule, however for my actual example and not the MWE, it cannot meet my needs. Thank you. – jopeto Mar 25 '21 at 17:22tikzmarklibrary provides a more legible solution, and allows you to mark multiple nodes with content that you refer to afterwards. We don't know exactly your project requirements but I suggest that you take a look at it. See my solution below. – SebGlav Mar 25 '21 at 21:59\begin{tikzpicture}[baseline=-0.12cm]as in the answer below – js bibra Mar 26 '21 at 05:06