# How to make a table less cramped

I used MathPix OCR program to get the Latex code of this table.

When I tried to use the tabular mode, all the "a" and "g" lost the math font. So I had to put  between each varible.

$\begin{array}{|c|c|c|c|c|c|c|c|c|c|c|} \hline {\text { I }} & a_{11} & a_{12} & a_{13} & b_1 & S_1 & 2,1161 & 0,1254 & 0,1397 & 0,77 & 9,2 \\ \cline { 2 - 11 } & a_{12} & a_{22} & a_{23} & b_2 & S_2 & 0,1254 & 1,1675 & 0,1768 & 0,88 & 10,2 \\ \cline { 2 - 11 } & a_{13} & a_{23} & a_{33} & b_3 & S_3 & 0,1397 & 0,1768 & 1,2168 & 0,99 & 10,2 \\ \hline{\text { II }} & g_{11} & g_{12} & g_{13} & y_1 & S_1^{\prime} & 1,789 & 0,559 & 0,559 & 2,236 & 5,143 \\ \cline { 2 - 11 } & & g_{22} & g_{23} & y_2 & S_2^{\prime} & & 1,841 & 0,374 & 1,766 & 3,98 \\ \cline { 2 - 11 } & & & g_{33} & y_3 & S_3^{\prime} & & & 1,936 & 1,08 & 3,016 \\ \hline \text { III } & x_1 & x_2 & x_3 & & & 0,811 & 0,846 & 0,558 & & \\ \hline \end{array}$


My main advice for giving your table a less-cramped look is to get rid of all vertical rules and employ fewer, but well-spaced, horizontal rules.

And, in order to make the table more readable, I'd also align the numbers in the final five columns on their respective decimal markers. Finally, there's no need to write ^{\prime} unless you possess a moderate to severe self-loathing streak. Just write ' instead and instantaneously make the input more readable. :-)

\documentclass{article} % or some other suitable document class

\usepackage{booktabs} % for well-spaced horizontal rules
\usepackage{siunitx}  % for 'S' column type
\sisetup{output-decimal-marker={,}} % use "," as decimal marker

\begin{document}

$\begin{array}{@{} % suppress left-hand side whitespace padding l *{5}{c} *{3}{S[table-format=1.4]} *{2}{S[table-format=1.3]} @{} } % % suppress right-hand side whitespace padding \toprule \mathrm{I} & a_{11} & a_{12} & a_{13} & b_1 & S_1 & 2,1161 & 0,1254 & 0,1397 & 0,77 & 9,2 \\ & a_{12} & a_{22} & a_{23} & b_2 & S_2 & 0,1254 & 1,1675 & 0,1768 & 0,88 & 10,2 \\ & a_{13} & a_{23} & a_{33} & b_3 & S_3 & 0,1397 & 0,1768 & 1,2168 & 0,99 & 10,2 \\ \addlinespace \mathrm{II} & g_{11} & g_{12} & g_{13} & y_1 & S_1' & 1,789 & 0,559 & 0,559 & 2,236 & 5,143 \\ & & g_{22} & g_{23} & y_2 & S_2' & & 1,841 & 0,374 & 1,766 & 3,98 \\ & & & g_{33} & y_3 & S_3' & & & 1,936 & 1,08 & 3,016 \\ \addlinespace \mathrm{III} & x_1 & x_2 & x_3 & & & 0,811 & 0,846 & 0,558 \\ \bottomrule \end{array}$

\end{document}

• I love that the two answers currently provided both do a good job of solving the problem while having slightly different styles. I personally have a mild preference for what @CarLaTeX did, but (a) that preference could easily change based on the context of the table relative to other objects in the document, and (b) is 100% subjective, as opposed to the only slightly subjective notion that decimal markers (i.e., commas here) should be aligned. (Technically subjective, I suppose, but I believe universally agreed on.) Mar 8, 2023 at 13:37

I would do something like this, with tabularray:

\documentclass{article}
\usepackage{geometry}

\usepackage{tabularray}
\UseTblrLibrary{amsmath}
\UseTblrLibrary{siunitx}
\NewColumnType{A}[1][1.4]{Q[
si={
group-digits  = false,
table-format=#1,
table-number-alignment=center,
output-decimal-marker={,}
},
c]}

