# Problem with Listings package concerning line breaking and wrong alignment [duplicate]

Hello I have the following code:

\documentclass[12pt]{article}
\usepackage[top=0.3in, bottom=1.5in, left=0.8in, right=0.8in]{geometry}

\usepackage[utf8]{inputenc}

\usepackage{setspace}
\setlength{\parindent}{0cm}

\usepackage{amsmath}
\usepackage{unicode-math}

\usepackage{listings}

\begin{document}

#include  <msp430g2553.h>

unsigned int i = 0;

void main(void)
{
WDTCTL = WDTPW + WDTHOLD;

P1DIR |= 0x01;
P1DIR |= 0x40;

for(;;)

{

P1OUT ^= 0x01;
P1OUT ^= 0x40;

//Or alternative P1OUT ^= 0x01|0x40

for(i=0;i<30000;i++);

//If I place P1OUT ^= 0x40; here then one LED blink and then the other
};

}

\end{lstlisting}

\end{document}


In the last comment why doesn't the new line starts from the beggining (meaning under the //) but instead starts with a little left margin? And also why the first comment is far more left than the rest of the code in its block?

I have uploaded an image also with tabs on. There is something wrong. When I experiment with tabs odd things happen and the document doesn't appear as it should be. The second image is based on the code I wrote in that post and I haven't experiment on that one.

## marked as duplicate by jub0bs, Jesse, Thorsten, Guido, Peter JanssonMar 20 '14 at 12:14

• You must have a tab, versus actual spaces which are being treated differently. You can try adjusting tabsize=<number>. Cutting and pasting your MWE works fine for me so the tabbing must be getting lost in the pasting here. – Peter Grill Mar 19 '14 at 19:09
• For debugging this you could add showtabs=true to your listing – Andrew Swann Mar 19 '14 at 21:02