I am a beginner in Latex and I am struggling about doing tables. I have in my project several long and wide tables that span over several pages. I am finding difficult in aligning them within the page size which is A4 landscape.
Also, I am finding difficult on how to wrap the text within a cell of the table with a specified size. Finally, I am finding difficult to align the text in the headers and in the text so I make it all centered
I really appreciate if someone can help me so I can use and adapt my code for subsequent tables I have to do. I would appreciate if the code suggested is simple but generalisable enough so I can apply to as many further tables I have. Thank you!
Please see below my example code
\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}
This is part of the table latex produces
This is the nice table I would like to produce with everything well aligned (using excel)
In particular I would like the following to be improved
you can see that "superiority" is not centered. "Cediranib 20mg+FOLFOX6" go over to the next cell. "Bevacizumab+FOLFOX6" go over the next cell.
How do I improve these aspects in such a way that regardless of the text the text gets wrapped within the limits of the cell of the table?
Many thanks
Andy
Best Answer
I have spent a little time to make you table better (I hope).
\citeyear
, seems is one word, and it can't be wrapped, so the only solution is to increase width of column. By the way, some column can be made narrower.\vrule height 14pt depth 10pt width 0pt Investigational group
. This increases height of very first row.p{}
as specification of multicolum if text fits in one line, usec
to center text in whole width of multicolum span.\multirow{3}{\hsize}{\centering Study}
. Multirow ignores alignment specification for cell, so it need to be specified explicitly.{\arraystretch}{0.9}
lines touch text, seems, it is not wery good, better to increase value of \arraystretch.And here is how the table looks
\multirow
for some cells andorigin
for ratated words in body of the table.Here is code of the table (only body, no changes to preamble)