4

I use longtabu package to build table, when I use \\ to separate every line, it is ok, see below

\begin{center}

\begin{longtabu} to \textwidth {|X[1 , p ] |X[1 , p ] | X[2 , p ]| X[2 , p ]|X[1 , p ]|X[1 , p ]|}

\caption{A simple longtabu example}\\

\hline

\textbf{A} & \textbf{B} & \textbf{C} & \textbf{D} & \textbf{E} & \textbf{F}  \\

\hline

\endfirsthead

\multicolumn{6}{c}%

{\tablename\ \thetable\ -- \textit{Continued from previous page}} \\

\hline

\textbf{A} & \textbf{B} & \textbf{C} & \textbf{D} & \textbf{E} & \textbf{F}  \\

\hline

\endhead

\hline \multicolumn{6}{r}{\textit{Continued on next page}} \\

\endfoot

\hline

\endlastfoot



ab&cd&ef&gh&ij&kq\\ab&cd&ef&gh&ij&kq\\ab&cd&ef&gh&ij&kq\\\end{longtabu}\end{center}\end{document}

enter image description here

But if i use \hline or \hline\, like below, the complie always show error

ab&cd&ef&gh&ij&kq\hline\ab&cd&ef&gh&ij&kq\hline\ab&cd&ef&gh&ij&kq\hline\\end{longtabu}\end{center}\end{document}   

OR

ab&cd&ef&gh&ij&kq\hlineab&cd&ef&gh&ij&kq\hlineab&cd&ef&gh&ij&kq\hline\end{longtabu}\end{center}\end{document}    

OR \\\hline

ab&cd&ef&gh&ij&kq\\\hlineab&cd&ef&gh&ij&kq\\\hlineab&cd&ef&gh&ij&kq\\\hline\end{longtabu}\end{center}\end{document}    

looks like this

enter image description here

The reason I write them together without any space is, I have a program to create table, the program use strings to create table.

I want to have a line between each row in the table, how to do it? either \hline or \hline\ doesnot work, for example \hline maybe read as \hlineab...

postit
  • 415
  • 3
    You must use \\ before a \hline command can be written! (or better, use \tabularnewline, if available!) –  Aug 07 '14 at 22:38
  • We can't not help about the program of course –  Aug 07 '14 at 22:46
  • \\hline does not work too, the program has no problem, i just can not write a correct latex format to correctly create the table – postit Aug 07 '14 at 22:48
  • Try \\ \hline –  Aug 07 '14 at 22:51
  • 1
    Off-topic comment: There is a question by you, having two answers, which both seem to fit your request - consider accepting one of them, before piling up other questions ;-) http://tex.stackexchange.com/questions/194517/how-to-add-a-logo-in-every-page-without-any-margin –  Aug 07 '14 at 22:56
  • In the first example you have a \ab and in the second and third you have \hlineab. Change these to ab and \hline ab, respectively, and it should work. –  Aug 07 '14 at 23:00
  • Thank you! I just fixed the problem, the answer is, first break the line: "\", second draw a line: "\hline", third add a space:" " – postit Aug 07 '14 at 23:02
  • 4
    The question could be solved by comments –  Aug 07 '14 at 23:13
  • 1
    It is not off-topic someone needs to write an answer. Please don't close all questions, this place started to look like SO – percusse Aug 07 '14 at 23:42
  • 2
    Simply you could play around this by inserting two braces after \hline as follows:
    `\documentclass[12pt,a4paper]{article}
    \usepackage{array}
    \usepackage{tabu}
    \usepackage{longtable}
    \begin{document}
    
    \begin{longtabu}{cccccc}\hline{}ab&cd&ef&gh&ij&kq\\\hline{}ab&cd&ef&gh&ij&kq\\\hline{}ab&cd&ef&gh&ij&kq\\\hline{}\end{longtabu}\end{document}`
    
    – AboAmmar Aug 07 '14 at 23:58

1 Answers1

6

When building tables, the \hline command at the very beginning of a row: this means just after the \begin{tabular}{<column-spec>} line to come before the first row or immediately after \\ for the other rows.

(La)TeX commands are made up of the escape character (\), a series of letters up to the first non-letter or the escape character (\) followed by one non-letter. Following these rules, \hlineab is a separate command name from \hline: both are made up of the escape sequence followed by letters. Thus your system for building your table needs to include something after \hline to separate it from ab. The usual case would simply to be to include a space here

\\ \hline ab

If for some reason that is not possible, adding an empty group will also do the job

\\ \hline{}ab

(This latter trick is also used to stop TeX skipping spaces after a command: not relevant here but does show up for example when writing for example \LaTeX{} is a document preparation system: try without the braces and see the effect.)

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
  • 1
    I already answered this in my comment above. Why don't I see up-votes? – AboAmmar Aug 08 '14 at 12:37
  • @AboAmmar I don't follow. I'm happy to remove my answer if you want to post one instead, but comments don't have the same 'status' as answers for the StackExchange back-end. So while a comment can get votes, you don't get any 'reputation' for it and it doesn't mark the question as having an answer. – Joseph Wright Aug 08 '14 at 12:41
  • 2
    No, you shouldn't remove it since more readers can see the answer rather than comments. We aim at the benefit of the site users. – AboAmmar Aug 08 '14 at 12:59