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 have a script in R that build a report in LaTeX. Sometimes, this report has very long and very wide table, so, after some research I decided try ltxtable. My problem is that I didn't get how it works.

I have this LaTeX code for the report:

\documentclass{report}
\usepackage{ltxtable, tabularx, longtable}
\usepackage[latin1]{inputenc}
\usepackage[left=2cm,top=1cm,right=3cm,nohead,nofoot]{geometry}
\title{CP 68 - Estatístico}
\author{Rodrigo Coster - 1141783-01}
\begin{document}
\textbf{ \begin{center}{\LARGE Informações referentes ao CP 68 - Estatístico }\end{center} } 
\section*{Informações sobre processos} 
 Relação do quantitativo de candidatos convocados para cada processo selecionado  
\LTXtable{\textwidth}{'table.tex'}
\section*{Informações sobre fila de espera} 
 Este CP não possui mais candidatos habilitados.  
\end{document}

And, in the same folder, the file table.tex:

\begin{longtable}{|c|c|c|c|c{1cm}|}
\begin{center}
 \hline  
 \textbf{\textbf{Processo}} & \textbf{Vagas} & \textbf{Data} & \textbf{Convocados} & \textbf{Exercicio ok} \\ \hline  
 \textbf{001.010726.12.8} & 2 & 13/04/2012 & 2 & 2 \\ \hline  
\end{center}
\end{longtable}

After run, in console appears:

("C:\relatorios\Concursos\20130312 - CP 68 - Estatistico.aux")
*geometry* driver: auto-detecting
*geometry* detected driver: pdftex
Enter file name:

I tried a lot of file names. For most of them, he ask for the name again. If I type table.tex I get this error:

