1

I am having a bit of trouble putting python code into a latex document using listings. The code is appearing with a large indent on the left so that it has to go onto multiple lines.

Here is an image: enter image description here

This is the code I am using to set up listings:

\usepackage{listings}
\usepackage{color}
\usepackage[dvipsnames]{xcolor}

\lstdefinestyle{customc}{
  belowcaptionskip=1\baselineskip,
  breaklines=true,
  frame=L,
  xleftmargin=\parindent,
  language=Python,
  showstringspaces=false,
  basicstyle=\footnotesize\ttfamily,
  keywordstyle=\bfseries\color{green!40!black},
  commentstyle=\itshape\color{purple!40!black},
  identifierstyle=\color{blue},
  stringstyle=\color{red},
  columns=flexible 
}

\lstset{escapechar=@,style=customc}

And here is how I create a listing:

\lstinputlisting[caption= Construction of output for \texttt{write\_dataLine}, style=customc, label= inputtottxt, firstline=27, lastline=27]{datafile.py}

Thank you in advance.

closed as unclear what you're asking by siracusa, Phelype Oleinik, Kurt, Zarko, Troy Oct 23 '18 at 0:12

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! Could you also add the contents of datafile.py? – egreg Mar 14 '16 at 21:46
  • Those listings settings don't cuase the code to be indented as much as in your screenshot. Could it be that line 27 of datafile.py is already indented a lot? – Arun Debray Mar 14 '16 at 23:17
  • I unintended all of the code to try and fix the issue. Still did the same thing. – Sam_PUG Mar 15 '16 at 9:38

Browse other questions tagged or ask your own question.