请您帮我解决以下代码(如下)好吗?
第一项研究的文本最后一列有一段很长的文本,我想将其挤在单元格空间内,或者为该特定研究留出单元格空间。
问题是:我想确保间距仅适用于具有长文本的特定单元格。我有一个其他研究列表,这些研究不需要减小文本的单元格间距或扩大单元格的间距。
您的代码越通用,对我来说就越好(例如,如果 Latex 能够自动调整所有内容或以很好的方式挤压文本)
非常感谢你的帮助
泽维尔
\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}
\small
\renewcommand{\arraystretch}{0.70}%
\begin{longtable}{
>{\centering\hspace{0pt}}m{0.10\linewidth}
>{\centering\hspace{0pt}}m{0.10\linewidth}
>{\centering\hspace{0pt}}m{0.09\linewidth}
>{\centering\hspace{0pt}}m{0.106\linewidth}
>{\centering\hspace{0pt}}m{0.096\linewidth}
>{\centering\hspace{0pt}}m{0.15\linewidth}
>{\centering\hspace{0pt}}m{0.15\linewidth}
>{\centering\arraybackslash\hspace{0pt}}m{0.15\linewidth}
}
\cline{1-8}
\textbf{Reference} & \textbf{HRQoL instruments} & \textbf{HRQoL domain} & \textbf{Assessment timepoints} & \textbf{HRQoL estimates} & \textbf{Investigational estimates} & \textbf{Reference estimates} & \textbf{Comparison between groups} \\
\cline{1-8}
\multirow{2}{\hsize}{\centering author, date} & \multirow{2}{\hsize}{\centering EORTC QLQ C-30} & \multirow{2}{\hsize}{\centering Global} & Baseline & \multirow{2}{\hsize}{\centering Mean(SD) [N]} & 66.7 (18.4) [NR] & 58 (23) [NR] & \multirow{2}{\hsize}{\centering Time adjusted difference (95\%CI): -0.40 (-3.5,2.7), p>0.05 despite higher \% of AEs in investigational arm} \\
\cmidrule{4-4}\cmidrule{6-7} & & & \footnotesize End of treatment & & 51.1 (22.3) [NR] & 52.2 (25.9) [NR] & \\
\cmidrule{2-4}\cmidrule{6-8} & \multirow{2}{\hsize}{\centering EQ-5D} & \multirow{2}{\hsize}{\centering Utility index} & Baseline & & 0.84 (0.19) [NR] & 0.75 (0.23) [NR] & \multirow{2}{\hsize}{\centering Time adjusted difference (95\%CI): 0 (-0.1, 0), p>0.05 despite higher \% of AEs in investigational arm} \\
\cmidrule{4-4}\cmidrule{6-7} & & & \footnotesize End of treatment & & 0.57 (0.40) [NR] & 0.57 (0.39) [NR] & \\
\cmidrule{3-4}\cmidrule{6-8} & & \multirow{2}{\hsize}{\centering Global} & Baseline & & 73.4 (17.3) [NR] & 71.4 (17.4) [NR] & \multirow{2}{\hsize}{\centering Time adjusted difference (95\%CI): -1.2 (-4, 1.7), p>0.05 despite higher \% of AEs in investigational arm} \\
\cmidrule{4-4}\cmidrule{6-7} & & & \footnotesize End of treatment & & 61.5 (21.4) [NR] & 62.6 (22.3) [NR] & \\
\midrule
\multirow{2}{\hsize}{\centering autor2, date} & \multirow{2}{\hsize}{\centering EORTC QLQ C-30} & \multirow{9}{\hsize}{\centering Global} & Baseline & \multirow{2}{\hsize}{\centering Mean (95\%CI) [N]} & 74.4(73.1,75.6) [796] & 74.8(73.6,76) [794] & \multirow{2}{\hsize}{\centering Significant differences between treatments at 3-6 months (p<0.05) favouring investigational group} \\
\cmidrule{4-4}\cmidrule{6-7} & & & 1 month & & 70.3(68.9,71.7) [719] & 69.2(67.6,70.8) [677] & \\
\cmidrule{4-4}\cmidrule{6-7} & & & 2 months & & 65.8(64.3,67.3) [660] & 64.5(62.9,66.1) [664] & \\
\cmidrule{4-4}\cmidrule{6-7} & & & 3 months & & 65.8(63.9,67.6) [456] & 64.4(62.8,66) [597] & \\
\cmidrule{4-4}\cmidrule{6-7} & & & 4 months & & 75.2(73.8,76.6) [543] & 65.5(63.9,67.1) [554] & \\
\cmidrule{4-4}\cmidrule{6-7} & & & 5 months & & 77.5(76.1,78.9) [522] & 66(64.4,67.6) [504] & \\
\cmidrule{4-4}\cmidrule{6-7} & & & 6 months & & 77.7(76.4,79.1) [509] & 65.5(63,68) [204] & \\
\cmidrule{4-4}\cmidrule{6-7}
\midrule
\end{longtable}
\end{landscape}
\end{document}
答案1
最有希望的解决方案似乎是使用tabularray
包。它针对多行单元格的解决方案会自动增加单元格高度,以使文本不会突出到其下方的单元格。
作为示例,它的用法是表格的第一部分:
\documentclass{article}
\usepackage[a4paper,
%width=150mm,
hmargin=25mm,
vmargin={25mm, 35mm},
bindingoffset=6mm
]{geometry}
\usepackage{pdflscape}
\usepackage{tabularray}
\begin{document}
\begin{landscape}
\small
\begin{longtblr}[caption = {The Caption}]%
{hlines, vlines,
colspec={l X[0.9, c] X[0.9, c] X[1.1, c] *{3}{X[1, c]} X[2, c] },
colsep =2pt,
rowhead = 1,
row{1} = {font=\bfseries\small},
}
%%%% table body
Reference & HRQoL instruments & HRQoL domain & Assessment time points &
HRQoL estimates & Investigational estimates & Reference estimates & Comparison between groups \\
%
\SetCell[r=6]{h} author, date
& EORTC QLQ & \SetCell[r=2]{h} Global
& Baseline &
\SetCell[r=6]{h} Mean(SD) [N]
& 66.7 (18.4) [NR] & 58 (23) [NR] & \SetCell[r=2]{m} Time adjusted difference (95\%CI):
-0.40 (-3.5,2.7), p>0.05 despite higher \% of AEs in investigational arm
\\
& C-30 & & End of treatment &
& 51.1 (22.3) [NR] & 52.2 (25.9) [NR] & \\
%
& \SetCell[r=4]{h} EQ-5D
& \SetCell[r=2]{h} Utility index
& Baseline &
& 0.84 (0.19) [NR] & 0.75 (0.23) [NR] & \SetCell[r=2]{h} Time adjusted difference (95\%CI):
0 (-0.1, 0), p>0.05 despite higher \% of AEs in investigational arm \\
%
& & & End of treatment &
& 0.57 (0.40) [NR] & 0.57 (0.39) [NR] & \\
& & \SetCell[r=2]{h} Global
& Baseline &
& 73.4 (17.3) [NR] & 71.4 (17.4) [NR] & \SetCell[r=2]{h} Time adjusted difference (95\%CI):
-1.2 (-4, 1.7), p>0.05 despite higher \% of AEs in investigational arm \\
& & & End of treatment &
& 61.5 (21.4) [NR] & 62.6 (22.3) [NR] & \\
\end{longtblr}
\end{landscape}
\end{document}
如果您不喜欢垂直线,请vlines
从表格序言中删除选项。
答案2
这将计算将一行文本分成两行所需的宽度。
\documentclass{article}
\newcommand{\twolinewidth}[1]{% #1 = text to put into two lines
\sbox0{#1}% measure width
\dimen0=0.5\wd0
\loop\sbox0{\parbox{\dimen0}{#1}}% iterate over small increments
\dimen1=\dimexpr \ht0+\dp0\relax
\ifdim\dimen1>2\baselineskip\relax
\advance\dimen0 by 1pt
\repeat
\edef\twolineresult{\the\dimen0}}
\begin{document}
\twolinewidth{Time adjusted difference (95\%CI): -1.2 (-4, 1.7), p>0.05 despite higher \% of AEs in investigational arm}%
\twolineresult\\
\rule{\twolineresult}{1pt}\\
\parbox{\twolineresult}{Time adjusted difference (95\%CI): -1.2 (-4, 1.7), p>0.05 despite higher \% of AEs in investigational arm}
\end{document}