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}
  • Can you provide some code to see what you've write? – Romain Picot Aug 19 '15 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 – Romain Picot Aug 19 '15 at 11:46
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

  • 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 Aug 19 '15 at 12:00
  • Are you use those are ascii - and not some strange unicode dash? – daleif Aug 19 '15 at 12:16
  • And please make your MWE fully compilable. You are missing a document class. Can you compile my example? – daleif Aug 19 '15 at 12:16
  • 1
    Thanks it's now working, had to include \lstset{basicstyle=\ttfamily} before the R code – user85047 Aug 19 '15 at 12:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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