使 longtable 自动适合页面(行宽)

使 longtable 自动适合页面(行宽)

我有一个横向模式的长表,当行数太多时会自动拆分到多个页面上。

我已经解决了长度问题。现在我遇到了宽度问题,行超出了页面的右侧。

我想知道是否有一些自动的可以应用调整,使表格适合页面的 \linewidth。我想不是必须手动设置列宽,而是在单元格内适当的位置设置编译断线。其他 问题不要考虑“自动”部分,或者不要使用 longtable。

并非所有列都需要相同的宽度(包含较少单词的列应该较小)。

如果您允许我提及,在 Word 中,我会使用设置“最佳列大小”?很抱歉提及该程序 :)

更新)看起来像表格 会完全按照我需要的方式运作, 我发现一个答案关于如何将其与 longtable 结合以使其跨越多页,但我还有最后一个问题,标题不太合适。有什么想法可以解决这个问题吗?

表格标题不合适

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{longtable,tabulary}
\usepackage{pdflscape}

\makeatletter

%commands for multipage
\def\ltabulary{%
\def\endfirsthead{\\\hline}%
\def\endhead{\\\hline}%
\def\endfoot{\\\hline}%
\def\endlastfoot{\\\hline}%
\def\tabulary{%
  \def\TY@final{%
\def\endfirsthead{\LT@end@hd@ft\LT@firsthead}%
\def\endhead{\LT@end@hd@ft\LT@head}%
\def\endfoot{\LT@end@hd@ft\LT@foot}%
\def\endlastfoot{\LT@end@hd@ft\LT@lastfoot}%
\longtable}%
  \let\endTY@final\endlongtable
  \TY@tabular}%
\dimen@\columnwidth
\advance\dimen@-\LTleft
\advance\dimen@-\LTright
\tabulary\dimen@}

\def\endltabulary{\endtabulary}

\makeatother

\begin{document}

\section{Notes on papers}

\begin{landscape}
    \subsection{Thematics}

    \begin{ltabulary}{L|L|L|L|L|L|L|L}
    Work & System & Spatial & Topologies & Dependencies & Attack & Methodologies & Notes \\ \hline
    \endhead % all the rows above this will be repeated on every page

    [8] & 2Int & No & RR, ER, SF & 1to1 (bidir) & random (1-p) & perc, gen fun, sim & introduced cascading fails concept \\ \hline
    [39] & 2Int & no & ER, SF & Dependencies & random (1-p) & perc, gen fun, sim & critical coupling \\ \hline
    [1] & single, 2Int & Yes & various & 1to1, none & random, targeted & perc, other? & review \\ \hline
    [37] & 2Int & no & ER, SF & 1to1? with pref & random & sim, analysis & inter-similarity measure \\ \hline

    [38] & ??? & ER, SF & conn, dep & Attacks & perc & Notes \\ \hline
    [7] & 2Int & no & RR, ER, SF & 1to1 (bidir) & random (1-p) & perc & same degrees connected \\ \hline
    [35] & single & no & ER & competitive & none & perc & different view \\ \hline
    [31] & single & yes & LB, ER & none & none & perc & Notes \\ \hline
    [46] & 2Int & no & ER, SF & sup, dep, multiple (unidir) & random (multiple) & perc, num sim & different links, unidir \\ \hline
    [2] & single & no & ER & con, dep & random (1-p) & perc, sim & single net with dep links \\ \hline

    [?] & single, 2Int & no & ER, SF & 1to1 (bidir) & targeted (1-p) & perc, gen fun & maps targeted attack to random \\ \hline
    [?] & single & no & ER, SF, Re & none & targeted (q) & perc, sim & risk mitigation, new robustness measure \\ \hline
    [?] & NON & no & TofER, SLofER, LLofER & full dep, partial dep & ??? & perc & Notes \\ \hline
    \end{ltabulary}
\end{landscape}

\end{document}

答案1

(无需了解单元格内容),您可以使用ltablex包并将长表转换为 breakable tabularx。这里可以使用X更宽的列类型。

\documentclass[]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pdflscape}
\usepackage{tabularx}
\usepackage{ltablex} % uncommenting this line will work
\keepXColumns

\title{MyTitle}
\author{Me}

\begin{document}

    \maketitle

    \section{First}
    %some words here

    \begin{landscape} %landscape mode
        \begin{tabularx}{1.5\textheight}{l|l|l|X|X}
            head1 & head2 & head3 & head4 & head5 \\
            \hline
            \endhead % all the rows above this will be repeated on every page

            %col5 goes out of the page (the real text is much longer)
            foo & foo & foo bar & foo bar foo bar foo bar & foo bar foo bar foo bar foo bar foo bar \\ \hline
            foo & foo bar foo & foo bar foo bar foo bar foo & foo bar & foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar \\ \hline
            foo & foo & foo bar foo bar foo bar foo & foo bar foo bar foo bar foo bar foo bar foo bar foo bar &  foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar \\ \hline

            %some more rows here

        \end{tabularx}
    \end{landscape}
\end{document}

在此处输入图片描述

相关内容