3

I've tried nearly everything with no success and I don't know why... I have a tablular with 9 columns and the only solution I found for fitting it into textwidth is using adjustbox, which I don't like because it scale the fonts it seems. So the numbers on my table can't barely be seen:

using adjustbox

I tried several other methods and the only one I found to "work" is to set manually the column padding instead of using adjustbox by adding to each one: @{\hspace{0.5em}}:

using manual padding

But then I have those unaligned vertical lines and I don't know how to deal with it... It's been like 4 hours since I started to solve this problem and nothing worked at all.

All I want is to adjust the table to the textwidth and make the number bigger by reducing the padding in each column. Can anyone help me a little bit? Thanks!

\begin{table}
\centering
\begin{adjustbox}{max width=\textwidth}
\begin{tabular}{|c|c|c|c|c|c|c|c|c|}
   \multicolumn{1}{c}{} &  \multicolumn{4}{c|}{Conjunto de datos original}  & \multicolumn{4}{c}{Conjunto de datos reducido} \\
    \cline{2-9}
   \multicolumn{1}{c|}{} & Filtro I & Filtro R & Filtro V & Filtros I,R,V & Filtro I & Filtro R & Filtro V & Filtros I,R,V \\

    \hline

   \begin{tabular}[c]{@{}c@{}}$q=0.62$\\ \citep{2007ApJ...662..564B} \end{tabular}  & $43.2_{-4.7}^{+4.2}$ & $41.9_{-3.4}^{+3.6}$ & $47.0_{-6.3}^{+6.3}$ & $41.7^{+3.8}_{-4.1}$ & $41.0_{-3.4}^{+3.5}$ & $45.3_{-4.8}^{+4.1}$ & $42.6_{-4.9}^{+5.8}$ & $45.5^{+4.9}_{-4.9}$ \\
    \hline

    \begin{tabular}[c]{@{}c@{}}$q=0.68$\\ \citep{2017MNRAS.472.2937H} \end{tabular} & $44.6_{-4.0}^{+4.8}$ & $43.1_{-3.6}^{+4.4}$ & $48.8_{-7.1}^{+7.5}$ & $43.0^{+4.5}_{-4.4}$ & $42.2_{-3.6}^{+4.4}$ & $46.5_{-5.5}^{+4.9}$ & $44.0_{-5.3}^{+5.3}$ & $46.8^{+5.6}_{-5.2}$ \\

    \hline

   Bootstrapping & $47.1_{-1.5}^{+1.5}$ & $45.6_{-1.3}^{+1.3}$ & $44.8_{-2.0}^{+2.4}$ & - & $44.0_{-1.3}^{+1.4}$ & $43.0_{-1.3}^{+1.4}$ & $40.3_{-2.7}^{+2.5}$ & - \\

    \hline
\end{tabular}
\end{adjustbox}
\caption{Resumen de los valores de $i$ destacados, obtenidos mediante diferentes métodos.}
\label{resultados finales}
\end{table}
New contributor
Peybol is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
4
  • 1
    Welcome to TeX.SE. Please tell us how wide the textblock is. Alternatively, could you tell us which paper sheet size you employ (US Letter?, A4?, something else?) and how wide the margins are?
    – Mico
    Commented 2 days ago
  • Hi! Thanks for helping :) I'm pretty rockie in LaTeX so I have no idea on what are you asking... is this helping? \documentclass[12pt,a4paper]{article} \usepackage[utf8]{inputenc} \usepackage[top=3cm, bottom=1.8cm, left=2cm, right=2cm]{geometry}
    – Peybol
    Commented 2 days ago
  • yes but you should add it to the code in your question, and the missing \begin{document} and \usepackage so that peopel can copy the code and see the result. especially in a question like this the \geometry setting is more important than the table in your exampel as you are asking how to make a table fit in a space without sayong how big the space is Commented 2 days ago
  • Ok, thanks everyone for the tips and patience!
    – Peybol
    Commented 2 days ago

