我的桌子不適合;我有什麼選擇?

我的桌子不適合;我有什麼選擇?

我有一個表格想要插入到頁面上,但至少滿足以下條件之一(也許兩個):

  1. 桌子也太寬的以適應文字區塊或頁面。也就是說,我超過了一些水平的限制。

  2. 桌子也太高的以適應文字區塊或頁面。也就是說,我超過了一些垂直的限制。

我有哪些選擇可以讓這張桌子適合?如果它不適合,無論我如何嘗試,還有哪些其他選擇?

答案1

讓我們先確定當我們使用術語“表”時所指的是什麼。典型的table環境是漂浮,並且可以包含任何內容:一段文字、一張圖像,甚至一個tabular.tabular 這裡討論的是如何使用後者 - a - 以及如何調整它。該討論也適用於array結構,因為它們提供了數學模擬tabular

考慮閱讀如何影響 LaTeX 中圖形和表格等浮動環境的位置?如果你有興趣漂浮-具體展示位置。

其次,了解 atabular是靜態的二維結構。因此,它可能最適合表示二維(例如年齡X性別, 或者地區X類型)。因此,如果不「仔細」呈現,表示二維以上的任何事物本質上可能會出現問題,因為要製表的元素數量會擴展幾何地。如果您透過(例如)呈現(例如)三個維度的信息年齡,性別種族而該表不適合,或許可以考慮將這個表分成一個tabularby年齡性別對於每個種族。請記住,表格應該擴展或簡化資訊的消化,因此,如果其表示形式看起來複雜、密集或令人困惑,那麼分成更基本的組件可能是您的最佳選擇。


1. 我的桌子/tabular太寬了。我該怎麼做才能使它變得合適?

以下是可以考慮的選項(排名不分先後):

  • 如果您要呈現的資料具有大(寬)列標題,請考慮堆疊或者縮寫這些可以折疊太寬的列:

    \documentclass{article}
    \usepackage{makecell}
    \begin{document}

    \begin{table}
      \centering

      \begin{tabular}{ *{12}{c} }
        This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide. \\
        \hline
        1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12
      \end{tabular}

      \medskip

      % Condense column headers using abbreviations or acronyms
      \begin{tabular}{ *{12}{c} }
        This&is&a&\texttt{tbl}&with&twelve&cols&that&is&just&too&wide. \\
        \hline
        1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\[.5\normalbaselineskip]
        \multicolumn{12}{l}{%
          \footnotesize \texttt{tbl}: \texttt{tabular} title; cols: column title}
      \end{tabular}

      \bigskip

      \begin{tabular}{ *{3}{c} }
        This is a \texttt{tabular} with&three columns that is just&too wide to fit in \texttt{\string\textwidth}. \\
        \hline
        1  2  3  4 & 5  6  7  8 & 9  10  11  12
      \end{tabular}

      \medskip

      % Condense column headers via stacking
      \begin{tabular}{ *{3}{c} }
              This is           &                    &           too wide             \\ 
        a \texttt{tabular} with & three columns that &            to fit              \\
                                &      is just       & in \texttt{\string\textwidth}. \\
        \hline
        1  2  3  4 & 5  6  7  8 & 9  10  11  12
      \end{tabular}

      \medskip

      % Condense column headers via stacking
      \begin{tabular}{ *{3}{c} }
        \makecell[b]{This is \\ a \texttt{tabular} with} & 
        \makecell[t]{three columns that \\ is just} & 
        \makecell{too wide \\ to fit \\ in \texttt{\string\textwidth}.} \\
        \hline
        1  2  3  4 & 5  6  7  8 & 9  10  11  12
      \end{tabular}

      \medskip

      % Condense column headers via stacking in a paragraph-style column
      \begin{tabular}{ *{3}{c} }
        \multicolumn{1}{p{60pt}}{\centering This is a \texttt{tabular} with} & 
        \multicolumn{1}{p{7em}}{\raggedleft three columns that is just} & 
        \multicolumn{1}{p{3cm}}{\raggedright too wide to fit in \texttt{\string\textwidth}.} \\
        \hline
        1  2  3  4 & 5  6  7  8 & 9  10  11  12
      \end{tabular}

      \caption{This is a table caption.}
    \end{table}

    \end{document}

