MWE:
\documentclass{article}
\usepackage{array,etoolbox,lipsum}
\makeatletter
\preto{\@verbatim}{\topsep=0pt \partopsep=0pt}
\makeatother
\begin{document}
\begin{table}[ht]
\begin{tabular}{>{\ttfamily}p{3cm}|p{3cm}}
\vspace{-6pt} % NOTE!
\begin{verbatim}
lines within verbatim
environment. Let's add
some more lines
\end{verbatim}
\vspace{-\baselineskip} % NOTE!
ordinary lines out of
verbatim environment
&
\lipsum[1][1-2]\\
\end{tabular}\\
\end{table}
\noindent Before verbatim
\begin{verbatim}
\documentclass{article}
\begin{document}
\end{document}
\end{verbatim}
After verbatim
\end{document}
Output:
I looked for a solution that removes spaces before and after verbatim. Yes I found it (see line \preto) but, as you can see from the example above, it will not work in tabular's cell if I remove \vspaces. I empirically "hacked" the right values but I would like to understand what do I wrong. I want to use \verbatim just as is and see no odd leading spaces before or after in case of table cells.

array,etoolboxandlipsumpackages are missing. – leandriis Apr 01 '20 at 10:23Vtype column defined by egreg in an answer to a previous question should also work in your case. – leandriis Apr 01 '20 at 10:26verb|something|doesn't allow line breaks. – Timur Fayzrakhmanov Apr 01 '20 at 13:58