# Why ~ is not shown in place in R source listings? [duplicate]

My sample code is-

\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\begin{document}
\lstinputlisting[numbers=left,backgroundcolor=\color{lightgray},language=R]{code.R}
\end{document}


and code.R is -

m.datF <- read.csv("modified_dataF.csv", header=T)[,-1]
mod <- glm(salary ~ ., family=gaussian,  data=m.datF)
summary(mod)


output shows -

In this output the ~ is positioned little up.

## marked as duplicate by TeXnician, Troy, Werner, Stefan Pinnow, AndrewNov 12 '17 at 20:02

• That is font dependent... – TeXnician Nov 12 '17 at 17:07
• @TeXnician then what can I do? – alhelal Nov 12 '17 at 17:11
• Change the font. Personally I do not know which font fixes this, but I'll post a fix. – TeXnician Nov 12 '17 at 17:37
• I don't know why people are asking to close currently as no duplicate invoking the listings context has been put forward so far. – user4686 Nov 12 '17 at 18:06
• @jfbu See this answer to the question which is linked now. – TeXnician Nov 13 '17 at 6:06

You can use the literate feature to fix the tilde positioning (or compile your current code with lualatex that apparently fixes it too).

\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{lmodern}
\begin{document}
\lstset{basicstyle=\ttfamily,literate={~}{{\raisebox{-3pt}{\textasciitilde}}}1}
\begin{lstlisting}
~test
\end{lstlisting}
\end{document}