Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I just started using LaTeX last night, and I was trying to copy a general format I found on wikibooks. I wrote a python script to get 30 different stocks and their quotes, and I made it generate this .tex file.

\documentclass{article}
\usepackage[english]{babel}
\begin{document}
\title{PF30 Index}
     \begin{tabular}{ l | l | l | l | l | l }
     Name & SYM & MKT & Close & Open & Change \\
     \hline
     Advanced Micro De & AMD & NYSE & 2.6014 & 2.62 & -1.46% \\
     Apple Inc & AAPL & NasdaqNM & 487.59 & 498.04 & -2.82% \\
     AT and T Inc & T & NYSE & 33.70 & 33.98 & -0.94% \\
     Bank of America C & BAC & NYSE & 11.465 & 11.3799 & -0.04% \\
     Cemex, SAB de  & CX & NYSE & 10.235 & 10.36 & -1.49% \\
     Citigroup, Inc C & C & NYSE & 42.381 & 41.80 & +0.38% \\
     Coca-Cola Company & KO & NYSE & 37.18 & 36.99 & +0.51% \\
     Dell Inc & DELL & NasdaqNM & 12.95 & 12.72 & +5.37% \\
     Facebook, Inc & FB & NasdaqNM & 30.52 & 31.71 & -1.38% \\
     Ford Motor Compan & F & NYSE & 14.225 & 13.91 & +1.68% \\
     General Electric  & GE & NYSE & 21.17 & 21.04 & +0.24% \\
     General Motors Co & GM & NYSE & 30.59 & 30.1497 & +0.86% \\
     Google Inc & GOOG & NasdaqNM & 723.38 & 719.33 & +0.02% \\
     Groupon, Inc & GRPN & NasdaqNM & 5.225 & 5.27 & -0.85% \\
     Hewlett-Packard C & HPQ & NYSE & 16.5399 & 16.82 & -2.42% \\
     Home Depot, Inc  & HD & NYSE & 63.72 & 63.50 & +0.38% \\
     International Bus & IBM & NYSE & 191.54 & 191.31 & -0.56% \\
     Intel Corporation & INTC & NasdaqNM & 21.8799 & 21.95 & -0.54% \\
     Lowe's Companies, & LOW & NYSE & 35.855 & 35.45 & +1.34% \\
     Mastercard Incorp & MA & NYSE & 521.07 & 521.69 & -0.47% \\
     McDonald's Corpor & MCD & NYSE & 91.20 & 91.05 & -0.36% \\
     Microsoft Corpora & MSFT & NasdaqNM & 27.055 & 26.84 & +0.61% \\
     Netflix, Inc & NFLX & NasdaqNM & 101.79 & 103.25 & -1.60% \\
     Pepsico, Inc Com & PEP & NYSE & 71.47 & 71.10 & +0.25% \\
     Procter  and  Gamble  & PG & NYSE & 69.74 & 69.24 & +0.16% \\
     Visa Inc & V & NYSE & 159.67 & 159.66 & -0.61% \\
     Walt Disney Compa & DIS & NYSE & 50.88 & 50.50 & +0.57% \\
     Wells Fargo  and  Com & WFC & NYSE & 34.985 & 34.64 & +0.62% \\
     Yahoo! Inc & YHOO & NasdaqNM & 19.4456 & 19.30 & +0.08% \\
     Yum! Brands, Inc & YUM & NYSE & 66.27 & 66.02 & +0.18% \\
     \end{tabular}
\end{center}

The error TeXworks is giving me is ! Extra alignment tab has been changed to \cr. when it gets to the line for Apple Inc. What can I do to fix this? It doesn't look as if I'm adding more than six columns, but from what I've read on the internet, that's what the error is for this line.

share|improve this question
    
each distinct line of tabular should end with \\ so you're never ending any of these lines. (and welcome to TeX.sx!) –  barbara beeton Jan 15 '13 at 20:03
    
To highlight code, you can select it and click the "code" button (with "{}" on it). This indents blocks by 4 spaces or encloses words in backticks `. –  Torbjørn T. Jan 15 '13 at 20:13
5  
The percentage sign is a comment character, so everything after the % on each line is ignored. To typeset a percentage sign type \%. See e.g. en.wikibooks.org/wiki/LaTeX/Basics#Comments en.wikibooks.org/wiki/LaTeX/Basics#Reserved_Characters –  Torbjørn T. Jan 15 '13 at 20:16
    
Thanks! It's now working, I'm going to have to use this more often. –  Tarkin Jan 15 '13 at 20:29
add comment

1 Answer

The percentage sign in (La)TeX indicates a comment, that is, everything after a % in the code is ignored by the compiler. Because of that, the \\ in the second line of your table is never seen, and the next line is read, leading to the error. To typeset a percentage sign in the text you must escape it, by writing \%.

This can be quite useful, as you can add comments to the code, explaining what you've done, and why, so if you read the code some time later, it will be easier to understand. In some cases a percent sign is required to avoid unwanted whitespace, see What is the use of percent signs (%) at the end of lines?

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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