jim ying jim ying - 3 months ago 9
LaTeX Question

org mode how to convert code block into latex format?

org-mode block code, i want to convert to latex with beautiful format.
The fllow org-mode text, when convert to latex file, it's so ugly. how should i
do?

#+begin_src c
#inlcude <stdio.h>

int main(int argc, char **argv)
{
printf("hello\n");
}
#+end_src

Answer

For formatting the code, try

\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\usepackage[scaled=.85]{beramono}

\lstset{
  language=C,
  backgroundcolor=\color{black!5}, % set backgroundcolor
  basicstyle=\footnotesize\ttfamily,% basic font setting
  columns=fullflexible,
}

\begin{document}

\begin{lstlisting}
int main(int argc, char **argv)
\end{lstlisting}

\end{document}

which gives

enter image description here

Hope this helps!

Comments