手動堆疊可能很乏味。將列標題設為固定寬度p{<len>}列是提供自動換行方式的一種方法(也如上所示)。

  • p當使用段落樣式的列規範時,允許列條目自然換行是可能的。此p{<len>}樣式的列換行於<len>。如果你不知道<len>應該怎樣,tabularx可以透過其靈活的X-column 提供幫助:

    \documentclass{article}
    \usepackage{tabularx}
    \begin{document}

    \begin{table}
      \centering

      \begin{tabular}{ *{3}{c} }
        This is a \texttt{tabular} with&three columns that is just&too wide to fit in \texttt{\string\textwidth}. \\
        \hline
        1  2  3  4 & 5  6  7  8 & 9  10  11  12
      \end{tabular}

      \medskip

      % tabularx provides a fixed-width table with flexible columns
      \begin{tabularx}{\textwidth}{ c X >{\raggedright\arraybackslash}X }
        This is a \texttt{tabular} with&three columns that is just&too wide to fit in \texttt{\string\textwidth}. \\
        \hline
        1  2  3  4 & 5  6  7  8 & 9  10  11  12
      \end{tabularx}

      \caption{This is a table caption.}
    \end{table}

    \end{document}

- 列中合理的換行X可能會導致過度\hbox警告,這可以透過使用設定來避免\raggedright。由於tabularx負載array>{<prefix>}可以新增列前綴。

tabulary提供了類似的介面,在這方面也可能有所幫助。

  • 標頭迴轉還可以提供一些水平減少:

    \documentclass{article}
    \usepackage{graphicx}
    \newcommand{\hd}{\rotatebox{60}}
    \begin{document}

    \begin{table}
      \centering

      \begin{tabular}{ *{12}{c} }
        This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide. \\
        \hline
        1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12
      \end{tabular}

      \bigskip

      % Condense column headers using rotation
      \begin{tabular}{ *{12}{c} }
        \hd{This}&\hd{is}&\hd{a}&\hd{\texttt{tabular}}&\hd{with}&\hd{twelve}&
          \hd{columns}&\hd{that}&\hd{is}&\hd{just}&\hd{too}&\hd{wide.} \\
        \hline
        1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12
      \end{tabular}

      \caption{This is a table caption.}
    \end{table}

    \end{document}

旋轉格式在視覺上相當極端,應謹慎使用。

  • 嘗試水平配合的最佳方法可能是打破tabular較小的寬度配合tabulars。它是視覺上侵入性最小的(一般而言),並且可能會傳達訊息以便讀者更好地消化:

    \documentclass{article}
    \begin{document}
    
    \begin{table}
      \centering
    
      \begin{tabular}{ *{12}{c} }
        1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
        \hline
        This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
      \end{tabular}
    
      \bigskip
    
      \begin{tabular}{ *{6}{c} }
        1 & 2 & 3 & 4 & 5 & 6 \\
        \hline
        This & is & a & \texttt{tabular} & with & twelve \\
        \\
        7 & 8 & 9 & 10 & 11 & 12 \\
        \hline
        columns & that & is & just & too & wide.
      \end{tabular}
    
      \bigskip
    
      \begin{tabular}{ *{6}{c} }
        1 & 2 & 3 & 4 & 5 & 6 \\
        \hline
        This & is & a & \texttt{tabular} & with & twelve
      \end{tabular}
      
      \medskip
      
      \begin{tabular}{ *{6}{c} }
        7 & 8 & 9 & 10 & 11 & 12 \\
        \hline
        columns & that & is & just & too & wide.
      \end{tabular}
    
      \caption{This is a table caption.}
    \end{table}
    
    \end{document}
  • 考慮刪除水平內容以使其適合您需求的寬度。您可以手動刪除內容,儘管這對於大型tabular檔案來說可能很乏味。但是,如果您不想刪除內容但仍刪除列,請閱讀刪除列的最簡單方法?

    \documentclass{article}

    % https://tex.stackexchange.com/a/16607/5764
    \usepackage{array}
    \newcolumntype{H}{>{\setbox0=\hbox\bgroup}c<{\egroup}@{}}

    \begin{document}

    \begin{table}
      \centering

      \begin{tabular}{ *{12}{c} }
        1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
        \hline
        This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
      \end{tabular}

      \bigskip

      % Drop/Hide column 10
      \begin{tabular}{ *{9}{c} H *{2}{c} }
        1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
        \hline
        This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
      \end{tabular}

      \caption{This is a table caption.}
    \end{table}

    \end{document}
  • 考慮減少列之間的水平間距。預設文檔類別定義\tabcolsep6pt.對於arrays,使用的長度\arraycolsep預設為5pt。這可能超出您的需求。對於多列tabular,減少\tabcolsep可以為您節省寶貴的積分。

    \documentclass{article}
    \begin{document}

    \begin{table}
      \centering

      \begin{tabular}{ *{12}{c} }
        1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
        \hline
        This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
      \end{tabular}

      \bigskip

      \begingroup
      \setlength{\tabcolsep}{0.75\tabcolsep}% Reduce \tabcolsep by 25%
      \begin{tabular}{ *{12}{c} }
        1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
        \hline
        This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
      \end{tabular}
      \endgroup

      \caption{This is a table caption.}
    \end{table}

    \end{document}

