hacer esta mesa

hacer esta mesa

Tengo que hacer la tabla de la figura, pero me sale varios errores. ¿Podrías explicar cuáles son mis errores, por favor? (No puse los números en mi código... sólo quiero entender cómo funciona esto)

ingrese la descripción de la imagen aquí

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

Respuesta1

Como dijimos en los comentarios:

  1. debes usar \\, no //en el y de las filas de la tabla
  2. %es un carácter especial para LaTeX, debes escribirlo \%si lo usas como porcentaje, de lo contrario LaTeX considera lo que sigue %como un comentario
  3. en la parte superior de una tabla, por razones de espacio, debes usar \toprule, no \bottomrule(por eso los han nombrado de esa manera)
  4. no debes usarlo tabularxsi no tienes un Xtipo de columna.

Para explicar mejor el último punto, mira estos ejemplos:

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

ingrese la descripción de la imagen aquí

Aplicando todo eso, aquí hay un código de trabajo (ya que su tabla es más grande que el ancho de línea que agregué \footnotesizepara hacer la fuente más pequeña).

Para la alineación, tenga en cuenta que lsignifica izquierda, rderecha y 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}

ingrese la descripción de la imagen aquí

Por supuesto que hay otras soluciones, aquí hay un ejemplo con tabularx. Dado que la Xcolumna está irregular a la derecha de forma predeterminada, creé un nuevo tipo de columna Rpara que las columnas estén irregulares a la izquierda.

*5Res un atajo 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}

ingrese la descripción de la imagen aquí

Respuesta2

considerando todos los comentarios a continuación de la pregunta... y agregue algunas de mis sugerencias:

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

ingrese la descripción de la imagen aquí

Las líneas rojas agregadas son solo para mostrar el diseño de la página.

Respuesta3

Prueba esto

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

información relacionada