0

I have a table with a big number of columns. I'm trying to split it in order to make it visible. The problem is some "cell" contains very long data and some very short, but the width of every column is fixed by the first row. For example, the first data rows are barely contained in the page, and the others are made mostly of empty space. How can I fix it (and make the table more readable)? Can the second, third etc. bunch of data rows contain more columns and the first one?

Is it possible to code the table without `\hlines´ and make LaTeX automatically split on new lines automatically?


\documentclass[12pt]{article}
\setlength{\textwidth}{200mm}
\setlength{\textheight}{245mm}
\setlength{\topmargin}{-15mm}
\setlength{\oddsidemargin}{-20mm}
\setlength{\evensidemargin}{-20mm}
\setlength{\unitlength}{1mm}
\begin{document}

\begin{table}[htb]
\begin{center}
\begin{tabular}{llllllllll}
ShortID & DiscoveryName & Reference & $SPT_{OPT}$ & $SPT_{NIR}$ \\
J0000-0001 & Ref CAT3 1234567891234567890 & ................... & ... & ... \\
J0000-0002 & Ref CAT3 1234567891234567891 & ................... & ... & ... \\
J0000-0003 & Ref CAT3 1234567891234567892 & ................... & ... & ... \\
\hline
Parallax & ParallaxName & PMRA & PMDEC & TMASSJ\\
10.00 $\pm$ 0.01 & xxxxx\&A...xxxx...xx & -100.00 $\pm$ 0.01 & -50 $\pm$ 0.01 & 10.00 $\pm$ 0.02 \\
10.00 $\pm$ 0.01 & xxxxx\&A...xxxx...xx & -100.00 $\pm$ 0.01 & -100 $\pm$ 0.01 & nan $\pm$ nan \\
10.00 $\pm$ 0.01 & xxxxx\&A...xxxx...xx & -100.00 $\pm$ 0.01 & -50 $\pm$ 0.01 & 10.00 $\pm$ 0.01 \\
\hline
$Magr_{G}$ & $Magr_{BP}$ & $Magr_{RP}$ & RA & DEC\\
10.00 $\pm$ 0.0 & 10.00 $\pm$ 0.0 & 10.00 $\pm$ 0.0 & 0.00000001 & -10.00000000 \\
10.00 $\pm$ 0.0 & 10.00 $\pm$ 0.01 & 10.00 $\pm$ 0.01 & 0.00000001 & -10.00000000 \\
10.00 $\pm$ 0.0 & 10.00 $\pm$ 0.1 & 10.00 $\pm$ 0.01 & 0.00000001 & -10.00000000 \\
\hline
Alternate\_ID & $SPT_{GEN}$ & $J_{GEN}$ & $V_{TAN}$ & SeparationAU\\
1234567891234567890 & -50.0 & 10.00 & 10.00 $\pm$ 0.01 & 0 \\
1234567891234567891 & -50.0 & nan & 10.00 $\pm$ 0.01 & 0 \\
1234567891234567892 & -50.0 & 10.00 & 10.00 $\pm$ 0.01 & 300 \\
\end{tabular}
\end{center}
\end{table}

\end{document}
10
  • 3
    Welcome to TSE. Please post a Minimal Working Example, instead of a code snippet. Jul 8, 2022 at 9:14
  • Thank you @JoséCarlosSantos , I'm sorry, I'm new to LaTeX! I've added the MWE, I hope it's ok now! Jul 8, 2022 at 10:10
  • 1
    Hello. I'd have one suggestion. It seems there are 4 headers in this table and as such 4 different groups of information. Consequently, the same columns contain different type of data. I think separating different groups of data would ease formatting per each table.
    – Celdor
    Jul 8, 2022 at 11:41
  • 1
    @AiyaEarendil, you actually not have LaTeX problem, but decision what to have in table. This is very opinion based and dependent on context of your article (report/book). In this we cant help you.
    – Zarko
    Jul 8, 2022 at 12:15
  • 1
    I'm not sure the OP is asking what the best table layout would be (which is opinion-based), but rather how to automatically start a new table 'part' when needed with a potentially different number of columns or something like that. This doesn't seem like a good or doable idea but it is not really asking for opinions.
    – Marijn
    Jul 9, 2022 at 11:06

2 Answers 2

0

One suggestion is below. I tried a solution without horizontal rules and I'd stick with the rules.

I still think you would be better off splitting the table and apply a better number/text formatting per group. I hope the code will give more ideas about options for further formatting as you like.

One remark. You can probably see, the code is rather complex. You may want to get familiar with tabularray. The documentation might seem overwhelming a bit but this is because the package gives a lot of options to customise tables with minimum effort.

enter image description here

\documentclass[12pt]{article}
\usepackage{tabularx}   % X columnt-type, and extra options from array
\usepackage{booktabs}   % extra rules and spacing in tables
\usepackage{makecell}   % makecell for multiple lines in cells 
\usepackage{caption}    % adds caption formatting
    \captionsetup[table]{skip=6pt, position=top}
\usepackage{kantlipsum}

\usepackage[pass]{geometry}
% \setlength{\textwidth}{200mm}
% \setlength{\textheight}{245mm}
% \setlength{\topmargin}{-15mm}
% \setlength{\oddsidemargin}{-20mm}
% \setlength{\evensidemargin}{-20mm}
% \setlength{\unitlength}{1mm}

\NewDocumentCommand\HD{sm}{%
    % --- Text in bold
    % *  - add italic  (optional)
    % #2 - the main text
    {\bfseries\IfBooleanT{#1}{\itshape}#2}}
\NewDocumentCommand\SC{m e{_^}}{%
    % --- a shorter variant for sub- and super-scripts without turning to math mode 
    % #1 - the main text
    % ^  - superscript e.g. \SC{text}^{something} (optional)
    % _  - subscript e.g. \SC{text}_{something}  (optional)
    #1%
    \IfValueT{#2}{\textsubscript{#2}}%
    \IfValueT{#3}{\textsuperscript{#3}}}
\newcommand\noval{\multicolumn{1}{c}{---}}


\begin{document}
\kant[1]

\newgeometry{margin=1in}
\begin{table}
    \small
    \renewcommand{\arraystretch}{1.2}
    \centering
    \caption{\kant[1][1]}
    \begin{tabularx}{\textwidth}{X *{4}{r}}
        \toprule
        \HD{ShortID} &
            \multicolumn{1}{l}{\HD{DiscoveryName}} &
            \multicolumn{1}{c}{\HD{Reference}} &
            \multicolumn{1}{c}{\HD*{\SC{SPT}_{OPT}}} &
            \multicolumn{1}{c}{\HD*{\SC{NIR}_{SPT}}} \\
        \midrule[0.4pt]
        J0000-0001 & \makecell[lt]{Ref CAT3\\1234567891234567890} & \noval & \noval & \noval \\
        J0000-0002 & \makecell[lt]{Ref CAT3\\1234567891234567891} & \noval & \noval & \noval \\
        J0000-0003 & \makecell[lt]{Ref CAT3\\1234567891234567892} & \noval & \noval & \noval \\
        \addlinespace[12pt]
        \HD{Parallax} &
            \multicolumn{1}{l}{\HD{ParallaxName}} &
            \multicolumn{1}{c}{\HD{PMRA}} &
            \multicolumn{1}{c}{\HD{PMDEC}} &
            \multicolumn{1}{c}{\HD{TMASSJ}} \\
        \midrule[0.4pt]
        10.00 $\pm$ 0.01 & \makecell[lt]{xxxxx \&\\ A...xxxx...xx} & -100.00 $\pm$ 0.01 &  -50 $\pm$ 0.01 & 10.00 $\pm$ 0.02 \\
        10.00 $\pm$ 0.01 & \makecell[lt]{xxxxx \&\\ A...xxxx...xx} & -100.00 $\pm$ 0.01 & -100 $\pm$ 0.01 &   nan $\pm$ nan  \\
        10.00 $\pm$ 0.01 & \makecell[lt]{xxxxx \&\\ A...xxxx...xx} & -100.00 $\pm$ 0.01 &  -50 $\pm$ 0.01 & 10.00 $\pm$ 0.01 \\
        \addlinespace[12pt]
        \HD*{\SC{Magr}_{G}} &
            \multicolumn{1}{c}{\HD*{\SC{Magr}_{BP}}} &
            \multicolumn{1}{c}{\HD*{\SC{Magr}_{RP}}} &
            \multicolumn{1}{c}{\HD{RA}} &
            \multicolumn{1}{c}{\HD{DEC}} \\
        \midrule[0.4pt]
        10.00 $\pm$ 0.0 & 10.00 $\pm$ 0.0  & 10.00 $\pm$ 0.0  & 0.00000001 & -10.00000000 \\
        10.00 $\pm$ 0.0 & 10.00 $\pm$ 0.01 & 10.00 $\pm$ 0.01 & 0.00000001 & -10.00000000 \\
        10.00 $\pm$ 0.0 & 10.00 $\pm$ 0.1  & 10.00 $\pm$ 0.01 & 0.00000001 & -10.00000000 \\
        \addlinespace[12pt]
        \HD{AlternateID} &
            \multicolumn{1}{c}{\HD*{\SC{SPT}_{GEN}}} &
            \multicolumn{1}{c}{\HD*{\SC{J}_{GEN}}} &
            \multicolumn{1}{c}{\HD*{\SC{V}_{TAN}}} &
            \multicolumn{1}{c}{\HD{\SC{Separation}_{AU}}} \\
        \midrule[0.4pt]
        123456781234567890 & -50.0 & 10.00 & 10.00 $\pm$ 0.01 & 0   \\
        123456781234567891 & -50.0 &   nan & 10.00 $\pm$ 0.01 & 0   \\
        123456781234567892 & -50.0 & 10.00 & 10.00 $\pm$ 0.01 & 300 \\
        \bottomrule
    \end{tabularx}
\end{table}
\restoregeometry

\kant[2]
\end{document}
0

Some advices:

  • Split the table. Even if they are related and all are under the same caption, there is no reason to mix four tables in one except make your live harder.

  • To have elegant tables, use rules of the booktabs package, and note that sometimes is better a space that a rule.

  • For set column widths are several methods, from just use columns of fixed width (e.g. p{3cm}) instead of l,r,c columns, that moreover allow multiline cells, to use packages as tabularx that set a width of the table (or a maximal width in tabulary package) that is equally distributed in X columns (or are unequally distributed in L, C, R; J columns according to the contents, so columns with more contents tend to be wider, in tabulary package) and can be combined with and standard columns (l,r,c that will have always the width dependent of the content of a single line), and with the also standard p columns. The example show the use of tabularx combining just X and l columns. Experiment yourself with columns of tabulary, p and others (for more information, invoke texdoc array,texdoc tabularx, etc.).


mwe


\documentclass[12pt]{article}
\usepackage[margin=2cm]{geometry} % decent margins
\usepackage{lipsum} % dummy text
\usepackage{booktabs} % more elegant rules
\usepackage{tabularx} % intelligent (equal) column width
\begin{document}

\lipsum[1][1-7]

\lipsum[2][1-7]

\begin{table}[htb]
\belowcaptionskip10pt
\caption{\lipsum[5][1-5]}\begin{center}

\begin{tabularx}{\linewidth}{@{}XlXXX@{}}
\toprule
ShortID & DiscoveryName & Reference & $SPT_{OPT}$ & $SPT_{NIR}$ \\
\midrule
J0000-0001 & Ref CAT3 1234567891234567890 & ................... & ... & ... \\
J0000-0002 & Ref CAT3 1234567891234567891 & ................... & ... & ... \\
J0000-0003 & Ref CAT3 1234567891234567892 & ................... & ... & ... \\
%\bottomrule
\end{tabularx}
\par\bigskip
\begin{tabularx}{\linewidth}{@{}XlXlX@{}}
%\toprule
Parallax & ParallaxName & PMRA & PMDEC & TMASSJ\\
\midrule
10.00 $\pm$ 0.01 & xxxxx\&A...xxxx...xx & -100.00 $\pm$ 0.01 & -50 $\pm$ 0.01 & 10.00 $\pm$ 0.02 \\
10.00 $\pm$ 0.01 & xxxxx\&A...xxxx...xx & -100.00 $\pm$ 0.01 & -100 $\pm$ 0.01 & nan $\pm$ nan \\
10.00 $\pm$ 0.01 & xxxxx\&A...xxxx...xx & -100.00 $\pm$ 0.01 & -50 $\pm$ 0.01 & 10.00 $\pm$ 0.01 \\
%\bottomrule
\end{tabularx}
\par\bigskip\tabcolsep23pt 

\begin{tabularx}{\linewidth}{@{}XXXXl@{}}
%\toprule
$Magr_{G}$ & $Magr_{BP}$ & $Magr_{RP}$ & RA & DEC\\
\midrule
10.00 $\pm$ 0.0 & 10.00 $\pm$ 0.0 & 10.00 $\pm$ 0.0 & 0.00000001 & -10.00000000 \\
10.00 $\pm$ 0.0 & 10.00 $\pm$ 0.01 & 10.00 $\pm$ 0.01 & 0.00000001 & -10.00000000 \\
10.00 $\pm$ 0.0 & 10.00 $\pm$ 0.1 & 10.00 $\pm$ 0.01 & 0.00000001 & -10.00000000 \\
%\bottomrule
\end{tabularx}
\par\bigskip\tabcolsep22pt 
\begin{tabularx}{\linewidth}{@{}lXlll@{}}
%\toprule
Alternate\_ID & $SPT_{GEN}$ & $J_{GEN}$ & $V_{TAN}$ & SeparationAU\\
\midrule
1234567891234567890 & -50.0 & 10.00 & 10.00 $\pm$ 0.01 & 0 \\
1234567891234567891 & -50.0 & nan & 10.00 $\pm$ 0.01 & 0 \\
1234567891234567892 & -50.0 & 10.00 & 10.00 $\pm$ 0.01 & 300 \\\\\bottomrule
\end{tabularx}
\end{center}
\end{table}


\lipsum[3][1-73]

\lipsum[4][1-73]

\end{document}

You must log in to answer this question.

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