我是 Latex 的初学者,在制作表格方面遇到了困难。我的项目中有几个长而宽的表格,跨越了好几页。我发现很难在 A4 横向的页面尺寸内对齐它们。
此外,我发现如何将文本换行到指定大小的表格单元格内很困难。最后,我发现很难对齐标题和正文中的文本,所以我让它们全部居中
如果有人能帮助我,我可以使用并调整我的代码来处理我必须处理的后续表格,我将不胜感激。如果建议的代码简单但具有足够的通用性,那么我将不胜感激,这样我就可以将其应用于我拥有的尽可能多的其他表格。谢谢!
请参阅下面我的示例代码
\documentclass{article}
\usepackage{multirow}
\usepackage{lscape}
\usepackage{comment}
\usepackage{longtable}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage[T1]{fontenc}
\usepackage[style=nejm,backend=biber, maxbibnames=99, minnames=3, maxnames=20, terseinits=true, giveninits=true]{biblatex}
\usepackage{rotating}
\usepackage{float}
\usepackage{textgreek}
\usepackage[english]{babel}
\usepackage{pdflscape}
\usepackage[a4paper,width=150mm,top=25mm,bottom=35mm, right=25mm,left=25mm, bindingoffset=6mm]{geometry}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{ltablex,booktabs}
\usepackage{color,soul}
\usepackage{rotating}
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{landscape}
\centering
\renewcommand{\arraystretch}{0.9}%
\begin{longtable}{|
>{\centering\arraybackslash}m{2cm}|
>{\centering\arraybackslash}m{1cm}|
>{\centering\arraybackslash}m{1cm}|
>{\centering\arraybackslash}m{1cm}|
>{\centering\arraybackslash}m{2cm}|
>{\centering\arraybackslash}m{2cm}|
>{\centering\arraybackslash}m{1cm}|
>{\centering\arraybackslash}m{2cm}|
>{\centering\arraybackslash}m{2cm}|
>{\centering\arraybackslash}m{1cm}|
>{\centering\arraybackslash}m{1cm}|
>{\centering\arraybackslash}m{2cm}|
>{\centering\arraybackslash}m{1.5cm}|
}
%{|p{2cm}|p{1cm}|p{1cm}|p{1cm}|p{2cm}|p{2cm}|p{1cm}|p{2cm}|p{2cm}|p{1cm}|p{1cm}|p{2cm}|p{1.5cm}|}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\hline
\multirow{3}{2cm}{Study} &
\multirow{3}{1cm}{\rotatebox[origin=c]{90}{Phase}} &
\multirow{3}{1cm}{\rotatebox[origin=c]{90}{Blinding}} &
\multirow{3}{1cm}{\rotatebox[origin=c]{90}{Design}} &
\multirow{3}{2cm}{Disease} &
\multicolumn{3}{m{5cm}|}{\small Investigational group} &
\multicolumn{3}{m{5cm}|}{\small Reference group} &
\multicolumn{2}{m{4cm}|}{\small PFS/DFS} \\
\cline{5-13}
& & & & &
\multirow{1}{2cm}{\small Treatment} &
\multirow{1}{1cm}{N} &
\multirow{1}{2cm}{\small Median PFS months} &
\multirow{1}{2cm}{\small Treatment} &
\multirow{1}{1cm}{N} &
\multirow{1}{2cm}{\small Median PFS months} &
\multirow{1}{2cm}{PFS HR (95\% CI)} &
\multirow{1}{1.5cm}{PFS p-value} \\
& & & & & & & & & & & & \\
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\endfirsthead
\multicolumn{13}{l}%
{{\bfseries \tablename\ \thetable{} -- (Continued from previous page)}} \tabularnewline
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\hline
\multirow{3}{2cm}{Study} &
\multirow{3}{1cm}{\rotatebox[origin=c]{90}{Phase}} &
\multirow{3}{1cm}{\rotatebox[origin=c]{90}{Blinding}} &
\multirow{3}{1cm}{\rotatebox[origin=c]{90}{Design}} &
\multirow{3}{2cm}{Disease} &
\multicolumn{3}{m{5cm}|}{\small Investigational group} &
\multicolumn{3}{m{5cm}|}{\small Reference group} &
\multicolumn{2}{m{4cm}|}{\small PFS/DFS} \\
\cline{5-13}
& & & & &
\multirow{1}{2cm}{\small Treatment} &
\multirow{1}{1cm}{N} &
\multirow{1}{2cm}{\small Median PFS months} &
\multirow{1}{2cm}{\small Treatment} &
\multirow{1}{1cm}{N} &
\multirow{1}{2cm}{\small Median PFS months} &
\multirow{1}{2cm}{PFS HR (95\% CI)} &
\multirow{1}{1.5cm}{PFS p-value} \\
& & & & & & & & & & & & \\
\hline
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\endhead
& & \tabularnewline
\hline
\multicolumn{13}{l}{{(Continued on next page)}} \tabularnewline
\endfoot
\hline
\endlastfoot
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\cline{1-13}
\multicolumn{13}{|l|}{Primary endpoint DFS} \\
\cline{1-13}
\citeauthor*{pmid25403578}, \citeyear{pmid25403578} \parencite{pmid25403578}; \citeauthor*{pmid27310205}, \citeyear{pmid27310205} \parencite{pmid27310205} & 3 & No & \rotatebox[origin=c]{90}{Superiority} & Resectable metastatic colorectal cancer & FOLFOX7+FOLFORI & 140 & 24.5 & FOLFOX4 & 142 & 22.4 & 0.94 (0.94,0.70,1.26) & 0.679 \\
\cline{1-13}
\citeauthor*{pmid28634730}, \citeyear{pmid28634730} \parencite{pmid28634730} & 3 & No & \rotatebox[origin=c]{90}{Non-inferiority} & IIB/III colorectal cancer & Oral adjuvant uracil and tegafur plus protein-bound polysaccharide K (UFT + PSK) & 151 & NR, 3 years DFS=72.6\% & Oral adjuvant uracil and tegafur plus leucovorin (UFT/LV) & 161 & NR, 3 years DFS=82.3\% & NR & NR \\
\cline{1-13}
\citeauthor*{pmid25403578}, \citeyear{pmid25403578} \parencite{pmid25403578}; \citeauthor*{pmid27310205}, \citeyear{pmid27310205} \parencite{pmid27310205} & 3 & No & \rotatebox[origin=c]{90}{Superiority} & Resectable metastatic colorectal cancer & FOLFOX7+FOLFORI & 140 & 24.5 & FOLFOX4 & 142 & 22.4 & 0.94 (0.94,0.70,1.26) & 0.679 \\
\cline{1-13}
\citeauthor*{pmid28634730}, \citeyear{pmid28634730} \parencite{pmid28634730} & 3 & No & \rotatebox[origin=c]{90}{Non-inferiority} & IIB/III colorectal cancer & Oral adjuvant uracil and tegafur plus protein-bound polysaccharide K (UFT + PSK) & 151 & NR, 3 years DFS=72.6\% & Oral adjuvant uracil and tegafur plus leucovorin (UFT/LV) & 161 & NR, 3 years DFS=82.3\% & NR & NR \\
\cline{1-13}
\multicolumn{13}{|l|}{Primary endpoint Other} \\
\cline{1-13}
\citeauthor*{pmid25403578}, \citeyear{pmid25403578} \parencite{pmid25403578}; \citeauthor*{pmid27310205}, \citeyear{pmid27310205} \parencite{pmid27310205} & 3 & No & \rotatebox[origin=c]{90}{Superiority} & Resectable metastatic colorectal cancer & FOLFOX7+FOLFORI & 140 & 24.5 & FOLFOX4 & 142 & 22.4 & 0.94 (0.94,0.70,1.26) & 0.679 \\
\cline{1-13}
\citeauthor*{pmid28634730}, \citeyear{pmid28634730} \parencite{pmid28634730} & 3 & No & \rotatebox[origin=c]{90}{Non-inferiority} & IIB/III colorectal cancer & Oral adjuvant uracil and tegafur plus protein-bound polysaccharide K (UFT + PSK) & 151 & NR, 3 years DFS=72.6\% & Oral adjuvant uracil and tegafur plus leucovorin (UFT/LV) & 161 & NR, 3 years DFS=82.3\% & NR & NR \\
\cline{1-13}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{longtable}
\end{landscape}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
这是乳胶生产表的一部分
这是我想要制作的漂亮表格,其中所有内容都排列整齐(使用 excel)
我尤其希望改进以下方面
您可以看到“优越性”未居中。“Cediranib 20mg+FOLFOX6”转到下一个单元格。“Bevacizumab+FOLFOX6”转到下一个单元格。
我该如何改进这些方面,使得无论文本如何,文本都会在表格单元格的限制内换行?
非常感谢
安迪
答案1
我花了一点时间来让你的桌子变得更好(我希望)。
- 生成的文本
\citeyear
,似乎只有一个单词,并且无法换行,所以唯一的解决办法是增加列宽。顺便说一下,某些列可以做得更窄。 - 为了使旋转后的“盲法”适合表头,\vrule 可以放在“调查组”之前 -
\vrule height 14pt depth 10pt width 0pt Investigational group
。这会增加第一行的高度。 p{}
如果文本适合一行,请不要将其用作多列的规范,而应将c
文本置于多列跨度的整个宽度内居中。- 您可以将 \hsize 指定为 \multirow 的内容宽度
\multirow{3}{\hsize}{\centering Study}
。Multirow 会忽略单元格的对齐规范,因此需要明确指定。 - 当
{\arraystretch}{0.9}
线条接触文本时,似乎不太好,最好增加 \arraystretch 的值。 - 当然,类似的列(例如,处理)的宽度应该相同。
- 我已经删除了表格主体中的
\multirow
一些单元格和标注的单词。origin
以下是表格的代码(仅正文,序言无变化)
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{landscape}
\centering
\renewcommand{\arraystretch}{1.2}%
\tabcolsep=3pt
\begin{longtable}{|
>{\centering\arraybackslash}m{3.0cm}| % 1 Study
>{\centering\arraybackslash}m{0.7cm}| % 2 Phase
>{\centering\arraybackslash}m{0.7cm}| % 3 Blinding
>{\centering\arraybackslash}m{0.7cm}| % 4 Design
>{\centering\arraybackslash}m{2.0cm}| % 5 Desease
>{\centering\arraybackslash}m{2.3cm}| % 6 Treatment
>{\centering\arraybackslash}m{0.7cm}| % 7 N
>{\centering\arraybackslash}m{2.0cm}| % 8 Median PFS
>{\centering\arraybackslash}m{2.0cm}| % 9 Treatment
>{\centering\arraybackslash}m{0.7cm}| % 10 N
>{\centering\arraybackslash}m{2.0cm}| % 11 Median PFS
>{\centering\arraybackslash}m{2.5cm}| % 12 PFS HR
>{\centering\arraybackslash}m{1.5cm}| % 13 PFS p-value
}
%{|p{2cm}|p{1cm}|p{1cm}|p{1cm}|p{2cm}|p{2cm}|p{1cm}|p{2cm}|p{2cm}|p{1cm}|p{1cm}|p{2cm}|p{1.5cm}|}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\hline
\multirow{3}{\hsize}{\centering Study} &
\multirow{3}{\hsize}{\centering \rotatebox[origin=c]{90}{Phase}} &
\multirow{3}{\hsize}{\centering\rotatebox[origin=c]{90}{Blinding}} &
\multirow{3}{\hsize}{\centering\rotatebox[origin=c]{90}{Design}} &
\multirow{3}{\hsize}{\centering Disease} &
\multicolumn{3}{c|}{\small \vrule height 14pt depth 10pt width 0pt Investigational group} &
\multicolumn{3}{c|}{\small Reference group} &
\multicolumn{2}{c|}{\small PFS/DFS} \\
\cline{6-13}
& & & & &
\small Treatment &
N &
\small Median PFS months &
\small Treatment &
N &
\small Median PFS months &
PFS HR (95\%~CI) &
PFS p-value \\
%& & & & & & & & & & & & \\
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\endfirsthead
\multicolumn{13}{l}%
{{\bfseries \tablename\ \thetable{} -- (Continued from previous page)}} \tabularnewline
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\hline
\multirow{3}{\hsize}{\centering Study} &
\multirow{3}{\hsize}{\centering\rotatebox[origin=c]{90}{Phase}} &
\multirow{3}{\hsize}{\centering\rotatebox[origin=c]{90}{Blinding}} &
\multirow{3}{\hsize}{\centering\rotatebox[origin=c]{90}{Design}} &
\multirow{3}{\hsize}{\centering Disease} &
\multicolumn{3}{c|}{\small \vrule height 14pt depth 10pt width 0pt Investigational group} &
\multicolumn{3}{c|}{\small Reference group} &
\multicolumn{2}{c|}{\small PFS/DFS} \\
\cline{6-13}
& & & & &
\small Treatment &
N &
\small Median PFS months &
\small Treatment &
N &
\small Median PFS months &
PFS HR (95\%~CI) &
PFS p-value \\
%& & & & & & & & & & & & \\
\hline
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\endhead
%& & \tabularnewline
\hline
\multicolumn{13}{l}{{(Continued on next page)}} \tabularnewline
\endfoot
\hline
\endlastfoot
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\cline{1-13}
\multicolumn{13}{|l|}{Primary endpoint DFS} \\
\cline{1-13}
\citeauthor*{pmid25403578}, \citeyear{pmid25403578} \parencite{pmid25403578}; \citeauthor*{pmid27310205}, \citeyear{pmid27310205} \parencite{pmid27310205} & 3 & No & \rotatebox{90}{Superiority} & Resectable metastatic colorectal cancer & FOLFOX7+FOLFORI & 140 & 24.5 & FOLFOX4 & 142 & 22.4 & 0.94 (0.94,0.70,1.26) & 0.679 \\
\cline{1-13}
\citeauthor*{pmid28634730}, \citeyear{pmid28634730} \parencite{pmid28634730} & 3 & No & \rotatebox{90}{Non-inferiority} & IIB/III colorectal cancer & Oral adjuvant uracil and tegafur plus protein-bound polysaccharide K (UFT + PSK) & 151 & NR, 3 years DFS=72.6\% & Oral adjuvant uracil and tegafur plus leucovorin (UFT/LV) & 161 & NR, 3 years DFS=82.3\% & NR & NR \\
\cline{1-13}
\citeauthor*{pmid25403578}, \citeyear{pmid25403578} \parencite{pmid25403578}; \citeauthor*{pmid27310205}, \citeyear{pmid27310205} \parencite{pmid27310205} & 3 & No & \rotatebox{90}{Superiority} & Resectable metastatic colorectal cancer & FOLFOX7+FOLFORI & 140 & 24.5 & FOLFOX4 & 142 & 22.4 & 0.94 (0.94,0.70,1.26) & 0.679 \\
\cline{1-13}
\citeauthor*{pmid28634730}, \citeyear{pmid28634730} \parencite{pmid28634730} & 3 & No & \rotatebox{90}{Non-inferiority} & IIB/III colorectal cancer & Oral adjuvant uracil and tegafur plus protein-bound polysaccharide K (UFT + PSK) & 151 & NR, 3 years DFS=72.6\% & Oral adjuvant uracil and tegafur plus leucovorin (UFT/LV) & 161 & NR, 3 years DFS=82.3\% & NR & NR \\
\cline{1-13}
\noalign{\penalty-10000}
\multicolumn{13}{|l|}{Primary endpoint Other} \\
\cline{1-13}
\citeauthor*{pmid25403578}, \citeyear{pmid25403578} \parencite{pmid25403578}; \citeauthor*{pmid27310205}, \citeyear{pmid27310205} \parencite{pmid27310205} & 3 & No & \rotatebox{90}{Superiority} & Resectable metastatic colorectal cancer & FOLFOX7+FOLFORI & 140 & 24.5 & FOLFOX4 & 142 & 22.4 & 0.94 (0.94, 0.70, 1.26) & 0.679 \\
\cline{1-13}
\citeauthor*{pmid28634730}, \citeyear{pmid28634730} \parencite{pmid28634730} & 3 & No & \rotatebox{90}{Non-inferiority} & IIB/III colorectal cancer & Oral adjuvant uracil and tegafur plus protein-bound polysaccharide K (UFT + PSK) & 151 & NR, 3 years DFS=72.6\% & Oral adjuvant uracil and tegafur plus leucovorin (UFT/LV) & 161 & NR, 3 years DFS=82.3\% & NR & NR \\
\cline{1-13}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{longtable}
\end{landscape}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}