Faça esta mesa

Faça esta mesa

Tenho que fazer a tabela da figura, mas recebo vários erros. Você poderia explicar quais são meus erros, por favor? (Não coloquei os números no meu código... quero apenas entender como isso funciona)

insira a descrição da imagem aqui

\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}

Responder1

Como dissemos nos comentários:

  1. você deve usar \\, não //no e das linhas da tabela
  2. %é um caractere especial para o LaTeX, você deve escrever \%se usá-lo como uma porcentagem, caso contrário o LaTeX considera o que segue %como um comentário
  3. no topo de uma tabela, por motivos de espaçamento, você deve usar \toprule, não \bottomrule(é por isso que eles os nomearam dessa forma)
  4. você não deve usar tabularxse não tiver um Xtipo de coluna.

Para explicar melhor o último ponto, veja estes exemplos:

\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}

insira a descrição da imagem aqui

Aplicando tudo isso, aqui está um código funcional (já que sua tabela é maior que a largura da linha que adicionei \footnotesizepara diminuir a fonte).

Para o alinhamento, observe que isso lsignifica esquerda, rdireita e ccentro.

\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}

insira a descrição da imagem aqui

Claro que existem outras soluções, aqui está um exemplo com tabularx. Como a Xcoluna é irregular para a direita por padrão, criei um novo tipo de coluna Rpara que as colunas sejam irregulares para a esquerda.

*5Ré um atalho para 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}

insira a descrição da imagem aqui

Responder2

considerando todos os comentários abaixo da pergunta ... e adicione algumas sugestões:

\documentclass{article}
\usepackage{adjustbox}

%-------------------------------- 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}

insira a descrição da imagem aqui

as linhas vermelhas adicionadas são apenas para mostrar o layout da página.

Responder3

Experimente isso

\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}

informação relacionada