2

I've a problem with a tabular. Here the MVE:

\documentclass[A4,11pt,twoside]{book}
\usepackage[T1]{fontenc}

\begin{tabular}{l|l|l|c|c|c|c}
\hline\hline
\multicolumn{4}{c}{\textbf{Livello Istruzione}}\\
\hline
\multicolumn{2}{c}{\textbf{Fascia 1}} & \multicolumn{2}{c}{\textbf{Fascia 2}} & \multicolumn{2}{c}{\textbf{Fascia 3}} & \multicolumn{2}{c}{\textbf{Fascia 4}}\\
\hline
\multicolumn{1}{c}{\textbf{BdM}} & \multicolumn{1}{c}{\textbf{BTV}} & \multicolumn{1}{c}{\textbf{BdM}} & \multicolumn{1}{c}{\textbf{BTV}} & \multicolumn{1}{c}{\textbf{BdM}} & \multicolumn{1}{c}{\textbf{BTV}} & \multicolumn{1}{c}{\textbf{BdM}} & \multicolumn{1}{c}{\textbf{BTV}}\\
\hline
30\% & 40\% & 2\%\\
20\% & 25\%\\
\hline\hline
\end{tabular}

I want a tabular like this:

enter image description here

but latex says "Error: extra allignement..."

Thank you for help!

3
2

If you really want to create the look of the table shown in your screenshot, you should use the l column type for all 8 columns of the tabular environment. (The code you posted features a mixture of l and c cells.)

In the header cells, you appear to want to center rather than left-align the cell contents. In the second argument of \multicolumn, be sure to specify whether or not | ("vertical bar") should appear at the left- or right-hand edges of the column.

enter image description here

\documentclass[a4paper,11pt,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\begin{document}
\begin{tabular}{|*{8}{l|}}
\hline
\multicolumn{8}{|c|}{} \\
\multicolumn{8}{|c|}{\textbf{Livello Istruzione}}\\
\multicolumn{8}{|c|}{} \\
\hline
\multicolumn{2}{|c|}{\textbf{Fascia 1}} & 
\multicolumn{2}{c|}{\textbf{Fascia 2}}  & 
\multicolumn{2}{c|}{\textbf{Fascia 3}}  & 
\multicolumn{2}{c|}{\textbf{Fascia 4}}  \\
\hline
\multicolumn{1}{|c|}{\textbf{BdM}} & \multicolumn{1}{c|}{\textbf{BTV}}  & 
\multicolumn{1}{c|}{\textbf{BdM}}  & \multicolumn{1}{c|}{\textbf{BTV}}  & 
\multicolumn{1}{c|}{\textbf{BdM}}  & \multicolumn{1}{c|}{\textbf{BTV}}  & 
\multicolumn{1}{c|}{\textbf{BdM}}  & \multicolumn{1}{c|}{\textbf{BTV}}  \\
\hline
30\% & 40\% & 2\% & & & & & \\
20\% & 25\% &     & & & & & \\
\hline
\end{tabular}
\end{document}
2

I have edited this answer because, with the latest version of nicematrix (5.6), we don't need makecell any longer here.


You can obtain the look of the table in the question with nicematrix. With this solution, all the expected rules are drawn with only one key hvlines.

\documentclass{article}
\usepackage{nicematrix}
\usepackage{geometry}
\begin{document}
\begin{NiceTabular}{*{8}{c}}[hvlines]
\Block{1-8}{\textbf{Livello Istruzione}}\\
\Block{1-2}{\textbf{Fascia 1}}  && 
\Block{1-2}{\textbf{Fascia 2}}  && 
\Block{1-2}{\textbf{Fascia 3}}  && 
\Block{1-2}{\textbf{Fascia 4}}  \\
\textbf{BdM}  & \textbf{BTV}  & 
\textbf{BdM}  & \textbf{BTV}  & 
\textbf{BdM}  & \textbf{BTV}  & 
\textbf{BdM}  & \textbf{BTV}  \\
\Block{}{30\% \\ 20\%} & \Block{}{40\%\\20\%} & \Block{}{2\%\\25\%} \\
\end{NiceTabular}
\end{document}

Output of the above code

0

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.