4 Answers 4

4

I endorse Mico's idea, but I'd make a few changes.

First off, a numeric table always benefits from siunitx; in this case there are two main reasons:

  1. the decimal comma is used throughout without the need of trusting babel-spanish;

  2. the asymmetric uncertainties are input in a much easier and uniform way.

The other main change is to set the citation callouts in a legend below the table, saving precious space. Finally, I got rid of the abbreviations and of unnecessary horizontal rules.

\documentclass[12pt,a4paper]{article}
 
%\usepackage[utf8]{inputenc}  % that's the default nowadays
\usepackage[top=3cm,bottom=1.8cm,hmargin=2cm]{geometry}

\usepackage[T1]{fontenc}
\usepackage[spanish,es-tabla]{babel}

\usepackage[authoryear,round]{natbib} % for \citep macro

\usepackage{booktabs}        % for well-spaced horizontal rules
\usepackage{siunitx}         % for numeric tables

\begin{document}

\begin{table}[htp]
\setlength\tabcolsep{0pt}

\begin{tabular*}{\textwidth}{
  @{\extracolsep{\fill}}
  l
  *{8}{S[table-format=2.1(1)]}
  @{}
}
\toprule
& \multicolumn{8}{c}{Filtros} \\
\cmidrule{2-9}
& \multicolumn{4}{c}{Conjunctos de datos original}  
& \multicolumn{4}{c}{Conjunctos de datos reducido} \\
\cmidrule{2-5} \cmidrule{6-9}
& {I} & {R} & {V} & {I,\,R,\,V} & {I} & {R} & {V} & {I,\,R,\,V} \\
\midrule

$q=0.62$ (a)
& 43.2(42:47) & 41.9(36:34) & 47.0(63:63) & 41.7(38:41) 
& 41.0(35:34) & 45.3(41:48) & 42.6(58:49) & 45.5(40:49) \\

\addlinespace

$q=0.68$ (b)
& 44.6(48:40) & 43.1(44:36) & 48.8(75:71) & 43.0(45:44)
& 42.2(44:36) & 46.5(49:55) & 44.0(53:53) & 46.8(56:52) \\

\addlinespace

Bootstrapping
& 47.1(15:15) & 45.6(13:13) & 44.8(24:20) & {--} 
& 44.0(14:13) & 43.0(14:13) & 40.3(25:27) & {--} \\

\midrule[\heavyrulewidth]

\multicolumn{9}{l}{%
  (a) \citet{2007ApJ...662..564B},\quad
  (b) \citet{2017MNRAS.472.2937H}
}
\end{tabular*}

\caption{Resumen de los valores de i destacados, obtenidos mediante diferentes métodos.}
\label{resultados_finales}

\end{table}

\end{document}

Production note: I used dummy bibliographic data to match the citations in your picture.

enter image description here

