# generate latex table online and then use them in latex in TeXstudio

I made the table in latex for my project in latex from the following website :

https://www.tablesgenerator.com/latex_tables#

The code generated is :

% Please add the following required packages to your document preamble:
% \usepackage{graphicx}
% \usepackage[table,xcdraw]{xcolor}
% If you use beamer only pass "xcolor=table" option, i.e. \documentclass[xcolor=table]{beamer}
\begin{table}[]
\centering
\resizebox{\textwidth}{!}{%
\begin{tabular}{ccccccccc}
\rowcolor[HTML]{C0504D}
& \multicolumn{8}{c}{\cellcolor[HTML]{C0504D}MAE} \\
\rowcolor[HTML]{DFA7A6}
\cellcolor[HTML]{C0504D}A & \begin{tabular}[c]{@{}c@{}}A\\ s\n\end{tabular} & \begin{tabular}[c]{@{}c@{}}V\end{tabular} & \begin{tabular}[c]{@{}c@{}}N\end{tabular} & \begin{tabular}[c]{@{}c@{}}P\end{tabular} & \begin{tabular}[c]{@{}c@{}}H\end{tabular} & \begin{tabular}[c]{@{}c@{}}A\end{tabular} & \begin{tabular}[c]{@{}c@{}}No\end{tabular} & \begin{tabular}[c]{@{}c@{}}J\end{tabular} \\
\rowcolor[HTML]{EFD3D2}
\cellcolor[HTML]{C0504D}Lt & 2& 1& 1& 1&  & 2& 1&  \\
\rowcolor[HTML]{DFA7A6}
\cellcolor[HTML]{C0504D}Xt & 2& 1&  & 1& 1&  & 2&  \\
\rowcolor[HTML]{EFD3D2}
\cellcolor[HTML]{C0504D}\begin{tabular}[c]{@{}c@{}}R\\ \\ r\end{tabular} & 2&  &  &  &  & 2&  &  \\
\rowcolor[HTML]{DFA7A6}
\cellcolor[HTML]{C0504D}\begin{tabular}[c]{@{}c@{}}A\\ \end{tabular} & 2&  &  &  & 2& 2&  &  \\
\rowcolor[HTML]{EFD3D2}
\cellcolor[HTML]{C0504D}N & 2&  & 1&  &  &  &  &  \\
\rowcolor[HTML]{DFA7A6}
\cellcolor[HTML]{C0504D}C & 2&  & 1 &  &  &  &  & 1\\
\rowcolor[HTML]{EFD3D2}
\cellcolor[HTML]{C0504D}\begin{tabular}[c]{@{}c@{}}K\\ e\end{tabular} & 2&  &  &  &  &  &  &  \\
\rowcolor[HTML]{DFA7A6}
\cellcolor[HTML]{C0504D}\begin{tabular}[c]{@{}c@{}}K \end{tabular} & 2 &  &  &  &  &  &  &  \\
\rowcolor[HTML]{EFD3D2}
\cellcolor[HTML]{C0504D}L & 3&  &  &  & 2&  &  &  \\
\rowcolor[HTML]{DFA7A6}
\cellcolor[HTML]{C0504D}\begin{tabular}[c]{@{}c@{}}E \end{tabular} & 2&  &  &  &  &  &  &  \\
\rowcolor[HTML]{EFD3D2}
\cellcolor[HTML]{C0504D}s &  &  & 1&  &  & 2&  &  \\
\rowcolor[HTML]{DFA7A6}
\cellcolor[HTML]{C0504D}\begin{tabular}[c]{@{}c@{}}L \end{tabular} &  &  &  &  & 1&  &  &  \\
\rowcolor[HTML]{EFD3D2}
\cellcolor[HTML]{C0504D}E&  &  &  &  & 2&  &  &  \\
\rowcolor[HTML]{DFA7A6}
\cellcolor[HTML]{C0504D}R &  &  &  &  & 2&  &  &
\end{tabular}%
}
\end{table}


Then I copied this code pasted in TeXstudio.Ran that code. The code gave me the error:

