拆分包含很多列的异构长表

拆分包含很多列的异构长表

我有一张包含大量列的表格。我试图将其拆分以使其可见。问题是有些“单元格”包含非常长的数据,有些则非常短,但每列的宽度由第一行固定。例如,第一行数据几乎不包含在页面中,而其他行则大部分由空白空间组成。我该如何修复它(并使表格更具可读性)?第二、第三等数据行是否可以包含更多列和第一列?

是否可以在不使用“\hlines”的情况下对表格进行编码并让 LaTeX 自动在新行上分割?


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

答案1

下面是一个建议。我尝试了一种没有水平线的解决方案,但我会坚持使用水平线。

我仍然认为最好拆分表格并为每个组应用更好的数字/文本格式。我希望代码能为您提供更多关于进一步格式化选项的想法。

一个注释。你可能已经看到,代码相当复杂。你可能需要熟悉tabularray。文档可能看起来有点让人不知所措,但这是因为该软件包提供了很多选项,可以用最少的努力来定制表格。

在此处输入图片描述

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

答案2

一些建议:

  • 拆分表格。即使它们是相关的并且都在同一个标​​题下,也没有理由将四个表格混合在一起,这只会让您的生活更加困难。

  • 要想拥有美观的表格,就要使用booktabs包装的规则,并且注意,有时空间比规则更好。

  • 设置列宽有几种方法,从仅使用固定宽度的列(例如p{3cm})而不是lrc列(这些列还允许多行单元格),到使用 等包tabularx来设置表格的宽度(或等tabulary包中的最大宽度),这些宽度在列中均匀分布X(或者根据内容在 L、C、R;J 列中不均匀分布,因此等包中内容较多的列往往更宽tabulary),并且可以与 和标准列(lrc其宽度始终取决于单行的内容)以及标准列相结合。示例显示仅结合和列p的用法。您可以自己试验一下、和其他列(有关更多信息,请调用、等)。tabularxXltabularyptexdoc arraytexdoc tabularx


姆韦


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

相关内容