![如何建立一個橫跨兩個垂直(且相對)A4 頁寬度的表格?](https://rvso.com/image/266391/%E5%A6%82%E4%BD%95%E5%BB%BA%E7%AB%8B%E4%B8%80%E5%80%8B%E6%A9%AB%E8%B7%A8%E5%85%A9%E5%80%8B%E5%9E%82%E7%9B%B4%EF%BC%88%E4%B8%94%E7%9B%B8%E5%B0%8D%EF%BC%89A4%20%E9%A0%81%E5%AF%AC%E5%BA%A6%E7%9A%84%E8%A1%A8%E6%A0%BC%EF%BC%9F.png)
我有一張大(寬)桌子要排版。我通常在表格中使用下面的程式碼,這使我能夠指定表格中每列的寬度。但是,我需要確保列寬度的總和適合頁面。
\documentclass[12pt, a4paper]{article}
\usepackage{booktabs, array}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\begin{document}
\begin{table}
\begin{tabular}{C{2cm} C{2cm} C{2cm} C{2cm} C{2cm} C{2cm}}
\toprule
~ & \textbf{Column 1} & \textbf{Column 2} & \textbf{Column 3} & \textbf{Column 4} & \textbf{Column 5} \\
\textbf{Row 1} & Text (1,1) & Text (1,2) & Text (1,3) & Text (1,4) & Text (1,5) \\
\textbf{Row 2} & Text (2,1) & Text (2,2) & Text (2,3) & Text (2,4) & Text (2,5) \\
\textbf{Row 3} & Text (3,1) & Text (3,2) & Text (3,3) & Text (3,4) & Text (3,5) \\
\textbf{Row 4} & Text (4,1) & Text (4,2) & Text (4,3) & Text (4,4) & Text (4,5) \\
\textbf{Row 5} & Text (5,1) & Text (5,2) & Text (5,3) & Text (5,4) & Text (5,5) \\
\textbf{Row 6} & Text (6,1) & Text (6,2) & Text (6,3) & Text (6,4) & Text (6,5) \\
\bottomrule
\end{tabular}
\caption{This is a table}
\end{table}
\end{document}
我想創建一個非常寬的表格,橫跨 2 個垂直 A4 頁的寬度
(我正在使用頁面的兩側編寫文檔,我希望表格的左角位於偶數頁碼上,表格的右角位於相反的頁面上)。
因此,左邊頁上不應有任何右邊距,右邊頁上不應有左邊距,以便表格在兩個 A4 頁的寬度上是連續的。
這可能嗎?
答案1
我的回答始於如何建立按段落對齊的 6 個平行文本,每頁 3 個文本?作為基準,但必須做出一些改變。
從更簡單的角度來看,我不必擔心此 OP 查詢的不同高度的行條目。但不利的一面是,我必須大幅重寫程式碼來處理 10 個或更多列條目(因為#10
不起作用)。為此,我沒有傳遞不同的列條目作為參數,而是編寫了自己的選項卡解析程式碼,以便可以像表格行一樣輸入該行。
我仍然使用 Herbert 的程式碼片段來處理 中的表格標記\whiledo
,並且添加了 Stephan Lehmke 的片段,用於在模式下以偶數頁碼開始表格twoside
。
作為一個額外的功能,我不僅允許程式碼跨左/右頁分解,而且還可以垂直分解,以用於超長的表格。語法是\newtwopagetable
初始化進程。然後,新增各個行,\tenbyrow{}
其中參數是&
十個條目的分隔清單(這是對其他列號條目的小重寫)。最後,當所有資料都以這種方式輸入時,您有兩個選擇:
\newtwopagetable{caption}
整個表格將在兩頁上輸出;或者
\maketwopagetable[4]{caption}
\maketwopagetable[4]{caption}
也會將雙面表格分成垂直部分,如上所示,第一個雙頁上有四行,第二個雙頁上有四行。
這是原始碼:
\documentclass[twoside]{article}% TABLE CLEARS TO EVEN PAGE
%\documentclass{article}% TABLE CLEARS TO NEXT PAGE
\usepackage{booktabs, array}
\usepackage{ifthen}
\usepackage{etoolbox}
\makeatletter%%%%%%%%%%% My own tab parsing code
\newcounter{TABcellindex@}
\newcommand\readTABrow[2]{%
\def\doneTABread{F}%
\def\postTAB{#2}%
\setcounter{TABcellindex@}{0}%
\whiledo{\equal{\doneTABread}{F}}{%
\stepcounter{TABcellindex@}%
\expandafter\processTAB\postTAB&\\%
\ifthenelse{\equal{\preTAB}{}}{%
\addtocounter{TABcellindex@}{-1}%
\def\doneTABread{T}%
}{%
\expandafter\protected@edef\csname #1\alph{TABcellindex@}\endcsname{%
\preTAB}%
}%
}%
% \#1TABcells GIVES HOW MANY TAB COLUMNS WERE PROCESSED
% \expandafter\xdef\csname #1TABcells\endcsname{\arabic{TABcellindex@}}%
}
\def\processTAB#1\\{%
\protected@edef\preTAB{#1}%
\protected@edef\postTAB{#2}%
}
\makeatother%%%%%%%%%%% END My own tab parsing code
\makeatletter%%%%%%%%%%% Herbert's tabular token code
\newcounter{tabindex}
\newtoks\@tabtoks
\newcommand\addtabtoks[1]{%
\@tabtoks\expandafter{\the\@tabtoks\stepcounter{tabindex}#1}}
\newcommand*\resettabtoks{\@tabtoks{}}
\newcommand*\synctabindex[1]{\setcounter{tabindex}{\value{#1}}}
\newcommand*\printtabtoks{\the\@tabtoks}
\makeatother%%%%%%%%%%% END Herbert's tabular token code
\makeatletter%%%%%%% Lehmke's \cleartoleftpage
\def\cleartoleftpage{\clearpage\if@twoside \ifodd\c@page
\hbox{}\newpage\if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother
\makeatother%%%%%%%% END Lehmke's \cleartoleftpage
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcounter{sptstartrow}
\newcounter{sptendrow}
\newcounter{entries}
\newcommand\newtwopagetable{%
\setcounter{sptendrow}{0}%
\setcounter{entries}{0}%
\cleartoleftpage%
}
\makeatletter
\newcommand\tenbyrow[1]{%
\stepcounter{entries}%
\readTABrow{entryX\roman{entries}X}{#1}%
}
\makeatother
\newcounter{index}
\newcommand\maketwopagetable[2][\theentries]{%
\setcounter{sptstartrow}{\thesptendrow}%
\ifthenelse{\thesptstartrow > 1}%
{\addtocounter{table}{-1}\def\conttext{, continued}}%
{\def\conttext{}}%
\addtocounter{sptendrow}{#1}%
\ifthenelse{\thesptendrow > \theentries}{\setcounter{sptendrow}{\theentries}}{}%
\clearpage
\setcounter{index}{\thesptstartrow}%
\synctabindex{index}
\resettabtoks%
\whiledo{\theindex < \thesptendrow}{%
\stepcounter{index}%
\addtabtoks{%
\csname entryX\roman{tabindex}Xa\endcsname &
\csname entryX\roman{tabindex}Xb\endcsname &
\csname entryX\roman{tabindex}Xc\endcsname &
\csname entryX\roman{tabindex}Xd\endcsname &
\csname entryX\roman{tabindex}Xe\endcsname
\\%
}%
}%
\begin{table}
\centering
\begin{tabular}{C{2cm} C{2cm} C{2cm} C{2cm} C{2cm}}
\toprule
\printtabtoks%
\bottomrule
\end{tabular}%
\caption{#2 (left half\conttext)}
\end{table}%
\addtocounter{table}{-1}%
\clearpage
\setcounter{index}{\thesptstartrow}%
\synctabindex{index}
\resettabtoks%
\whiledo{\theindex < \thesptendrow}{%
\stepcounter{index}%
\addtabtoks{%
\csname entryX\roman{tabindex}Xf\endcsname &
\csname entryX\roman{tabindex}Xg\endcsname &
\csname entryX\roman{tabindex}Xh\endcsname &
\csname entryX\roman{tabindex}Xi\endcsname &
\csname entryX\roman{tabindex}Xj\endcsname
\\%
}%
}%
\begin{table}
\centering
\begin{tabular}{C{2cm} C{2cm} C{2cm} C{2cm} C{2cm}}
\toprule
\printtabtoks%
\bottomrule
\end{tabular}%
\caption{#2 (right half\conttext)}
\end{table}%
}
\begin{document}
\newtwopagetable
\tenbyrow%
{~ & \textbf{Column 1} & \textbf{Column 2} & \textbf{Column 3} &
\textbf{Column 4} & \textbf{Column 5} & \textbf{Column 6} &
\textbf{Column 7} & \textbf{Column 8} & \textbf{Column 9}}
\tenbyrow%
{\textbf{Row 1} & Text (1,1) & Text (1,2) & Text (1,3) & Text (1,4)
& Text (1,5) & Text (1,6) & Text (1,7) & Text (1,8) & Text (1,9)}
\tenbyrow%
{\textbf{Row 2} & Text (2,1) & Text (2,2) & Text (2,3) & Text (2,4)
& Text (2,5) & Text (2,6) & Text (2,7) & Text (2,8) & Text (2,9)}
\tenbyrow%
{\textbf{Row 3} & Text (3,1) & Text (3,2) & Text (3,3) & Text (3,4)
& Text (3,5) & Text (3,6) & Text (3,7) & Text (3,8) & Text (3,9)}
\tenbyrow%
{\textbf{Row 4} & Text (4,1) & Text (4,2) & Text (4,3) & Text (4,4)
& Text (4,5) & Text (4,6) & Text (4,7) & Text (4,8) & Text (4,9)}
\tenbyrow%
{\textbf{Row 5} & Text (5,1) & Text (5,2) & Text (5,3) & Text (5,4)
& Text (5,5) & Text (5,6) & Text (5,7) & Text (5,8) & Text (5,9)}
\tenbyrow%
{\textbf{Row 6} & Text (6,1) & Text (6,2) & Text (6,3) & Text (6,4)
& Text (6,5) & Text (6,6) & Text (6,7) & Text (6,8) & Text (6,9)}
\tenbyrow%
{\textbf{Row 7} & Text (7,1) & Text (7,2) & Text (7,3) & Text (7,4)
& Text (7,5) & Text (7,6) & Text (7,7) & Text (7,8) & Text (7,9)}
\maketwopagetable{This is a table}
\newtwopagetable
\setcounter{entries}{8}% THIS IS TO FOOL LaTeX INTO THINKING I RE-ENTERED THE TABLE DATA
\maketwopagetable[4]{This is a vertically split table}
\maketwopagetable[4]{This is a vertically split table}
\end{document}
這是雙頁上的完整表格輸出:
這是表格,按寬度和長度分割,作為接下來四頁的輸出。請注意,(left/right half, continued)
評論由 提供\maketwopagetable
,並且不是使用者字幕參數的一部分。