3
  • I like how it looks! Didn't know about that package... I tried to add this answer to my document but it's giving me some errors in siunitx package: Package siunitx Error: Invalid number '43.2(42'. Its something related to the new format errors for numbers right?
    – Peybol
    Commented 2 days ago
  • @Peybol Quite likely you have an outdated version
    – egreg
    Commented 2 days ago
  • Mmm I tried your code in a new document and it worked (I'm using overleaf), but in the document I already have is not working and don't know why, maybe another packages are doing weird things? I put this ones just before the \begin{document}
    – Peybol
    Commented 2 days ago
5

It suffices to (a) switch to a tabular* environment (with a target width of \textwidth) while setting \tabcolsep -- which governs the amount of intercolumn whitespace padding -- to 0pt and (b) shorten some of the header cells. I would also get rid of all vertical rules and replace the basic \hline directives with the line-drawing macros of the booktabs package. Your readers may appreciate the table's more open and inviting "look".

enter image description here

\documentclass[12pt,a4paper]{article}
 
%\usepackage[utf8]{inputenc}  % that's the default nowadays
\usepackage[top=3cm,bottom=1.8cm,hmargin=2cm]{geometry}

\usepackage[T1]{fontenc}
\usepackage[spanish,es-tabla]{babel}

\usepackage{array} % for \newcolumntype macro
\newcolumntype{C}{>{$}c<{$}} % automatic math mode

\usepackage[numbers]{natbib} % for \citep macro
\usepackage{booktabs}        % for well-spaced horizontal rules
\newcommand\mytab[1]{\begin{tabular}{l} #1 \end{tabular}} % handy shortcut macro

\begin{document}

\begin{table}
\setlength\tabcolsep{0pt}

\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} l *{8}{C} }
\toprule
& \multicolumn{4}{c}{Filtros, Conj.\ de datos original}  
& \multicolumn{4}{c}{Filtros, Conj.\ de datos reducido} \\
\cmidrule(l){2-5} \cmidrule(l){6-9}
& I & R & V & I,R,V & I & R & V & I,R,V \\
\midrule

\mytab{$q{=}0.62$\\ \citep{2007ApJ...662..564B}}
& 43.2_{-4.7}^{+4.2} & 41.9_{-3.4}^{+3.6} 
& 47.0_{-6.3}^{+6.3} & 41.7^{+3.8}_{-4.1} 
& 41.0_{-3.4}^{+3.5} & 45.3_{-4.8}^{+4.1} 
& 42.6_{-4.9}^{+5.8} & 45.5^{+4.9}_{-4.9} \\

\midrule

\mytab{$q{=}0.68$\\ \citep{2017MNRAS.472.2937H}}
& 44.6_{-4.0}^{+4.8} & 43.1_{-3.6}^{+4.4} 
& 48.8_{-7.1}^{+7.5} & 43.0^{+4.5}_{-4.4} 
& 42.2_{-3.6}^{+4.4} & 46.5_{-5.5}^{+4.9} 
& 44.0_{-5.3}^{+5.3} & 46.8^{+5.6}_{-5.2} \\

\midrule

Bootstr. 
& 47.1_{-1.5}^{+1.5} & 45.6_{-1.3}^{+1.3} 
& 44.8_{-2.0}^{+2.4} & \mbox{--} 
& 44.0_{-1.3}^{+1.4} & 43.0_{-1.3}^{+1.4} 
& 40.3_{-2.7}^{+2.5} & \mbox{--} \\

\bottomrule
\end{tabular*}

\caption{Resumen de los valores de i destacados, obtenidos mediante diferentes métodos.}
\label{resultados_finales}
\end{table}

\end{document}
1
  • Thanks for the reply. It surely is a nonsense but I don't like to shorten these things :( But it results in a pretty clear view for the whole table.
    – Peybol
    Commented 2 days ago
5

Consider swapping your layout from horizontal (current) to vertical:

enter image description here

\documentclass{article}

\usepackage{makecell,booktabs}

\begin{document}

