3

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...

  • 2
    You must use ` \\ ` before a \hline command can be written! (or better, use \tabularnewline, if available!) – user31729 Aug 7 '14 at 22:38
  • 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 ;-) tex.stackexchange.com/questions/194517/… – user31729 Aug 7 '14 at 22:56
  • 4
    The question could be solved by comments – user31729 Aug 7 '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 7 '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 7 '14 at 23:58
5

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.)

  • 1
    I already answered this in my comment above. Why don't I see up-votes? – AboAmmar Aug 8 '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 8 '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 8 '14 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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