1

I'm using lstlisting to include my R code in my LaTeX, however, the minus sign after < is not appearing in the compiled file.

\usepackage{listings}
\begin{document}

\begin{lstlisting} [language=R]

n<- c(10, 15, 20, 35)
w <- c(300, 500, 700,100)
i <- c(1, 1, 2, 2)
 j <- c(1, 2, 1, 2)
 beta <- c(1, 1)
 for (iter in 1:20) {
 alpha <- sqrt(tapply(w*n^2/beta[j], i, sum)/
               tapply(w*beta[j], i, sum))
 beta <- sqrt(tapply(w*n^2/alpha[i], j, sum)/
              tapply(w*alpha[i], j, sum))}
 alpha
       1        2 
11.41714 24.63072 

 beta
        1         2 
0.8229245 1.3470172 
\end{lstlisting}
\end{document}
2
  • Can you provide some code to see what you've write? Commented Aug 19, 2015 at 11:41
  • 1
    You should edit your question instead of putting it in comment. Furthermore, add also the preamble and \begin{document} and \end{document} this could be usefull Commented Aug 19, 2015 at 11:46

1 Answer 1

1

As a longer comment, I have no problems here

\documentclass[a4paper]{memoir}
\usepackage{listings}
\lstset{basicstyle=\ttfamily}
\begin{document}


\begin{lstlisting}[language=R] 
n<- c(10, 15, 20, 35) 
w <- c(300, 500, 700,100) 
i <- c(1, 1, 2, 2) 
j <- c(1, 2, 1, 2) 
beta <- c(1, 1) 
for (iter in 1:20) { 
  alpha <- sqrt(tapply(wn^2/beta[j], i, sum)/ tapply(wbeta[j], i,sum))  
  beta <- sqrt(tapply(wn^2/alpha[i], j, sum)/ tapply(walpha[i],j,sum)) 
}
 alpha 1 2 11.41714 24.63072 beta 1 2 0.8229245 1.3470172 
\end{lstlisting}

\end{document}

enter image description here

4
  • still the same problem, I'm using a mac!! I even tried to transfer my code to Sharelatex but it's still not working
    – user85047
    Commented Aug 19, 2015 at 12:00
  • Are you use those are ascii - and not some strange unicode dash?
    – daleif
    Commented Aug 19, 2015 at 12:16
  • And please make your MWE fully compilable. You are missing a document class. Can you compile my example?
    – daleif
    Commented Aug 19, 2015 at 12:16
  • 1
    Thanks it's now working, had to include \lstset{basicstyle=\ttfamily} before the R code
    – user85047
    Commented Aug 19, 2015 at 12:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .