This question already has an answer here:

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 - enter image description here

In this output the ~ is positioned little up.

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    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. – jfbu 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).

tilde

\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}

Not the answer you're looking for? Browse other questions tagged or ask your own question.