# LyX table row error

I hope someone can help with this problem. I have a 3x4 table which is too wide for a page if just entered as is. Therefore, I have fixed each column width at 25% of the text width and then used ERT \linebreak inside the table.

However, when trying to compile I get this error 4 times:

Extra alignment tab has been changed to \cr.

The LaTeX code for the LyX table is:

\begin{table}
\caption{CD271 Antibody Assessment}

\centering{}%
\begin{tabular}{|>{\centering}p{0.25\textwidth}|p{0.25\textwidth}|p{0.25\textwidth}|}
\hline
Sample & \multicolumn{2}{p{0.25\textwidth}|}{Percentage Identified\linebreak as MSCs by Panel} & \multicolumn{2}{p{0.25\textwidth}|}{Percentage CD271\linebreak Postive}\tabularnewline
\hline
\hline
BMMC & 0&02 & 1&78\tabularnewline
\hline
\hline
Cultured Bone Marrow & 39&08 & 5&70\tabularnewline
\hline
\hline
Commerical MSCs & 99&51 & 45&44\tabularnewline
\hline
\end{tabular}
\end{table}


Any idea what I am doing wrong? I have tried looking at the online helps but can't find an answer.

• Welcome to TeX.SX. Please complete your code in order to provide a compilable example. The documentclass, the table-packages and \begin{document} \end{document} should be enough. You are talking about "3x4" but you have 5 columns. I have not tested your code yet, but that looks a bit strange. 25 % per column would be a bit too much than... – LaRiFaRi May 27 '14 at 14:54
• Why are you using ERT? In LyX After you set fixed width for the columns, you can use return and ctrl + return. – scottkosty May 27 '14 at 15:33

You have a tabular environment with only 3 columns

\begin{tabular}{{...}p{...}p{...}p{...}}


So you can't put in the second row three cells taking 5 columns:

1. Sample & --> 1
2. \multicolumn{2}{...}{...} & --> 1 + 2 = 3
3. \multicolumn{2}{...}{...}\tabularnewline --> 3+2 =5

Nor five cells in the following rows:

1. BMMC &
2. 0 &
3. 02 &
4. 1 &
5. 78 \tabularnewline

The solution is a tabular environment with five columns. Some like:

\begin{tabular}{p{...}p{...}p{...}p{...}p{...}}


BTW, please avoid the vertical lines as well as the double lines. I suggest the use of tho horizontal rules of the booktabs package instead of \hline and some other changes. Please check the difference in this minimal working example:

\documentclass{article}
\usepackage{array,booktabs}

\begin{document}

\begin{table}
\caption{CD271 Antibody Assessment}
\centering{}%
\begin{tabular}{|>{\centering}p{0.12\textwidth}|p{0.12\textwidth}|p{0.12\textwidth}|p{0.12\textwidth}|p{0.12\textwidth}|}
\hline
Sample & \multicolumn{2}{p{0.24\textwidth}|}{Percentage Identified\linebreak as MSCs by Panel} & \multicolumn{2}{p{0.24\textwidth}|}{Percentage CD271\linebreak Postive}\tabularnewline
\hline
\hline
BMMC & 0&02 & 1&78\tabularnewline
\hline
\hline
Cultured Bone Marrow & 39&08 & 5&70\tabularnewline
\hline
\hline
Commerical MSCs & 99&51 & 45&44\tabularnewline
\hline
\end{tabular}
\end{table}

\begin{table}
\caption{CD271 Antibody Assessment}
\centering{}%
\begin{tabular}{lcccccc}
\toprule
Sample & & \multicolumn{2}{>{\raggedright}m{0.25\textwidth}}{Percentage Identified as MSCs by Panel} & & \multicolumn{2}{>{\raggedright}m{0.25\textwidth}}{Percentage CD271 Postive}\tabularnewline
\cmidrule{1-1}\cmidrule{3-4}\cmidrule{6-7}
BMMC & & 0 & 02 & & 1 & 78\tabularnewline
Cultured Bone Marrow & &  39 & 08 & & 5 & 70\tabularnewline
Commerical MSCs & & 99 & 51 & & 45 & 44\tabularnewline
\bottomrule
\end{tabular}

