[Tex/LaTex] how to make a line between two rows in table? (when no space between strings)

line-breakingline-spacingtables

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…

Best Answer

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