\begin{document}
$\begin{tblr}{ colspec={l*{5}{c}*{3}{A}A[1.3]A[2.3]}, % row{1}={guard}, <--- in case you would add a header row column{1}={mode=text}, column{2-Z}={mode=math}, hline{1,4,7,Z}={} } I & a_{11} & a_{12} & a_{13} & b_1 & S_1 & 2,1161 & 0,1254 & 0,1397 & 0,77 & 9,2 \\ & a_{12} & a_{22} & a_{23} & b_2 & S_2 & 0,1254 & 1,1675 & 0,1768 & 0,88 & 10,2 \\ & a_{13} & a_{23} & a_{33} & b_3 & S_3 & 0,1397 & 0,1768 & 1,2168 & 0,99 & 10,2 \\ II & g_{11} & g_{12} & g_{13} & y_1 & S_1' & 1,789 & 0,559 & 0,559 & 2,236 & 5,143 \\ & & g_{22} & g_{23} & y_2 & S_2' & & 1,841 & 0,374 & 1,766 & 3,98 \\ & & & g_{33} & y_3 & S_3' & & & 1,936 & 1,08 & 3,016 \\ III & x_1 & x_2 & x_3 & & & 0,811 & 0,846 & 0,558 & & \\ \end{tblr}$
\end{document}


• +1. Since the OP would appear to want to use the , (comma) symbol as the decimal marker, you may want to add the option output-decimal-marker={,} to the list of arguments of si{...}.
– Mico
Mar 7, 2023 at 8:35
• @Mico Thank you, corrected! Mar 7, 2023 at 8:50

You don't give much context about what the table is supposed to show.

I'd definitely use a table environment with its caption, so you have a place where to explain the data.

Since the table is quite wide, it may make sense to make it as wide as the text width, see the second realization with tabular*. This however depends on your page setup: don't widen the table if it's not above, say, 80% of the text width.

\documentclass{article}
\usepackage{amsmath}
\usepackage{array,booktabs,siunitx}

\sisetup{output-decimal-marker={,}}

\begin{document}

\begin{table}[!htp]
\centering

\begin{tabular}{
@{}% no left padding
c % centered column
*{5}{>{$}c<{$}}% five math columns
*{3}{S[table-format=1.4]}% three numeric columns
S[table-format=1.3]
S[table-format=2.3]
@{}% no right padding
}
\toprule
I   & a_{11} & a_{12} & a_{13} & b_1 & S_1  & 2,1161 & 0,1254 & 0,1397 & 0,77  &  9,2  \\
& a_{12} & a_{22} & a_{23} & b_2 & S_2  & 0,1254 & 1,1675 & 0,1768 & 0,88  & 10,2  \\
& a_{13} & a_{23} & a_{33} & b_3 & S_3  & 0,1397 & 0,1768 & 1,2168 & 0,99  & 10,2  \\
\midrule
II  & g_{11} & g_{12} & g_{13} & y_1 & S_1' & 1,789  & 0,559  & 0,559  & 2,236 & 5,143 \\
&        & g_{22} & g_{23} & y_2 & S_2' &        & 1,841  & 0,374  & 1,766 & 3,98  \\
&        &        & g_{33} & y_3 & S_3' &        &        & 1,936  & 1,08  & 3,016 \\
\midrule
III & x_1    & x_2    & x_3    &     &      &        & 0,811  & 0,846  & 0,558 &  \\
\bottomrule
\end{tabular}

\caption{A table with values, where you should also specify the meaning of the rows and columns}

\end{table}

\begin{table}[!htp]
\centering