\end{table}

\end{document}

• Thanks - the table only has 3 columns. Lyx seemed to convert 0.02 to 0&02 in latex code making it look like a five column table. – user3677842 May 28 '14 at 10:51
• @user3677842 This is not the normal behaviour of LyX. This type of problems explain why you should provide always a minimal working example (file) and not a only a chunk of not compilable code. In this case, preferably post the original .lyx istead of the .tex version. – Fran May 28 '14 at 19:35

As others already noticed: In the LaTeX code generated by LyX the table definition \begin{tabular} creates 3 columns by p{...}, but each row contains 5 columns/cells, e.g. the alignment tab & occurs 4 times in the third row. Hence, LaTeX complains about the extra alignment tabs.

You asked what you are doing wrong... Well, regarding LyX, actually nothing. You simply hit a bug! Regarding the example - well - minimizing the example (in LyX) as much as possible such that the problem still persists is always helpful. In this case, it would mean to delete rows or columns one by one until the problem disappears and then undo the last action (such that the problem appears again). Doing so will lead to a minimalistic table.

Now I create the problem from scratch:

1. In a LyX document, insert a table with 1 row and 1 column, i.e. just one cell.
2. Click inside the cell and set the following table settings (e.g. via Edit > Table settings...): Set horizontal alignment to "At Decimal Separator" and set width to "50" "Text Width%".

3. Back at the table, type the number "1.2" inside the cell.

Looking at the LaTeX source preview in LyX, one might recognize the problem:

\begin{tabular}{|p{0.5\textwidth}|}
\hline
1&2\tabularnewline
\hline
\end{tabular}


The problem is the combination of decimal alignment and fixed width for a column in LyX.

(Note that later while editing the table and changing the "Width" setting, the horizontal alignment will be reset to "Center" - hence, no decimal alignment and thus no error occurs. Setting the alignment back to decimal will show the problem again.)

Now repeating step 1. - 3. but not setting "Width", i.e. leaving this field blank, creates the following table:

\begin{tabular}{|r@{\extracolsep{0pt}.}l|}
\hline
1&2\tabularnewline
\hline
\end{tabular}


It shows how LyX deals with decimal alignment, i.e. it creates two column and splits the number at the decimal separator.

Workaround 1

Given a table that should have a column with decimal alignment and a long heading.

1. Do not set the width of the column, i.e. just leave the field "Width" blank, but set the horizontal alignment to "At Decimal Separator".

2. Go to / click inside the cell with the heading that takes too much (horizontal) space.

a) Select via the menu Edit > Table > Multicolumn. (Actually, the same setting could be made in the table setting dialog, but it is greyed out there.)

b) Now open the table settings dialog and set the "Width" to whatever is suitable for you, e.g. "25" "Text Width%". By using his way, manual line breaks seem unnecessary!

Here is a picture of such a table and the resulting LaTeX code:

\begin{tabular}{|r@{\extracolsep{0pt}.}l|}
\hline
\multicolumn{2}{|>{\raggedright}p{0.5\textwidth}|}{a column that has decimal alignment and a long heading}\tabularnewline
\hline
\hline
1111&2\tabularnewline
\hline
3&4444\tabularnewline
\hline
\end{tabular}


Note when changing the decimal separator you have to undo the above multicolumn setting and redo it after the change. Furthermore, it seems that the decimal separator is really restricted to ., ,, ;, :. Trying to use some more exotic separator like "/" will fail in LyX without an error message.

Workaround 2 would be using the package dcolumn. Then the field "LaTeX argument" of column can be set to D{.}{.}{4..2}, see the LyX wiki here for more details.

• This answer shows three bugs in LyX 2.1: combination of decimal alignment and setting column width; later the multicolumn setting; and the changing of the decimal separator to some exotic character. – e-birk May 29 '14 at 15:24