(C:\relatorios\Concursos\table.tex
! Missing # inserted in alignment preamble.
<to be read again> 
                   &
l.1 \begin{longtable}{|c|c|c|c|c{1cm}|}

? 

I already tried put \begin{center} in the first line, but didn't work.

EDIT:

Anothe table.tex:

\begin{longtable}{|c|c|c|c|c|c|}
 \hline  
 \textbf{\textbf{Área}} & \textbf{Convocados} & \textbf{Não ingressou} & \textbf{Para convocar} & \textbf{Manifestou interesse} & \textbf{Exercicio ok} \\ \hline  
 \textbf{Administração e economia               } &   8 &  6 & 0 &  0 &   2 \\ \hline  
 \textbf{Anos iniciais dos ciclos de formação   } & 474 & 80 & 0 & 13 & 381 \\ \hline  
 \textbf{Artes visuais                          } &  45 &  8 & 2 &  2 &  33 \\ \hline  
 \textbf{Biologia                               } &   1 &  0 & 0 &  0 &   1 \\ \hline  
 \textbf{Ciências da computação                 } &   2 &  1 & 0 &  0 &   1 \\ \hline  
 \textbf{Ciências físicas, químicas e biológicas} &  72 & 12 & 0 &  1 &  59 \\ \hline  
 \textbf{Ciências sócio-históricas              } &  48 & 11 & 0 &  2 &  35 \\ \hline  
 \textbf{Dança                                  } &  17 &  6 & 0 &  0 &  11 \\ \hline  
 \textbf{Deficiência mental                     } &  40 &  5 & 0 &  0 &  35 \\ \hline  
 \textbf{Deficiência visual                     } &   4 &  1 & 0 &  0 &   3 \\ \hline  
 \textbf{Educação de surdos                     } &   6 &  3 & 0 &  0 &   3 \\ \hline  
 \textbf{Educação física/rede escolar           } & 134 & 26 & 0 &  1 & 107 \\ \hline  
 \textbf{Educação infantil                      } & 123 & 17 & 1 &  2 & 103 \\ \hline  
 \textbf{Filosofia                              } &   7 &  0 & 0 &  0 &   7 \\ \hline  
 \textbf{Física                                 } &   1 &  0 & 0 &  0 &   1 \\ \hline  
 \textbf{Geografia                              } &  56 & 15 & 1 &  2 &  38 \\ \hline  
 \textbf{História                               } &  51 & 15 & 0 &  0 &  36 \\ \hline  
 \textbf{Língua espanhola                       } &  33 &  8 & 0 &  1 &  24 \\ \hline  
 \textbf{Língua francesa                        } &   3 &  1 & 0 &  0 &   2 \\ \hline  
 \textbf{Língua inglesa                         } &  38 &  9 & 1 &  0 &  28 \\ \hline  
 \textbf{Língua portuguesa                      } &  81 & 22 & 1 &  0 &  58 \\ \hline  
 \textbf{Matemática                             } & 104 & 26 & 1 &  1 &  76 \\ \hline  
 \textbf{Música                                 } &  51 & 17 & 0 &  1 &  33 \\ \hline  
 \textbf{Teatro                                 } &   5 &  0 & 0 &  0 &   5 \\ \hline  
\end{longtable}
share|improve this question
    
You can not put \begin{center} inside longtable )or any other latex tabular environment` Justdelete those lines. c{1cm} is also a syntax error latex c columns do not take a length parameter. –  David Carlisle Mar 12 '13 at 17:13
    
If this is primarily a table of numeric data you do not want ltxtable/tabularx as that allows entries in a column to wrap over several lines but you can not do line breaking in numbers. –  David Carlisle Mar 12 '13 at 17:15
    
@DavidCarlisle I removed the \begin{center}, \end{center} and {1cm}. Now it ask the file name several times (actualy, 4). After the 4th, the .pdf file is created (and with the table! \o/). You know why (and how to solve)? My problem with the width is in the title line (some tables has more than 5 columns) –  Rcoster Mar 12 '13 at 17:21
    
Probably the quotes are confusing things try changing {'table.tex'} to {table} But ltxtable will do nothing on this example other than be slower than a normal tabular. see this for ways of making tables narrower tex.stackexchange.com/questions/101748/… –  David Carlisle Mar 12 '13 at 17:28
    
It worked! I added another table.tex, with more columns. I read you post, but didn't get how to adapt it to ltxtable :/ –  Rcoster Mar 12 '13 at 17:46

2 Answers 2

up vote 7 down vote accepted

There is no need for that table to be wide, you just need to make sure the table width is not dominated by the headers. It is much better to do that by hand than rely on tabularx / ltxtable which knows nothing about the table structure.

here I rotated the headings but there are other possibilities:

enter image description here

\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage{longtable,graphicx,array}

\newcommand\rothead[1]{\rotatebox{90}{#1\ }}
\begin{document}

\begin{longtable}{|>{\bfseries\raggedright}p{5cm}|c|c|c|c|c|}
 \hline  
 \rothead{Área} & \rothead{Convocados} & \rothead{Não ingressou} &
 \rothead{Para convocar} & \rothead{Manifestou interesse} & \rothead{Exercicio ok} \\ \hline  
 Administração e economia              &   8 &  6 & 0 &  0 &   2 \\ \hline  
 Anos iniciais dos ciclos de formação  & 474 & 80 & 0 & 13 & 381 \\ \hline  
 Artes visuais                         &  45 &  8 & 2 &  2 &  33 \\ \hline  
 Biologia                              &   1 &  0 & 0 &  0 &   1 \\ \hline  
 Ciências da computação                &   2 &  1 & 0 &  0 &   1 \\ \hline  
 Ciências físicas, químicas e biológicas &  72 & 12 & 0 &  1 &  59 \\ \hline  
 Ciências sócio-históricas             &  48 & 11 & 0 &  2 &  35 \\ \hline  
 Dança                                 &  17 &  6 & 0 &  0 &  11 \\ \hline  
 Deficiência mental                    &  40 &  5 & 0 &  0 &  35 \\ \hline  
 Deficiência visual                    &   4 &  1 & 0 &  0 &   3 \\ \hline  
 Educação de surdos                    &   6 &  3 & 0 &  0 &   3 \\ \hline  
 Educação física/rede escolar          & 134 & 26 & 0 &  1 & 107 \\ \hline  
 Educação infantil                     & 123 & 17 & 1 &  2 & 103 \\ \hline  
 Filosofia                             &   7 &  0 & 0 &  0 &   7 \\ \hline  
 Física                                &   1 &  0 & 0 &  0 &   1 \\ \hline  
 Geografia                             &  56 & 15 & 1 &  2 &  38 \\ \hline  
 História                              &  51 & 15 & 0 &  0 &  36 \\ \hline  
 Língua espanhola                      &  33 &  8 & 0 &  1 &  24 \\ \hline  
 Língua francesa                       &   3 &  1 & 0 &  0 &   2 \\ \hline  
 Língua inglesa                        &  38 &  9 & 1 &  0 &  28 \\ \hline  
 Língua portuguesa                     &  81 & 22 & 1 &  0 &  58 \\ \hline  
 Matemática                            & 104 & 26 & 1 &  1 &  76 \\ \hline  
 Música                                &  51 & 17 & 0 &  1 &  33 \\ \hline  
 Teatro                                &   5 &  0 & 0 &  0 &   5 \\ \hline  
\end{longtable}

\end{document}
share|improve this answer

Just a simple typography tip, as I liked David's technical answer but not the looks (I don't like to turn my head to read headers). Although also not a very good solution you can use abbreviations, turn the table data around or use symbols (which you can explain in the caption or in the text).

enter image description here

share|improve this answer
    
Yes I'd have probably suggested abbreviating the headers but I wasn't sure what they all meant so rotating them was linguistically safer:-) (+1) –  David Carlisle Mar 12 '13 at 18:58
    
@DavidCarlisle Sure maybe Paul can translate them for us:) –  Yiannis Lazarides Mar 12 '13 at 19:01

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.