[Tex/LaTex] How to align tables in LaTeX

tables

Is there a way to align tables in LaTeX?

I was writing a document with several tables in the same page, and often the edges don't match.

I would like to have tables aligned in both left and right edge.

\paragraph{Articoli}
\begin{large}
\begin{tabular}{ | l | l | l | p{3cm} |}
\hline
\textbf{Attributo} & \textbf{Tipo} & \textbf{Byte} & \textbf{Complessivo} 
\\    \hline
& & & 1500 occorrenze \\ \hline
Codice & Char(7) & 7 & 10,7 kB \\ \hline
Nome  &  Varchar (100) & 100 & 150 kB  \\ \hline
Marca & Varchar (100) & 100 & 150 kB \\ \hline
Prezzo & Money & 8 & 12,2 kB \\ \hline
Disponibile & Integer & 4 & 6.2 kB \\ \hline
Soglia & Integer & 4 & 6.2 kB \\ \hline
Reparto & Char (4) & 4 & 6.2 kB \\ \hline
Totale &  & &   321 kB      \\ \hline
Dati + Block Header & & & 322 kB \\ \hline
    \end{tabular}
\paragraph{Reparti}
 \begin{tabular}{ | l | l | l | p{3cm} |}
    \hline
    \textbf{Attributo} & \textbf{Tipo} & \textbf{Byte} & \textbf{Complessivo}        
     \\ \hline
    & & & 120 occorrenze \\ \hline
    Codice & Char(4) & 4 & 0,5 kB  \\ \hline
    Nome  &  Varchar (100) &  100 & 12.1 kB \\ \hline
    Sezione & Char(4) & 4 & 0.5 kB \\ \hline
    Totale &  & &  12.2 kB        \\ \hline
    Dati + Block Header & & & 12.3 kB \\ \hline
        \end{tabular}
  \paragraph{Pagamenti}
 \begin{tabular}{ | l | l | l | p{3cm} |}
    \hline
    \textbf{Attributo} & \textbf{Tipo} & \textbf{Byte} & \textbf{Complessivo} \\ \hline
    & & & 10 occorrenze  \\ \hline
    Codice & Char(4) & 4 & 0,1 kB \\ \hline
    Nome  &  Varchar (100) &  100 & 1 kB  \\ \hline
            Totale &  & &  1.1 kB       \\ \hline
            Dati + Block Header & & & 1.2 kB  \\ \hline
        \end{tabular}

Best Answer

I think you're abusing the \paragraph macro. I believe it's preferable to set up a new macro that typesets its argument ("articoli", "reparti", and "pagamenti", resp.) in bold in a "box" of a given width.

A separate comment: In the right-hand column of the tables, you seem to be using commas and periods ("full stops") to denote the decimal marker. I believe it's good practice to standardize the notation.

enter image description here

\documentclass{article}
\newlength\mylen
\settowidth{\mylen}{\bfseries Pagamenti \ \ }
\begin{document}
\noindent\parbox{\mylen}{\bfseries Articoli}
\begin{tabular}{ | l | l | l | p{3cm} |}
\hline
\textbf{Attributo} & \textbf{Tipo} & \textbf{Byte} & \textbf{Complessivo} 
\\    \hline
& & & 1500 occorrenze \\ \hline
Codice & Char(7) & 7 & 10,7 kB \\ \hline
Nome  &  Varchar (100) & 100 & 150 kB  \\ \hline
Marca & Varchar (100) & 100 & 150 kB \\ \hline
Prezzo & Money & 8 & 12,2 kB \\ \hline
Disponibile & Integer & 4 & 6.2 kB \\ \hline
Soglia & Integer & 4 & 6.2 kB \\ \hline
Reparto & Char (4) & 4 & 6.2 kB \\ \hline
Totale &  & &   321 kB      \\ \hline
Dati + Block Header & & & 322 kB \\ \hline
    \end{tabular}


\bigskip\noindent\parbox{\mylen}{\bfseries Reparti}
 \begin{tabular}{ | l | l | l | p{3cm} |}
    \hline
    \textbf{Attributo} & \textbf{Tipo} & \textbf{Byte} & \textbf{Complessivo}        
     \\ \hline
    & & & 120 occorrenze \\ \hline
    Codice & Char(4) & 4 & 0,5 kB  \\ \hline
    Nome  &  Varchar (100) &  100 & 12.1 kB \\ \hline
    Sezione & Char(4) & 4 & 0.5 kB \\ \hline
    Totale &  & &  12.2 kB        \\ \hline
    Dati + Block Header & & & 12.3 kB \\ \hline
        \end{tabular}

\bigskip\noindent\parbox{\mylen}{\bfseries Pagamenti}
 \begin{tabular}{ | l | l | l | p{3cm} |}
    \hline
    \textbf{Attributo} & \textbf{Tipo} & \textbf{Byte} & \textbf{Complessivo} \\ \hline
    & & & 10 occorrenze  \\ \hline
    Codice & Char(4) & 4 & 0,1 kB \\ \hline
    Nome  &  Varchar (100) &  100 & 1 kB  \\ \hline
            Totale &  & &  1.1 kB       \\ \hline
            Dati + Block Header & & & 1.2 kB  \\ \hline
        \end{tabular}
\end{document}
Related Question