\begin{table} on input line 35 ended by \end{document}. \end{document}
You can't use \end' in internal vertical mode. \end{document}
\begin{table} on input line 35 ended by \end{document}. \end{document}
Missing } inserted. \end{document}


After i found another link for generating table .

https://www.latex-tables.com/#

There I go from File>Import Table>Latex. I pasted the above the code therein Latex. From there I got the new code

\documentclass{article}
\usepackage{colortbl}

\begin{document}

\begin{table}
\centering
\begin{tabular}{ccccccccc}
\rowcolor[rgb]{0.753,0.314,0.302}                                                                                                                             & \multicolumn{8}{c}{MAE}                                                                                           \\
\rowcolor[rgb]{0.875,0.655,0.651} {\cellcolor[rgb]{0.753,0.314,0.302}}A                                                                                       & \begin{tabular}[c]{@{}>{\cellcolor[rgb]{0.875,0.655,0.651}}c@{}}A\\ s \end{tabular} & V & N & P & H & A & No & J  \\
\rowcolor[rgb]{0.937,0.827,0.824} {\cellcolor[rgb]{0.753,0.314,0.302}}Lt                                                                                      & 2                                                                                   & 1 & 1 & 1 &   & 2 & 1  &    \\
\rowcolor[rgb]{0.875,0.655,0.651} {\cellcolor[rgb]{0.753,0.314,0.302}}Xt                                                                                      & 2                                                                                   & 1 &   & 1 & 1 &   & 2  &    \\
\rowcolor[rgb]{0.937,0.827,0.824} {\cellcolor[rgb]{0.753,0.314,0.302}}\begin{tabular}[c]{@{}>{\cellcolor[rgb]{0.753,0.314,0.302}}c@{}} R\\ \\ r \end{tabular} & 2                                                                                   &   &   &   &   & 2 &    &    \\
\rowcolor[rgb]{0.875,0.655,0.651} {\cellcolor[rgb]{0.753,0.314,0.302}}\begin{tabular}[c]{@{}>{\cellcolor[rgb]{0.753,0.314,0.302}}c@{}} A\\ \end{tabular}      & 2                                                                                   &   &   &   & 2 & 2 &    &    \\
\rowcolor[rgb]{0.937,0.827,0.824} {\cellcolor[rgb]{0.753,0.314,0.302}}N                                                                                       & 2                                                                                   &   & 1 &   &   &   &    &    \\
\rowcolor[rgb]{0.875,0.655,0.651} {\cellcolor[rgb]{0.753,0.314,0.302}}C                                                                                       & 2                                                                                   &   & 1 &   &   &   &    & 1  \\
\rowcolor[rgb]{0.937,0.827,0.824} {\cellcolor[rgb]{0.753,0.314,0.302}}\begin{tabular}[c]{@{}>{\cellcolor[rgb]{0.753,0.314,0.302}}c@{}} K\\ e \end{tabular}    & 2                                                                                   &   &   &   &   &   &    &    \\
\rowcolor[rgb]{0.875,0.655,0.651} {\cellcolor[rgb]{0.753,0.314,0.302}}K                                                                                       & 2                                                                                   &   &   &   &   &   &    &    \\
\rowcolor[rgb]{0.937,0.827,0.824} {\cellcolor[rgb]{0.753,0.314,0.302}}L                                                                                       & 3                                                                                   &   &   &   & 2 &   &    &    \\
\rowcolor[rgb]{0.875,0.655,0.651} {\cellcolor[rgb]{0.753,0.314,0.302}}E                                                                                       & 2                                                                                   &   &   &   &   &   &    &    \\
\rowcolor[rgb]{0.937,0.827,0.824} {\cellcolor[rgb]{0.753,0.314,0.302}}s                                                                                       &                                                                                     &   & 1 &   &   & 2 &    &    \\
\rowcolor[rgb]{0.875,0.655,0.651} {\cellcolor[rgb]{0.753,0.314,0.302}}L                                                                                       &                                                                                     &   &   &   & 1 &   &    &    \\
\rowcolor[rgb]{0.937,0.827,0.824} {\cellcolor[rgb]{0.753,0.314,0.302}}E                                                                                       &                                                                                     &   &   &   & 2 &   &    &    \\
\rowcolor[rgb]{0.875,0.655,0.651} {\cellcolor[rgb]{0.753,0.314,0.302}}R                                                                                       &                                                                                     &   &   &   & 2 &   &    &
\end{tabular}
\end{table}
\end{document}