\begin{figure}
  \centering
  \begin{tabular}{ l l c c c }
    \toprule
    & \multicolumn{1}{c}{Filtro(s)} &
      \makecell[b]{$q = 0.62$ \\ (Bitner et al.~2007)} & % \citep{2007ApJ...662..564B}
      \makecell[b]{$q = 0.68$ \\ (Hill et al.~2017)} & %\citep{2017MNRAS.472.2937H}
      Bootstrapping \\
    \midrule
    \multicolumn{5}{l}{\itshape Conjunto de datos original} \\[0.5em]
    & I       & $43.2_{-4.7}^{+4.2}$ & $44.6_{-4.0}^{+4.8}$ & $47.1_{-1.5}^{+1.5}$ \\[0.5em]
    & R       & $41.9_{-3.4}^{+3.6}$ & $43.1_{-3.6}^{+4.4}$ & $45.6_{-1.3}^{+1.3}$ \\[0.5em]
    & V       & $47.0_{-6.3}^{+6.3}$ & $48.8_{-7.1}^{+7.5}$ & $44.8_{-2.0}^{+2.4}$ \\[0.5em]
    & I, R, V & $41.7^{+3.8}_{-4.1}$ & $43.0^{+4.5}_{-4.4}$ &          --          \\
    \addlinespace
    \multicolumn{5}{l}{\itshape Conjunto de datos reducido} \\[0.5em]
    & I       & $44.0_{-1.3}^{+1.4}$ & $41.0_{-3.4}^{+3.5}$ & $42.2_{-3.6}^{+4.4}$ \\[0.5em]
    & R       & $43.0_{-1.3}^{+1.4}$ & $45.3_{-4.8}^{+4.1}$ & $46.5_{-5.5}^{+4.9}$ \\[0.5em]
    & V       & $42.6_{-4.9}^{+5.8}$ & $44.0_{-5.3}^{+5.3}$ & $40.3_{-2.7}^{+2.5}$ \\[0.5em]
    & I, R, V & $45.5^{+4.9}_{-4.9}$ & $46.8^{+5.6}_{-5.2}$ &          --          \\
    \bottomrule
  \end{tabular}
  \caption{A figure caption}
\end{figure}

\end{document}
1
  • Thanks for your idea! It's something I want to avoid because all other tables in the document follow the same horizontal layout... For the next document I'll take this into account!
    – Peybol
    Commented 2 days ago
3

I endorse combination of the Werner's and egreg's ideas, but with use of ˙tabularray` package:

\documentclass[12pt,a4paper]{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs,               % for well-spaced horizontal rules
                siunitx}                % for numeric tables

\begin{document}
    \begin{table}[htp]
    \centering
\begin{tblr}{colsep = 10pt, 
             colspec= {@{} ll  *{3}{Q[c, si={table-format=2.1(2)}]} @{}},
             row{1} = {guard, b},
             rowsep = 3pt
            }
    \toprule
    &   Filtro(s)
        &   {$q = 0.62$ \\ (Bitner et al.~2007)} 
            &   {$q = 0.68$ \\ (Hill et al.~2017)} 
                &   Bootstrapping                           \\
    \midrule
\SetCell[c=4]{font=\itshape}  Conjunto de datos original
    &   &   &   &   &                                       \\
    & I         & 43.2(4.2:4.7) & 44.6(4.0:4.8)   & 47.0(1.5:1.5) \\
    & R         & 41.9(3.4:3.6) & 43.1(3.6:4.4)   & 45.6(1.3:1.3) \\
    & V         & 47.0(6.3:6.3) & 48.8(7.1:7.5)   & 44.8(2.0:2.4) \\
    & I, R, V   & 41.7(3.8:4.1) & 43.0(4.5:4.4)   &   {{{--}}}    \\
    \addlinespace
\SetCell[c=4]{font=\itshape}  Conjunto de datos reducido
    &   &   &   &   &                                  \\
    & I         & 44.0(1.3:1.4) & 41.0(3.4:3.5) &  42.2(3.6:4.4)     \\
    & R         & 43.0(1.3:1.4) & 45.3(4.8:4.1) &  46.5(5.5:4.9)     \\
    & V         & 42.6(4.9:5.8) & 44.0(5.3:5.3) &  40.3(2.7:2.5)     \\
    & I, R, V   & 45.5(4.9:4.9) & 46.8(5.6:5.2) &  {{{--}}}        \\
    \bottomrule
\end{tblr}

\caption{Resumen de los valores de i destacados, obtenidos mediante diferentes métodos.}
\label{resultados_finales}
    \end{table}
\end{document}

enter image description here

1
  • I tried to use that package before asking here because it's supposed to deal with automatic column widths but I had no success... thanks for the example!
    – Peybol
    Commented 2 days ago

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .