How do I remove the additional space that is added when using \underbrace{...}
, to get the same width in both lines:
\documentclass{scrreprt}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{beramono}
\begin{document}
\texttt{https://example.org/foo/id/123456789/bar/baz}
$
\underbrace{\texttt{https://example.org/foo}}_{\text{Base-URL}}%
\texttt{/id/}%
\underbrace{\texttt{123456789\vphantom{g}}}_{\text{Foo-ID}}%
\texttt{/}%
\underbrace{\texttt{bar/baz\vphantom{g}}}_{\text{Function}}
$
\end{document}
Edit:
Using the approach of Werners answer, I defined a command, because I need this special underbrace without spacing a several times:
...
\newcommand{\underbracewithoutspace}[2]{\mathrlap{\underbrace{\phantom{#1\strut}}_{#2}}#1}
$
\underbracewithoutspace{\texttt{https://example.org/foo}}{\text{Base-URL}}%
\texttt{/id/}%
\underbracewithoutspace{\texttt{123456789}}{\text{Foo-ID}}%
\texttt{/}%
\underbracewithoutspace{\texttt{bar/baz}}{\text{Function}}
$