# Table with multiple rows and columns, column issue

I am trying to replicate the following table in LaTeX

I have tried the following but I'm a beginner in making these more complicated tables, so I got stuck:

\documentclass[12pt,fleqn]{article}
\usepackage{booktabs,multirow}
\usepackage[table]{xcolor}
\usepackage{siunitx}
\begin{document}
\begin{table}[h!]
\label{tab:table2}
\centering
\begin{tabular}{S[table-format=1.0,
table-space-text-post={*}]
*{11}{>{$}c<{$}}
}
\toprule
{\multirow{4.5}{*}{\textbf{Basic Variable}}}
& \multirow{4.5}{*}{\textbf{Eq.}}
& \multicolumn{7}{c}{\textbf{Coefficient of:}}
& \multirow{4.5}{*}{\textbf{Right Side}}
& \multirow{4.5}{*}{\textbf{Ratio}}    \\
\cmidrule{3-8}
&  Z     & x_1      & x_2    & x_3 & x_4 & x_5 & x_6      \\
\midrule
Z   & (0) & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1    \\
\midrule
x_2   & (1) & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1   \\
x_6 & (2) & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1   \\
x_3  & (3) & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1   \\
\bottomrule
\end{tabular}
\end{table}
\end{document}


What can I do to fix the table? Any general suggestions are also appreciated.

Note: I do not want all vertical lines in the original table, plus the variables should be neat (not just x2, x6, x3 but with subscripts) (these things are already implemented in my code though).

• You must not use _ if you are not in math mode – book Dec 3 '18 at 12:11
• Your table has a lot of different numbers of columns, that cannot work. You tell that the table should have 12 columns, second row has 8 columns, 3rd row has 10 columns. The math does not match.... – book Dec 3 '18 at 12:15
• If you are using Excel I suggest using excel2latex. – user156344 Dec 3 '18 at 12:15
• @DũngVũ Noooooooooo, the output of excel2latex adds tons of incorrect multicolumns which will totally disable the purpose of siunitx to align the numbers – book Dec 3 '18 at 12:18
• @Book I fixed the first thing you mention. I see that the math does not match, but how to get it all right is hard. And no, I don't use Excel. – Anna Dec 3 '18 at 12:20

## 1 Answer

It is not very clear what you want to achieve.

If this doesn't fit your needs, let me know.

\documentclass[12pt,fleqn]{article}
\usepackage{caption}
\usepackage{booktabs,multirow}
\usepackage{siunitx}
\begin{document}
\begin{table}[h!]
\caption{\label{tab:table2}A caption}
\centering
\begin{tabular}{
*{11}{>{$}c<{$}}
}
\toprule
\textbf{Basic}
&
& \multicolumn{7}{c}{\textbf{Coefficient of:}}
& \textbf{Right}     \\
\cmidrule(lr){3-9}
\textbf{Variable} &\textbf{Eq.} & Z     & x_1      & x_2    & x_3 & x_4 & x_5 & x_6 &\textbf{Side} \\
\midrule
Z   & (0) & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1    \\
\midrule
x_2   & (1) & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1   \\
x_6 & (2) & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1   \\
x_3  & (3) & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1   \\
\bottomrule
\end{tabular}
\end{table}
\end{document}


• (+1) I recommend adding a picture showing the table. – user156344 Dec 3 '18 at 13:47
• your answer perfectly fit my taste at table design (+1) :-) – Zarko Dec 3 '18 at 15:36
• Hi all, that's exactly what I wanted to achieve but could not. Thank you. (Another table I had to make later on I could do on my own due to the help you provided) And @Zarko, thanks again for your earlier suggestion for this nice table design. – Anna Dec 5 '18 at 21:40