I am using this LaTeX code to implement some Python code in my LaTeX generated pdf document. I am using \lstdefinestyle because I have multiple styles for different code that I want to implement in the same file.

\lstdefinestyle{numbers} {numbers=left, stepnumber=1, numberstyle=\tiny, numbersep=8pt}


I am implementing in this way:

   print 'here the code'

The problem is that the code is going to give me an Overfull \hbox error when I compile the LateX code.

I wrote the code keeping an eye on the "gray line" on the right in my Python editor (Spyder):

Code Example

Unfortunately many code lines that don't go above the grey line that you can see in the picture (which I tought was a mark to show where to stop writing) will not fit in LaTeX.

Is there anything that I can do to resize the code so that I don't get this result:

LaTex Example

I would like the text to stay all inside the red line when it stays inside the gray line in Spyder. If I am asking too much I would like a solution to scale down the code so that it can enter in the box. Maybe there is something in lstlisting that I can use to resize the code?

Re-writing the programs is not a solution :D.

closed as unclear what you're asking by jub0bs, user13907, Guido, Masroor, Werner Sep 10 '14 at 15:52

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – jub0bs May 4 '14 at 12:33
  • I don't know of any automated solution for your problem. What I would do is choose a font for my listings and stick with it, then adjust (by trial and error) the font size and width of the listings so that no line shorter than my editor's number of columns (79 in my case) wraps. – jub0bs May 4 '14 at 12:41
  • 1
    Rather than an image of the code, you should add a small part of it so we can experiment with it (and not retype it). – egreg May 4 '14 at 12:49
  • Thanks for the answer. I will fix the question. The solution that I found now is to use: basicstyle=\ttfamily\scriptsize. – VitOne May 4 '14 at 22:16

Browse other questions tagged or ask your own question.