可能需要將變更的範圍限制為\tabcolsep,因此使用分組調整\setlength(透過\begingroup...\endgroup{... })。

  • 考慮減小tabular.如果\normalsize您的文件使用預設值,也許\small\footnotesize可能使其適合:

    \documentclass{article}
    \begin{document}

    \begin{table}
      \centering

      % This tabular is too wide
      \begin{tabular}{ *{12}{c} }
        1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
        \hline
        This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
      \end{tabular}

      \bigskip

      \begingroup
      \footnotesize% Change to smaller font from \normalsize
      \begin{tabular}{ *{12}{c} }
        1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
        \hline
        This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
      \end{tabular}
      \endgroup

      \caption{This is a table caption.}
    \end{table}

    \end{document}

LaTeX 文件的預設字體大小是多少?\Large 等字體大小是多少磅(pt)?有關字體和字體大小的討論。

可能需要限製字體變更的範圍,因此使用分組(透過\begingroup...\endgroup{... })。

  • 對於太寬的tabulars,您可以調整整個表格的大小以適合您的範圍水平地使用\resizebox{<width>}{<height>}{<tabular>}where <width>is atmost \linewidthor \textwidth(參見\textwidth、\linewidth 和 \hsize 之間的區別)。!的符號<height>將確保保持調整大小的縱橫比。

    \documentclass{article}
    \usepackage{graphicx}
    \begin{document}

    \begin{table}
      \centering

      \begin{tabular}{ *{12}{c} }
        1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
        \hline
        This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
      \end{tabular}

      \bigskip

      % \resizebox{<width>}{<height>}{<tabular>}
      \resizebox{\linewidth}{!}{%
        \begin{tabular}{ *{12}{c} }
          1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
          \hline
          This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
        \end{tabular}}

      \caption{This is a table caption.}
    \end{table}

    \end{document}

縮小tabular規模全部內容...包括文字。如果收縮係數足夠小,文件中使用的字體和縮放後的字體之間可能不會有明顯的差異tabular

  • 也許你已經承認tabular 因為上述任何更改都不足以滿足您的需求。但是,預設\centering不會tabular以居中的方式設定 ,因此您可以將tabular內部 a設定\makebox[<width>]得足夠小<width>(小於\linewidth),這將自動將其在邊距跨度內居中(請參閱如何讓太寬的桌子居中?):

    \documentclass{article}
    \begin{document}

    \begin{table}
      \centering

      \begin{tabular}{ *{12}{c} }
        1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
        \hline
        This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
      \end{tabular}

      \bigskip

      % This tabular is still too wide, but we'll keep it as-is...
      \makebox[\textwidth]{%
        \begin{tabular}{ *{12}{c} }
          1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
          \hline
          This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
        \end{tabular}}

      \caption{This is a table caption.}
    \end{table}

    \end{document}
  • 您可以將桌子旋轉 90 度(順時針或逆時針),並將其側放。通常頁面的高度大於寬度,這可能會更tabular合適。然而,這將是一個極端的調整,因為您要求觀眾調整他們的觀點,而有些人可能不喜歡水平(從左到右)和垂直(從下到上)設定之間的這種切換:

    \documentclass{article}        
    \usepackage{graphicx}
    \begin{document}
    
    \begin{table}
      \centering
    
      \begin{tabular}{ *{12}{c} }
        1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
        \hline
        This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
      \end{tabular}
    
      \bigskip
      
      \rotatebox{90}{%
        \begin{tabular}{ *{12}{c} }
          1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
          \hline
          This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
        \end{tabular}}
    
      \caption{This is a table caption.}
    \end{table}
    
    \end{document}