I tried the above new code in my project in TeXstudio. I got new types of error that are

Can be used only in preamble. \documentclass
Can be used only in preamble. \usepackage
Can be used only in preamble. \begin{document}
Undefined control sequence. \rowcolor
Undefined control sequence. \rowcolor
Undefined control sequence. ...wcolor[rgb]{0.875,0.655,0.651} {\cellcolor
Undefined control sequence. ...>{\cellcolor[rgb]{0.875,0.655,0.651}}c@{}}
Illegal character in array arg. ...>{\cellcolor[rgb]{0.875,0.655,0.651}}c@{}}
Illegal character in array arg. ...>{\cellcolor[rgb]{0.875,0.655,0.651}}c@{}}
..............


How I can remove these error and use the latex generated table from above two web links into my TeXstudio code

• Last document compiles perfectly with overleaf.com. – pzorba75 Jan 6 at 12:43
• Last document compiles also perfectly with TeXstudio – emeryville Jan 6 at 14:14
• The errors on the second document look like you have pasted the full code inside an existing document. However, the code itself is already a full document, it starts with \documentclass{article} and it ends with \end{document}. You cannot have a document within a document, therefore you get an error. If you copy only the part from \begin{table} to \end{table}, and you put \usepackage{colortbl} together with the other \usepackage statements in your code, then it should work. – Marijn Jan 6 at 21:59
• @Marijn i started my second code within a existing document with this"\usepackage \usepackage{colortbl} \begin{table}" ....it gave me error each line of code.Error Like 1) Can be used only in preamble. \usepackage 2) Undefined control sequence. \rowcolor 3) Undefined control sequence. ...wcolor[rgb]{0.875,0.655,0.651} {\cellcolor .... so on – aaaaa Jan 7 at 4:56
• @aaaaa You should make sure you use the correct code setup for the full document. The first line should be the document class, such as \documentclass{article} or \documentclass{report} or some other document class that you are using (but only one). The next lines in the code should contain all the packages that you use, normally one package per line, for example \usepackage{graphicx} on a line and \usepackage{colortbl} on the next line and any other packages after that. This part of the code (the document class and the packages) is called the preamble. The next line is ... – Marijn Jan 8 at 9:00

In the first Table if you drop \n in the row 12 in the expression s\n\end{tabular} the document compiles perfectly with TeXstudio.

\documentclass{book}
\usepackage{colortbl}
\usepackage{graphicx}
\usepackage[table,xcdraw]{xcolor}

\begin{document}

\chapter{Research gap}

Text ... text.

\begin{table}[]
\centering
\resizebox{\textwidth}{!}{%
\begin{tabular}{ccccccccc}
\rowcolor[HTML]{C0504D}
& \multicolumn{8}{c}{\cellcolor[HTML]{C0504D}MAE} \\
\rowcolor[HTML]{DFA7A6}
\cellcolor[HTML]{C0504D}A & \begin{tabular}[c]{@{}c@{}}A\\ s\end{tabular} & \begin{tabular}[c]{@{}c@{}}V\end{tabular} & \begin{tabular}[c]{@{}c@{}}N\end{tabular} & \begin{tabular}[c]{@{}c@{}}P\end{tabular} & \begin{tabular}[c]{@{}c@{}}H\end{tabular} & \begin{tabular}[c]{@{}c@{}}A\end{tabular} & \begin{tabular}[c]{@{}c@{}}No\end{tabular} & \begin{tabular}[c]{@{}c@{}}J\end{tabular} \\
\rowcolor[HTML]{EFD3D2}
\cellcolor[HTML]{C0504D}Lt & 2& 1& 1& 1&  & 2& 1&  \\
\rowcolor[HTML]{DFA7A6}
\cellcolor[HTML]{C0504D}Xt & 2& 1&  & 1& 1&  & 2&  \\
\rowcolor[HTML]{EFD3D2}
\cellcolor[HTML]{C0504D}\begin{tabular}[c]{@{}c@{}}R\\ \\ r\end{tabular} & 2&  &  &  &  & 2&  &  \\
\rowcolor[HTML]{DFA7A6}
\cellcolor[HTML]{C0504D}\begin{tabular}[c]{@{}c@{}}A\\ \end{tabular} & 2&  &  &  & 2& 2&  &  \\
\rowcolor[HTML]{EFD3D2}
\cellcolor[HTML]{C0504D}N & 2&  & 1&  &  &  &  &  \\
\rowcolor[HTML]{DFA7A6}
\cellcolor[HTML]{C0504D}C & 2&  & 1 &  &  &  &  & 1\\
\rowcolor[HTML]{EFD3D2}
\cellcolor[HTML]{C0504D}\begin{tabular}[c]{@{}c@{}}K\\ e\end{tabular} & 2&  &  &  &  &  &  &  \\
\rowcolor[HTML]{DFA7A6}
\cellcolor[HTML]{C0504D}\begin{tabular}[c]{@{}c@{}}K \end{tabular} & 2 &  &  &  &  &  &  &  \\
\rowcolor[HTML]{EFD3D2}
\cellcolor[HTML]{C0504D}L & 3&  &  &  & 2&  &  &  \\
\rowcolor[HTML]{DFA7A6}
\cellcolor[HTML]{C0504D}\begin{tabular}[c]{@{}c@{}}E \end{tabular} & 2&  &  &  &  &  &  &  \\
\rowcolor[HTML]{EFD3D2}
\cellcolor[HTML]{C0504D}s &  &  & 1&  &  & 2&  &  \\
\rowcolor[HTML]{DFA7A6}
\cellcolor[HTML]{C0504D}\begin{tabular}[c]{@{}c@{}}L \end{tabular} &  &  &  &  & 1&  &  &  \\
\rowcolor[HTML]{EFD3D2}
\cellcolor[HTML]{C0504D}E&  &  &  &  & 2&  &  &  \\
\rowcolor[HTML]{DFA7A6}
\cellcolor[HTML]{C0504D}R &  &  &  &  & 2&  &  &
\end{tabular}%
}
\end{table}
\end{document}

• I want to use this code in existing "\chapter{Research gap}".I can't start with " \documentclass{article} \usepackage{colortbl} \usepackage{graphicx} \usepackage[table,xcdraw]{xcolor} \begin{document}"....How should I start code for a table in existing "\chapter{Research gap}" ? – aaaaa Jan 10 at 10:07
• Do you mean you don't have a preamble? Because if I replace in the preamble \documentclass{article} by \documentclass{book} and add \chapter{Research gap}` it compiles perfectly. You need a preamble see en.wikibooks.org/wiki/LaTeX/Document_Structure for more details. – emeryville Jan 10 at 14:38
• I started with following set of commands "\chapter{Research gap} ---<my text>--- \documentclass{book} \usepackage{colortbl} \usepackage{graphicx} \usepackage[table,xcdraw]{xcolor} \begin{document} \begin{table}[] \centering \begin{tabular}{ccccccccc} \hline ----<my Table>---" ...It give errors like this: "Can be used only in preamble. \documentclass" for each line of the table – aaaaa Jan 11 at 9:01
• You should invert commands. I updated my example. Let me know if it's useful by upvoting it :)! – emeryville Jan 11 at 12:13
• From this link, you can download the project template: drive.google.com/open?id=1DVHh2_af6KyF0lEQ5emCG1feGE3Xk7QK -----------If you extract it. if open this template in TeXstudio.It will compile and run fine. In "\chapter{Methodology}" How i can place my table within the chapter Methodology. – aaaaa Jan 12 at 10:54