# Make this table

I have to make the table in the figure, but I get several errors. Could you explain what are my mistakes, please? (I did not put the numbers in my code...I want to just understand how this works)

\begin{document}
\begin{tabularx} {\textwidth} {cccccc}
\bottomrule
Regione & Assistiti & di cui over 65 & di cui under 65 & % anziani & % under 65
\midrule
Italia & x & x & x & x& x //
Nord & x & x & x & x& x //
Centro & x & x & x & x& x //
Sud & x & x & x & x& x //
Basilicata & x & x & x & x& x //
\bottomrule
end{tabularx}
\end{document}

• You should not use // instead of \\ .
– user121799
Feb 13 '18 at 13:12
• and you should write \% instead of % otherwise LaTeX considers the following words as comments Feb 13 '18 at 13:14
• also the options on the align are {lrrrrr} because you want first column left aligned and tho others right and not centered. Or you have to look at siunitx package to align on "." the numbers Feb 13 '18 at 13:15
• and don't use tabularx if you don't have an X column type Feb 13 '18 at 13:15
• Also, at the top of a table, preferably (for spacing reasons) put a \toprule. Feb 13 '18 at 13:16

1. you should use \\, not // at the and of the table rows
2. % is a special char for LaTeX, you should write \% if you use it as a percentage, otherwise LaTeX considers what follows % as a comment
3. at the top of a table, for spacing reasons, you should use \toprule, not \bottomrule (that's why they have named them in that way)
4. you should not use tabularx if you don't have an X column type.

To explain better the last point, look at these examples:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{booktabs}
\usepackage{tabularx}
\begin{document}
In the following example, since the table is longer than the line width
(we have an \verb|Overfull \hbox| error), the lines stop before the text
ends:

\begin{center}
\begin{tabularx}{\linewidth}{cc}
\toprule
Don't try this at home, this is wrong! & Non fatelo, è sbagliato!\\
\midrule
Example of wrong use of \texttt{tabularx} & Esempio di un uso sbagliato di \texttt{tabularx}\\
\bottomrule
\end{tabularx}
\end{center}

In the following example, since the table is too much shorter than the
line width, the lines go too much ahead w.r.t. the text:

\begin{center}
\begin{tabularx}{\linewidth}{cc}
\toprule
This is wrong! & Questo è sbagliato!\\
\midrule
Wrong use & Uso sbagliato\\
\bottomrule
\end{tabularx}
\end{center}

Whereas, with \verb|X| columns:
\begin{center}
\begin{tabularx}{\linewidth}{XX}
\toprule
Try this at home, this is correct! & Questo si può fare, è giusto!\\
\midrule
Example of correct use of \texttt{tabularx} & Esempio di un uso corretto di \texttt{tabularx}\\
\bottomrule
\end{tabularx}
\end{center}
\begin{center}
\begin{tabularx}{\linewidth}{XX}
\toprule
This is correct! & Questo è corretto!\\
\midrule
Correct use & Uso corretto\\
\bottomrule
\end{tabularx}
\end{center}
\end{document}


Applying all that, here is a working code (since your table is lager than the line width I added \footnotesize to make the font smaller).

For the alignment, please note that l means left, r right, and c center.

\documentclass{article}
\usepackage{booktabs}

\begin{document}
\begin{center}
\footnotesize\begin{tabular}{lrrrrr}
\toprule
Regione & Assistiti & di cui over 65 & di cui under 65 & \% anziani & \% under 65\\
\midrule
Italia & x & x & x & x& x \\
Nord & x & x & x & x& x \\
Centro & x & x & x & x& x \\
Sud & x & x & x & x& x \\
Basilicata & x & x & x & x& x \\
\bottomrule
\end{tabular}
\end{center}
\end{document}


Of course there are other solutions, here is an example with tabularx. Since the X column is ragged right by default, I created a new column type R to have the columns ragged left.

*5R is a shorcut for RRRRR.

\documentclass{article}
\usepackage{array}
\usepackage{tabularx}
\usepackage{booktabs}
\newcolumntype{R}{>{\raggedleft\arraybackslash}X}
\begin{document}
\begin{tabularx}{\linewidth}{l*5R}
\toprule
Regione & Assistiti & di cui over 65 & di cui under 65 & \% anziani & \% under 65\\
\midrule
Italia & x & x & x & x& x \\
Nord & x & x & x & x& x \\
Centro & x & x & x & x& x \\
Sud & x & x & x & x& x \\
Basilicata & x & x & x & x& x \\
\bottomrule
\end{tabularx}
\end{document}


• Thank you! May I know why do you use (1) \begin{center} (2) {lrrrrr} Feb 13 '18 at 13:25
• @Alwayslearning The center environment centers your table. You can also use table environment if you have a caption. Feb 13 '18 at 13:26
• @Alwayslearning, the {lrrrrr} corresponds to the outline of the columns within the table. You have 6 columns and they are outlined "left", "right", "right", "right", "right", "right", just like in your example. Change one of these letters to "c" (stands for center) and see what happens! Feb 13 '18 at 13:32
• @Alwayslearning instead of using \\, leave a blank line. Feb 13 '18 at 18:05

\documentclass{article}

%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}
\begin{table}[htb]
\sisetup{group-minimum-digits=4,
group-separator={.},
output-decimal-marker={,}}
\setlength\tabcolsep{0pt}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}
l
*{2}{S[table-format=6.0]}
S[table-format=5.0]
*{2}{S[table-format=2.2]}
}
\toprule
Regione & {Assistiti} & {di cui over 65} & {di cui under 65} & {\% anziani} & {\% under 65} \\
\midrule
Italia  & 123456      & 12345            & 1234              & 12,34        & 12,34         \\
Nord    & 12345       & 123456           & 123               & 12,34        & 12,34         \\
Centro  & 123456      & 12345            & 12345             & 12,34        & 12,34         \\
Sud     & 123456      & 12345            & 1234              & 12,34        & 12,34         \\
\bottomrule
\end{tabular*}
\end{table}
\end{document}


added red lines are only for show page layout.

• in the first shot i load wrong version of code (with missing end :-( ) and wrong image. now this is corrected. is now table still not acceptable to you? if it, please show us, how you will do :-) Feb 13 '18 at 13:51
• @CarLaTeX... I show it and deleted my comment... In Greek too (:P) Feb 13 '18 at 13:51
• It is fine! Sorry for hurrying to comment before really understand (my problem is what CarLaTeX understood) Feb 13 '18 at 13:55
• @koleygr, thank you for pointing to problem of my code. fortunately i observe this problem almost in the same time as you ... and try to put my cyber chaos in some order :-). i understood your comment very positive and in my response try to challenge/encourage you, to write (better) solution :-) Feb 13 '18 at 14:21

Try this

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}

\begin{document}
\begin{tabularx} {\textwidth} {cccccc}
\hline
Regione & Assistiti & di cui over 65 & di cui under 65 & \% anziani & \% under 65 \\
\hline
Italia      & x & x & x & x & x \\
Nord        & x & x & x & x & x \\
Centro      & x & x & x & x & x \\
Sud         & x & x & x & x & x \\
Basilicata  & x & x & x & x & x \\
\hline
\end{tabularx}
\end{document}

• it does not do the job well Feb 13 '18 at 13:37
• It works...I forgot to add the package before. Thanks! Feb 13 '18 at 13:40
• 1) As already said, using tabularx without an X column is useless. 2) Due to 1), the last columns header goes outside the table because the table itself is larger than the text width. Feb 13 '18 at 14:05