![在列之间添加垂直线](https://linux22.com/image/420195/%E5%9C%A8%E5%88%97%E4%B9%8B%E9%97%B4%E6%B7%BB%E5%8A%A0%E5%9E%82%E7%9B%B4%E7%BA%BF.png)
我正在为我的论文附录创建表格,并且对于特定的表格我遇到了以下问题:
- 我的表格从下一页开始。如果我想将表格分成几页,我应该如何更改?
- 我想在第二列和第三列之间添加一条垂直线(因为第 1 列和第 2 列中显示的信息与第 3 列和第 4 列中显示的信息相同)。
我向您展示了我使用的代码及其结果(请注意,我已经在文档中的其他表格中使用了 newcolumntypes)。表格应从附录 B 之后开始。
\usepackage{array,ragged2e}
\newcolumntype{C}{>{\Centering\hspace{0pt}}p{0.1\textwidth}}
\usepackage[output-decimal-marker={,}]{siunitx}
\usepackage{booktabs, makecell, tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\section{Suppliers´ production capabilities}
\begin{table}[ht]
\resizebox{\textwidth}{!}{%
\begin{tabular}{lllll}
\toprule
\multicolumn{1}{c}{\textbf{Facility Name}} & \multicolumn{1}{c}{\textbf{Product}} & \multicolumn{1}{c}{\textbf{Facility Name}} & \multicolumn{1}{c}{\textbf{Product}} \\
\midrule
Texttexttexttexttexttextt & Wordswordswordswordswordswords & Texttexttexttexttexttexttex & Wordswordswordswordswordswords \\
Texttexttexttexttexttextt & Wordswordswordswordswordswords & Texttexttexttexttexttexttex & Wordswordswordswordswordswords \\
Texttexttexttexttexttextt & Wordswordswordswordswordswords & Texttexttexttexttexttexttex & Wordswordswordswordswordswords \\
Texttexttexttexttexttextt & Wordswordswordswordswordswords & Texttexttexttexttexttexttex & Wordswordswordswordswordswords \\
Texttexttexttexttexttextt & Wordswordswordswordswordswords & Texttexttexttexttexttexttex & Wordswordswordswordswordswords \\
Texttexttexttexttexttextt & Wordswordswordswordswordswords & Texttexttexttexttexttexttex & Wordswordswordswordswordswords \\
Texttexttexttexttexttextt & Wordswordswordswordswordswords & Texttexttexttexttexttexttex & Wordswordswordswordswordswords \\
Texttexttexttexttexttextt & Wordswordswordswordswordswords & Texttexttexttexttexttexttex & Wordswordswordswordswordswords \\
Texttexttexttexttexttextt & Wordswordswordswordswordswords & Texttexttexttexttexttexttex & Wordswordswordswordswordswords \\
Texttexttexttexttexttextt & Wordswordswordswordswordswords & Texttexttexttexttexttexttex & Wordswordswordswordswordswords \\
Texttexttexttexttexttextt & Wordswordswordswordswordswords & Texttexttexttexttexttexttex & Wordswordswordswordswordswords \\
Texttexttexttexttexttextt & Wordswordswordswordswordswords & Texttexttexttexttexttexttex & Wordswordswordswordswordswords \\
Texttexttexttexttexttextt & Wordswordswordswordswordswords \\
\bottomrule
\end{tabular}%
}
\caption{Supplier facilities´ production capabilities }
\label{tab:my-table}
\end{table}
如果您能帮助我解决这个问题,我将非常感激!
答案1
这是一个longtable
基于的解决方案。所有四列都允许自动换行。列宽相等,并经过计算以占据最大可用宽度。
\documentclass{article}
\usepackage[hmargin=1in]{geometry} % set page parameters suitably
\usepackage{longtable,array,ragged2e}
\newlength\mylen
\setlength\mylen{\dimexpr0.25\textwidth-1.5\tabcolsep-0.25\arrayrulewidth\relax}
\newcolumntype{Z}{>{\RaggedRight}p{\mylen}}
\begin{document}
\section{Suppliers' production capabilities}
\setlength{\extrarowheight}{2pt}
\begin{longtable}{@{} ZZ | ZZ @{}}
%%% headers and footers:
\caption{Supplier facilities' production capabilities }
\label{tab:my-table}\\
\hline
\textbf{Facility Name} & \textbf{Product} &
\textbf{Facility Name} & \textbf{Product} \\
\hline
\endfirsthead
\multicolumn{4}{@{}l}{Table \thetable, cont'd}\\[1ex]
\hline
\textbf{Facility Name} & \textbf{Product} &
\textbf{Facility Name} & \textbf{Product} \\
\hline
\endhead
\hline
\multicolumn{4}{r@{}}{\footnotesize cont'd on following page}\\
\endfoot
\hline
\endlastfoot
%%% Body of table
Texttext texttextt exttexttex exttexttex & Wordswordswords wordswordswords & Texttext texttextt exttexttex exttexttex & Wordswordswords wordswordswords \\
Texttext texttextt exttextt & Wordswordswords wordswordswords & Texttext texttextt exttexttex exttexttex & Wordswordswords wordswordswords \\
Texttext texttextt exttextt & Wordswordswords wordswordswords & Texttext texttextt exttexttex exttexttex & Wordswordswords wordswordswords \\
Texttext texttextt exttextt & Wordswordswords wordswordswords & Texttext texttextt exttexttex exttexttex & Wordswordswords wordswordswords \\
Texttext texttextt exttextt & Wordswordswords wordswordswords & Texttext texttextt exttexttex exttexttex & Wordswordswords wordswordswords \\
Texttext texttextt exttextt & Wordswordswords wordswordswords & Texttext texttextt exttexttex exttexttex & Wordswordswords wordswordswords \\
Texttext texttextt exttextt & Wordswordswords wordswordswords & Texttext texttextt exttexttex exttexttex & Wordswordswords wordswordswords \\
Texttext texttextt exttextt & Wordswordswords wordswordswords & Texttext texttextt exttexttex exttexttex & Wordswordswords wordswordswords \\
Texttext texttextt exttextt & Wordswordswords wordswordswords & Texttext texttextt exttexttex exttexttex & Wordswordswords wordswordswords \\
\end{longtable}
\end{document}
答案2
使用方法如下xltabular
——它的语法与 longtable 相同,只是需要声明总宽度。具体来说,在 longtable 中,您不使用环境table
(它不是浮点数),标题被合并到表中,在第一头部分。
\documentclass{article}
\usepackage{array,ragged2e}
\newcolumntype{C}{>{\Centering\hspace{0pt}}p{0.1\textwidth}}
\usepackage[output-decimal-marker={,}]{siunitx}
\usepackage{lipsum}
\usepackage{booktabs, makecell, xltabular}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\begin{document}
\section{Suppliers´ production capabilities}
\lipsum[1-3]
\begin{xltabular}{\textwidth}{*{4}{L}}
\caption{Supplier facilities´ production capabilities }
\label{tab:my-table} \\
\toprule
\multicolumn{1}{c}{\textbf{Facility Name}} & \multicolumn{1}{c}{\textbf{Product}} & \multicolumn{1}{c}{\textbf{Facility Name}} & \multicolumn{1}{c}{\textbf{Product}} \\
\midrule
\endfirsthead
{\footnotesize (Continued)}\\
\toprule
\multicolumn{1}{c}{\textbf{Facility Name}} & \multicolumn{1}{c}{\textbf{Product}} & \multicolumn{1}{c}{\textbf{Facility Name}} & \multicolumn{1}{c}{\textbf{Product}} \\
\midrule
\endhead
\midrule
\multicolumn{4}{r}{\footnotesize (to be continued)}
\endfoot
\bottomrule
\endlastfoot
Text text text text text textt & Words words words words words words & Text text text text text text tex & Words words words words words words \\ \addlinespace
Text text text text text textt & Words words words words words words & Text text text text text text tex & Words words words words words words \\ \addlinespace
Text text text text text textt & Words words words words words words & Text text text text text text tex & Words words words words words words \\ \addlinespace
Text text text text text textt & Words words words words words words & Text text text text text text tex & Words words words words words words \\ \addlinespace
Text text text text text textt & Words words words words words words & Text text text text text text tex & Words words words words words words \\ \addlinespace
Text text text text text textt & Words words words words words words & Text text text text text text tex & Words words words words words words \\ \addlinespace
Text text text text text textt & Words words words words words words & Text text text text text text tex & Words words words words words words \\ \addlinespace
Text text text text text textt & Words words words words words words & Text text text text text text tex & Words words words words words words \\ \addlinespace
Text text text text text textt & Words words words words words words & Text text text text text text tex & Words words words words words words \\ \addlinespace
Text text text text text textt & Words words words words words words & Text text text text text text tex & Words words words words words words \\ \addlinespace
Text text text text text textt & Words words words words words words & Text text text text text text tex & Words words words words words words \\ \addlinespace
Text text text text text textt & Words words words words words words & Text text text text text text tex & Words words words words words words \\ \addlinespace
Text text text text text textt & Words words words words words words \
\end{xltabular}%
\end{document}