graphicx's\rotatebox{<angle>}{<tabular>}用於旋轉<tabular>度數<angle>

上面的例子旋轉了tabular 僅有的,將標題保留在原來的位置。如果你想旋轉整個漂浮- 包含標題,您可以使用sidewaystable(由rotating包裹):

    \documentclass{article}        
    \usepackage{rotating}
    \begin{document}
    
    \begin{table}
      \centering
    
      \begin{tabular}{ *{12}{c} }
        1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
        \hline
        This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
      \end{tabular}
            
      \caption{This is a table caption.}
    \end{table}

    \begin{sidewaystable}
      \centering
    
      \begin{tabular}{ *{12}{c} }
        1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
        \hline
        This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
      \end{tabular}
            
      \caption{This is a table caption.}
    \end{sidewaystable}
    
    \end{document}

請注意,asidewaystable假設您的表格相當寬的因此將佔據大部分文字區塊高度旋轉期間。因此,預設行為是將其放置在自己的頁面上。


2. 我的桌子/tabular太高了。我該怎麼做才能使它變得合適?

上面列出的許多相同程序都可以應用垂直為了調整tabular佈局,例如更改字體、旋轉或手動將內容分成多個tabular;下面列出了一些建議。

  • \arraystretch用於拉伸(或收縮) 中的每一行tabular。也許你\documentclass增加了這個。您可以使用以下方法調整它\renewcommand

    \documentclass{article}
    \begin{document}

    \begin{table}

      \begin{minipage}{0.3333\linewidth}
        \centering
        \renewcommand{\arraystretch}{1.2}    

        \begin{tabular}{ c c }
          1&This \\ 
          \hline
          2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\
          7&rows \\ 8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
        \end{tabular}

      \end{minipage}%
      \begin{minipage}{0.3333\linewidth}
        \centering
        \renewcommand{\arraystretch}{1}
      
        \begin{tabular}{ c c }
          1&This \\ 
          \hline
          2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\
          7&rows \\ 8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
        \end{tabular}

      \end{minipage}%
      \begin{minipage}{0.3333\linewidth}
        \centering
        \renewcommand{\arraystretch}{0.8}
      
        \begin{tabular}{ c c }
          1&This \\ 
          \hline
          2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\
          7&rows \\ 8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
        \end{tabular}

      \end{minipage}

      \caption{This is a table caption.}
    \end{table}

    \end{document}
  • 考慮切掉行塊並水平堆疊它們,而不是保持內容垂直。

    \documentclass{article}
    \begin{document}

    \begin{table}
      \centering

      \begin{tabular}{ c c }
        1&This \\ 
        \hline
        2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\
        7&rows \\ 8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
      \end{tabular}

      \bigskip

      \begin{tabular}{ c c @{\hspace{2em}} c c }
        1&This & 1&This \\ 
        \hline
        2&is & 8&that \\
        3&a  & 9&is \\
        4&\texttt{tabular} & 10&just \\
        5&with & 11&too \\
        6&twelve & 12&tall. \\
        7&rows
      \end{tabular}

      \bigskip

      \begin{tabular}[t]{ c c }
        1&This \\ 
        \hline
        2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\ 7&rows
      \end{tabular}\hspace{2em}%
      \begin{tabular}[t]{ c c }
        1&This \\ 
        \hline
        8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
      \end{tabular}

      \caption{This is a table caption.}
    \end{table}

    \end{document}
  • 減少字體大小也會減少行高,從而減少 的垂直跨度tabular

    \documentclass{article}
    \begin{document}

    \begin{table}
      \centering

      \begin{tabular}{ c c }
        1&This \\ 
        \hline
        2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\
        7&rows \\ 8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
      \end{tabular}%
      \hspace{2em}%
      \begingroup
      \small% Change to smaller font size from \normalsize
      \begin{tabular}{ c c }
        1&This \\ 
        \hline
        2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\
        7&rows \\ 8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
      \end{tabular}%
      \endgroup

      \caption{This is a table caption.}
    \end{table}

    \end{document}