\begin{tabular*}{\textwidth}{
@{\extracolsep{\fill}}% no left padding
l % left-aligned column
*{5}{>{$}c<{$}}% five math columns
*{3}{S[table-format=1.4]}% three numeric columns
S[table-format=1.3]
S[table-format=2.3]
@{}% no right padding
}
\toprule
I   & a_{11} & a_{12} & a_{13} & b_1 & S_1  & 2,1161 & 0,1254 & 0,1397 & 0,77  &  9,2  \\
& a_{12} & a_{22} & a_{23} & b_2 & S_2  & 0,1254 & 1,1675 & 0,1768 & 0,88  & 10,2  \\
& a_{13} & a_{23} & a_{33} & b_3 & S_3  & 0,1397 & 0,1768 & 1,2168 & 0,99  & 10,2  \\
\midrule
II  & g_{11} & g_{12} & g_{13} & y_1 & S_1' & 1,789  & 0,559  & 0,559  & 2,236 & 5,143 \\
&        & g_{22} & g_{23} & y_2 & S_2' &        & 1,841  & 0,374  & 1,766 & 3,98  \\
&        &        & g_{33} & y_3 & S_3' &        &        & 1,936  & 1,08  & 3,016 \\
\midrule
III & x_1    & x_2    & x_3    &     &      &        & 0,811  & 0,846  & 0,558 &  \\
\bottomrule
\end{tabular*}

\caption{A table with values, where you should also specify the meaning of the rows and columns}

\end{table}

\end{document}


Try using the array package and defining a new column type:

\usepackage{array}
\newcolumntype{N}{>{$}c<{$}}


and replace in the tabular environment with \usepackage{tabularx}. The pointer > will add the {$} on the left side and < add a {$} on the right side. In addition, put these two commands in your preamble to manipulate the line and column spacing:

\setlength{\tabcolsep}{5pt} % The default is 6pt
\renewcommand{\arraystretch}{1.5} % 1.0 = 100%, 1.5 = 150%, ...


The smaller the value inside the \setlength{\tabcolsep}{} command, the smaller the whitespace inside the cell, however this does not interfere with line spacing, so adding \renewcommand{\arraystretch}{} is essential to compensate for the other command.

Putting it all together:

\documentclass[border = 1cm]{standalone}

\usepackage{array}
\usepackage{amsmath}
\usepackage{tabularx}
\newcolumntype{N}{>{$}c<{$}}
\setlength{\tabcolsep}{5pt}
\renewcommand{\arraystretch}{1.5}

\begin{document}

\begin{tabular}{|N|N|N|N|N|N|N|N|N|N|N|}
\hline
{\text { I }} & a_{11} & a_{12} & a_{13} & b_1 & S_1 & 2,1161 & 0,1254 & 0,1397 & 0,77 & 9,2 \\
\cline
{ 2 - 11 } & a_{12} & a_{22} & a_{23} & b_2 & S_2 & 0,1254 & 1,1675 & 0,1768 & 0,88 & 10,2 \\
\cline
{ 2 - 11 } & a_{13} & a_{23} & a_{33} & b_3 & S_3 & 0,1397 & 0,1768 & 1,2168 & 0,99 & 10,2 \\
\hline
{\text { II }} & g_{11} & g_{12} & g_{13} & y_1 & S_1^{\prime} & 1,789 & 0,559 & 0,559 & 2,236 & 5,143 \\
\cline
{ 2 - 11 } & & g_{22} & g_{23} & y_2 & S_2^{\prime} & & 1,841 & 0,374 & 1,766 & 3,98 \\
\cline
{ 2 - 11 } & & & g_{33} & y_3 & S_3^{\prime} & & & 1,936 & 1,08 & 3,016 \\
\hline
\text { III } & x_1 & x_2 & x_3 & & & 0,811 & 0,846 & 0,558 & & \\
\hline
\end{tabular}
\end{document}


• In what sense does replacing the array environment with a tabular  environment create output that looks less cramped?
– Mico
Mar 7, 2023 at 7:37
• @Mico In no sense ('-'), I forgot to put the part to make it less tight. I already edited my post. I just used the tabular environment because that is what I am most used to using. Mar 7, 2023 at 7:57
• The claim that "The smaller the value inside the \setlength{\tabcolsep}{} command, the smaller the letter compression inside the table" is puzzling. For sure, the parameter \tabcolsep is not related to "cell compression"; instead, it governs the amount of whitespace padding that's inserted on both sides of a cell in a tabular-like environment.
– Mico
Mar 7, 2023 at 8:19
• Oh okay, I'll edit the post Mar 7, 2023 at 8:23