Tilde below letter + subscript creates unwanted spacing

You maybe want to use accents:

\documentclass{article}
\usepackage{amsmath}
\usepackage{accents}

\newcommand{\ut}[1]{\underaccent{\tilde}{#1}}
\renewcommand{\vec}[1]{\ut{#1}}

\begin{document}

$\vec v = \vec{e}_x + 2 \vec{e}_y + 3\vec{e}_z $

\end{document}

enter image description here


A stackengine solution. The underset gap can be adjusted with the 1st argument to \stackengine.

\documentclass[10pt,a4paper]{article}
\usepackage{amsmath,stackengine}
\renewcommand{\vec}[1]{%
  \smash{\ensurestackMath{\stackengine{1pt}{#1}{\scriptscriptstyle\sim}{U}{c}{F}{F}{S}}}
  \vphantom{#1}
}
\begin{document}
$\vec v = \vec{e}_x + 2 \vec{e}_y + 3\vec{e}_z $
\end{document}

enter image description here


Try the same using undertilde package.

The code is as follows. It works for me perfectly.

\documentclass[10pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{undertilde}
\begin{document}
$\utilde{v} = \utilde{e}_{x} + 2 \utilde{e}_{y} + 3\utilde{e}_{z}$ 
\end{document}

enter image description here