如何使該表可分頁?

如何使該表可分頁?

我目前的桌子已經變大了一些,不再適合其預定的空間。由於我預計該表將來會繼續增長,因此我需要使其可分頁,同時保持其當前的樣式。有很多關於如何獲取可分頁表的帖子,但我無法使用我找到的任何解決方案,因為我要么遇到了無法解決的錯誤,要么最終輸出看起來不好看如預期。

我在下面分享了一個 MWE,它顯示了我當前的(不可破壞的)表以及它生成的輸出的螢幕截圖。 MWE 所做的是建立一個清單環境,然後我可以在需要時呼叫環境。我的目標是複製此輸出,但確保表在到達分頁符號時正確中斷(而不是跳轉)

\documentclass[a4paper]{article}

\begin{document}

\newenvironment{entrylist}{%
  \noindent
  \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}rl}
}{%
  \end{tabular*}
}
\newcommand{\entry}[4]{%
    \parbox[t]{1.75cm}{#1\raggedleft}&\parbox[t]{\dimexpr\textwidth-2\tabcolsep-1.75cm}{\strut%
    \textbf{#2}%
    \hfill%
    {\footnotesize #3\par\strut}%
    #4\vspace{\parsep}%
  }\\}

\begin{entrylist}

  \entry
    {XXXX}
    {Fancy stuff 1}
    {Fancy stuff 1}
    {Fancy stuff 1}

  \entry
    {YYYY}
    {Fancy stuff 2}
    {Fancy stuff 2}
    {Fancy stuff 2}

  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {Fancy stuff 3}
    
\end{entrylist}

\end{document}

在此輸入影像描述

非常感謝大家抽出寶貴的時間。

答案1

您無需將所有內容封裝到表格環境中。您可以\entry透過巨集定義每個格式。當然,\smallskip後面的內容是可以分頁的。\hbox

\newdimen\colsep \colsep=1em
\def\topbox#1#2{\vtop{\parindent=0pt \hsize=\dimexpr#1\relax #2}}
\def\entry#1#2#3#4{\par
   \hbox{\topbox{1.75cm}{#1\raggedleft}\kern\colsep
         \topbox{\hsize-2\colsep-1.75cm}{{\bf#2}\hfill {\footnotesize#3}\endgraf#4\strut}}
   \smallskip
}

  \entry
    {XXXX}
    {Fancy stuff 1}
    {Fancy stuff 1}
    {Fancy stuff 1}

  \entry
    {YYYY}
    {Fancy stuff 2}
    {Fancy stuff 2}
    {Fancy stuff 2}

  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {Fancy stuff 3}

答案2

我想你需要做的就是

  • 載入longtable套件並發出說明\setlength\LTleft{0pt},並\setlength\LTright{0pt}在序言中

  • 取代環境定義中的\begin{tabular*}{\textwidth}with\begin{longtable}\end{tabular*}with 。\end{longtable}entrylist

或者,您可以\noindent在環境定義開始時刪除該指令entrylist

longtable有關長度參數\LTleft\LTright作用的更多信息,請參閱用戶指南的第 5 節,標題為“調整” 。

答案3

使用longtable

\documentclass[a4paper]{article}
\usepackage{longtable,array}

\usepackage{lipsum} % for nonsense text
\usepackage{showframe} % for showing the page boundaries

\newlength{\entrylistwidth}
\setlength{\entrylistwidth}{1.75cm}
\newenvironment{entrylist}{%
  \begin{longtable}{
    @{}
    w{l}{\entrylistwidth}
    p{\dimexpr\textwidth-2\tabcolsep-\entrylistwidth}
    @{}
  }
}{\end{longtable}}

\newcommand{\entry}[4]{%
  #1 & \textbf{#2}\hfill{\footnotesize #3\par}#4\\\noalign{\vspace{\parsep}}%
}

\begin{document}

\begin{entrylist}

  \entry
    {XXXX}
    {Fancy stuff 1}
    {Fancy stuff 1}
    {\lipsum[1][1-3]}

  \entry
    {YYYY}
    {Fancy stuff 2}
    {Fancy stuff 2}
    {\lipsum[2][1-3]}

  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
\end{entrylist}

\end{document}

在此輸入影像描述

相關內容