同樣,在這裡,可能需要範圍來限製字體更改。

  • graphicx\scalebox{<factor>}或是\resizebox{<width>}{<height>}一個選項。您可以指定適當的高度配合<height>長度或部分。 A <width>of!確保在調整大小期間保持縱橫比:

    \documentclass{article}
    \usepackage{graphicx}
    \begin{document}

    \begin{table}
      \centering

      \begin{tabular}{ c c }
        1&This \\ 
        \hline
        2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\
        7&rows \\ 8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
      \end{tabular}%
      \hspace{2em}%
      \resizebox{!}{.8\height}{%
        \begin{tabular}{ c c }
          1&This \\ 
          \hline
          2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\
          7&rows \\ 8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
        \end{tabular}}

      \caption{This is a table caption.}
    \end{table}

    \end{document}

以下範例直接取自文檔longtable,說明了環境元件的構造longtable,以便將表格分成多個頁面(帶有「續標題」):

    \documentclass{article}
    \usepackage{longtable}

    \def\v{\char`}

    \begin{document}

    % Note: Various parts of the following table will
    % *not* line up correctly until this document has been run
    % through LaTeX several times. This is a characteristic feature of
    % this package, as described below.

    \begin{longtable}{@{*}r||p{1in}@{*}}
        KILLED & LINE!!!! \kill
        \caption
          [An optional table caption (used in the list of tables)]
          {A long table\label{long}} \\
        \hline\hline
        \multicolumn{2}{@{*}c@{*}}%
          {This part appears at the top of the table} \\
        \textsc{First} & \textsc{Second} \\
        \hline\hline
      \endfirsthead
        \caption[]{(continued)} \\
        \hline\hline
        \multicolumn{2}{@{*}c@{*}}%
             {This part appears at the top of every other page} \\
        \textbf{First} & \textbf{Second} \\
        \hline\hline
      \endhead
        \hline
        This goes at the & bottom. \\
        \hline
      \endfoot
        \hline
        These lines will & appear \\
        in place of the  & usual foot \\
        at the end       & of the table \\
        \hline
      \endlastfoot
        \texttt{longtable} columns are specified & in the \\
        same way as  in the \texttt{tabular} & environment. \\
        ``\verb~@{*}r||p{1in}@{*}~'' & in this case. \\
        Each row ends with a & ``\verb|\\|'' command. \\
        The ``\verb|\\|'' command  has an & optional \\
        argument, just as in & the \\
        \texttt{tabular} & environment. \\[10pt]
        See the effect of ``\verb|\\[10pt]|'' & ? \\
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Also ``\verb|\hline|'' may be used, & as in \texttt{tabular}. \\
        \hline
        That was a ``\verb|\hline|'' & . \\
        \hline\hline
        That was ``\verb|\hline\hline|'' & . \\
        \multicolumn{2}{||c||}%
          {This is a \ttfamily\v\\multicolumn\v{2\v}\v{||c||\v}} \\
        If a page break occurs at a ``\verb|\hline|'' then & a line is drawn \\
        at the bottom of one page and at the & top of the next. \\
        \hline
        The ``\verb|[t] [b] [c]|'' argument of \texttt{tabular} & can not be used. \\
        The optional argument may be one of & ``\verb|[l] [r] [c]|'' \\
        to specify whether the table should be & adjusted \\
        to the left, right & or centrally. \\
        \hline\hline
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Some lines may take up a lot of space, like this: &
           \raggedleft This last column is a ``\texttt{p}'' column so this
           ``row'' of the table can take up several lines. Note however that
           \TeX\ will  never break a page within such a row. Page breaks only
           occur between rows of the table or at ``\verb|\hline|'' commands.
           \tabularnewline
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        Lots of lines & like this. \\
        \hline
        Lots\footnote{This is a footnote.} of lines & like this. \\
        Lots of lines & like this\footnote{\texttt{longtable} takes special
           precautions, so that footnotes may also be used in `\texttt{p}' columns.} \\
        \hline
        Lots of lines & like this. \\
        Lots of lines & like this.
    \end{longtable}

    \end{document}

3.我的tabular太寬了對於我放置它的位置來說太高了。我能做些什麼?

通常可以結合上述方法來改善寬度/高度。可能存在一些不相容的選擇(例如調整 的大小longtable)。

答案2

如果文件由縱向格式的頁面組成,並且如果採用橫向格式,則表格的寬度適合紙張,則可以考慮製作一個旋轉 90 度的長表格,跨越多個頁面。

(只有當該表僅用於無聊的查找(例如價目表或類似內容)時,人們才可能這樣做,在這種情況下,通過一次查看多條記錄來查看數據組之間的相關性並不重要。

現在你可以使用 zref 和最近在 LaTeX2e 核心中引入的鉤子系統:

  • 對於長表,暫時變更佈局,以便交換頁面寬度和頁面高度。

  • 在長表中,使用 zref 套件的工具在第一個和最後一個儲存格中設定標籤,以保存有關長表開頭和結尾的絕對頁碼的資訊。

  • \ShipoutBox如果絕對頁碼位於開頭的 zref 標籤表示的頁面範圍內,則使用新的鉤子系統將指令新增至每次出貨之前執行的鉤子中,以將頁面旋轉

\documentclass{article}
\usepackage{graphicx}
\usepackage[abspage]{zref}
\usepackage{longtable}
\usepackage{blindtext}

\makeatletter

% A scratch loop for repeating #3 while counting from #1 to #2.
% As counter is used \scratchmacro
% #3 is expanded until finding an unexpandable token.
% If the unexpandable token is a space token it is discarded.
\newcommand\scratchmacro{}
\newtoks\scratchtoks
\newcommand\PassFirstToSecond[2]{#2{#1}}
\newcommand\scratchtoksloop[3]{%
  \begingroup
  \def\scratchmacro{#1}%
  \scratchtoks{\endgroup}%
  \loop 
    \scratchtoks\expandafter{\the\expandafter\scratchtoks\romannumeral`\^^@#3}%
  \ifnum\scratchmacro < #2 %
    \edef\scratchmacro{\the\numexpr\scratchmacro+1\relax}%
  \repeat
  \the\scratchtoks
}%

% This checks if the current value of the abspage-counter is within the
% range given by zref-label #1 and zref-label #2.
\newcommand\saveabspage[1]{\zref@labelbyprops{#1}{abspage}}%
\newcommand\CheckWhetherAbsPageInLabelrange[2]{%
  \zref@ifrefundefined{#1}{\@secondoftwo}{%
    \zref@ifrefundefined{#2}{\@secondoftwo}{%
      \zref@ifrefcontainsprop{#1}{abspage}{%
        \zref@ifrefcontainsprop{#2}{abspage}{%
          \ifnum\zref@extractdefault{#1}{abspage}{-1}>\value{abspage}%
          \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
          {\@secondoftwo}{%
            \ifnum\zref@extractdefault{#2}{abspage}{-1}<\value{abspage}%
            \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
            {\@secondoftwo}{\@firstoftwo}%
          }%
        }{\@secondoftwo}%
      }{\@secondoftwo}%
    }%
  }%
}%

\makeatother

% The zref-label at the start of the longtable is "tablesfirstpage".
% The zref-label at the end of the longtable is "tableslastpage".
% Add to the hook carried out at every shipout the directive to check if
% absolute page is in range denoted by these labels, and if so,
% to rotate the page/to rotate \ShipoutBox:
\AddToHook{shipout/before}{%
  \CheckWhetherAbsPageInLabelrange{tablesfirstpage}{tableslastpage}{%
    \setbox\ShipoutBox=\vbox{\hbox{\rotatebox[origin=c]{90}{%
      \vbox{\hbox{\box\ShipoutBox\kern\ifodd\value{page}\evensidemargin\else\oddsidemargin\fi}}%
    }}}%
  }{%
  }%
}%

% Just make sure...
\csname @ifundefined\endcsname{pagewidth}{}{\pagewidth=\paperwidth}%
\csname @ifundefined\endcsname{pdfpagewidth}{}{\pdfpagewidth=\paperwidth}%
\csname @ifundefined\endcsname{pageheight}{}{\pageheight=\paperheight}%
\csname @ifundefined\endcsname{pdfpageheight}{}{\pdfpageheight=\paperheight}%

\begin{document}

\blindtext
\newpage
\begingroup
\ifodd\value{abspage}\newpage\else\newpage\null\newpage\fi
% ---- Layout ----------------------------------------------------------------------
%      For typesetting the longtable temporarily change the layout so that
%      width and height of page are exchanged and textwidth is increased etc:
\pagestyle{plain}%
\csname zref@ifrefundefined\endcsname{tablesfirstpage}{%
  \paperwidth=\the\expandafter\paperheight
  \expandafter\paperheight\expandafter=\the\paperwidth
  \csname @ifundefined\endcsname{pagewidth}{}{\pagewidth=\paperwidth}%
  \csname @ifundefined\endcsname{pdfpagewidth}{}{\pdfpagewidth=\paperwidth}%
  \csname @ifundefined\endcsname{pageheight}{}{\pageheight=\paperheight}%
  \csname @ifundefined\endcsname{pdfpageheight}{}{\pdfpageheight=\paperheight}%
  \textwidth=\paperwidth
}{%
  \textwidth=\paperheight
}%
\advance\textwidth-3cm\relax
\evensidemargin=\dimexpr-1in+1.5cm\relax
\oddsidemargin=\dimexpr-1in+1.5cm\relax
\marginparsep=2mm\relax
\marginparwidth=\dimexpr2cm-2\marginparsep\relax
\csname zref@ifrefundefined\endcsname{tablesfirstpage}{%
  \textheight=\paperheight
}{%
  \textheight=\paperwidth
}%
\advance\textheight-3cm\relax
\topmargin=\dimexpr-1in+1.5cm\relax
\headheight=0pt\relax
\headsep=0pt\relax
{\normalfont
 \setbox\csname @tempboxa\endcsname\hbox{0123456789}%
 \footskip=\dimexpr 1cm -.5\dp\csname @tempboxa\endcsname
                        +.5\ht\csname @tempboxa\endcsname\relax
\expandafter}\expandafter\footskip\expandafter=\the\footskip
\csname @colht\endcsname=\textheight
\csname @colroom\endcsname=\textheight
\vsize=\textheight
\columnwidth=\textwidth
\hsize=\columnwidth
\linewidth=\hsize
\parindent=0pt\relax
% ---- Layout-changes done. --------------------------------------------------------
\begin{longtable}{|c|c|c|c|}
\caption{Caption of Longtable}\label{LongtableLabel}\\
\hline
\saveabspage{tablesfirstpage}number&left&middle&right\\
\hline\endfirsthead
\hline
number&left&middle&right\\
\hline\endhead
\hline
\multicolumn{4}{|c|}{This is a clever remark.}\\
\hline\endfoot
\hline
\multicolumn{4}{|c|}{This is a clever remark.\saveabspage{tableslastpage}}\\
\hline\endlastfoot
\scratchtoksloop{1}%
                {100}%
                {%
                  \expandafter\hbox\expandafter{%
                    \expandafter\PassFirstToSecond
                    \expandafter{\scratchmacro}{\hphantom{100}\llap}%
                  }%
                  &left&middle&\scratchtoksloop{1}{11}{ this is wide }\\%
                }%
\end{longtable}%
\newpage
\endgroup
% ---- After typesettig the longtable reset the page layout ------------------------
\csname @colht\endcsname=\textheight
\csname @colroom\endcsname=\textheight
\vsize=\textheight
\columnwidth=\textwidth
\hsize=\columnwidth
\linewidth=\hsize

\blindtext

\end{document}

在此輸入影像描述

相關內容