1

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.

alhelal
  • 2,451
  • 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. –  Nov 12 '17 at 18:06
  • @jfbu See this answer to the question which is linked now. – TeXnician Nov 13 '17 at 06:06
  • @TeXnician yes that's true. But 1) that answer over there is not an answer to the question over there, but to the one here, 2) it is not the same as the one you provided. As a result the mechanism of the site simply does not work. If someone comes with a better answer to the specific listinsg context, he has no place where to put it. If someone has the same question as here he has to identify which one of the 8 overthere applies. Does not look efficient. –  Nov 13 '17 at 07:16

1 Answers1

3

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}
TeXnician
  • 33,589