问题与 MWE
我想将下longtblr
表的宽度增加到允许的最大页面宽度,我猜应该是与文本一样宽,即从页面的左边距到右边距。换句话说,我想使下表的宽度与文本一样宽,从左边距到右边距。
但是,我有一个限制。我想保持以下各列的宽度相同
colspec={m{0.9cm} m{0.1cm} m{0.6cm} m{1cm} m{3cm} m{6cm} m{1.5cm}},
除了第 6 列(称为Feature 2
)之外,现在它6cm
变宽了。因此,我们的想法是只使用第 6 列的宽度。
基本上,我想扩展/增加第 6 列的宽度,以使整个表格宽度达到允许的最大页面宽度。
是否有任何自动的方法可以做到这一点,或者我应该增加第 6 列的宽度,只要通过眼睛看到表格的左右边框与整个文档文本对齐?
我希望这足够清楚了!以下是我的 MWE 和相应的图:
\documentclass[twocolumn]{article}
% Some packages
\usepackage[margin=2cm]{geometry}
\usepackage[dvipsnames,table]{xcolor}
\definecolor{light-gray}{HTML}{FFFFFF}
\definecolor{light-blue}{HTML}{EBF5FB}
\usepackage{tabularray}
\usepackage{url}
% Other packages
\usepackage{lipsum}
\usepackage{tabulary,longtable,afterpage}
\usepackage{booktabs}
\makeatletter
\newcommand{\aftertwo}[1]{\afterpage{\if@firstcolumn #1
\else\afterpage{#1}\fi}}
\makeatother
% Start of the document
\begin{document}
% Some text
\lipsum[1-8]
% A "longtblr" table
\aftertwo{
\onecolumn
\begin{longtblr}[
caption = {This is a caption.},
]{
colspec={m{0.9cm} m{0.1cm} m{0.6cm} m{1cm} m{3cm} m{6cm} m{1.5cm}},
cells={font=\small},
row{1}={font=\itshape\small},
row{2,5-7}={bg=light-blue},
row{3-4}={bg=light-gray},
column{6}={preto={\minipage{6cm}}, appto={\endminipage}},
hlines
}
& Day
& Month
& Hours
& Feature 1
& Feature 2
& Feature 3\\
%-------------------------------------------------
Friday
& 5
& June
&
& This is a quite short text.
& This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times.
\begin{tblr}{ |c|c|c| }
\hline
cell1 & cell2 & cell3 \\
cell4 & cell5 & cell6 \\
cell7 & cell8 & cell9 \\
\hline
\end{tblr}
& Short text
\\
%-------------------------------------------------
\SetCell[r=2]{l} Saturday
& \SetCell[r=2]{l} 6
& \SetCell[r=2]{l} June
& 14 -- 21
& B\textsubscript{1}
&
& B\textsubscript{3}
\\
&
&
&
& C\textsubscript{1}
& C\textsubscript{2}
& C\textsubscript{3}
\\
% -------------------------------------------------
\SetCell[r=3]{l} Sunday
& \SetCell[r=3]{l} 7
& \SetCell[r=3]{l} June
& 08 -- 10
& D\textsubscript{1}
& D\textsubscript{2}
& D\textsubscript{3}
\\
&
&
& 10 -- 17
& E\textsubscript{1}
&
& E\textsubscript{3}
\\
&
&
&
& F\textsubscript{1}
& F\textsubscript{2}
& F\textsubscript{3}
\\
% -------------------------------------------------
\end{longtblr}
\twocolumn
}
% End of the document
\end{document}
答案1
- 您可以通过减少其他列的宽度来增加第 6 列的宽度。对于您的情况,我会减少第 5 列和最后一列的宽度,对于第 6 列,我会使用
X
列类型,其宽度\textwidth
为其余列宽度的总和。 - 为了增大第六列的宽度,您可以减小它
colsep
。 - 如你所见,我在第六列居中插入了
tblr
表格-
\documentclass[twocolumn]{article}
\usepackage[showframe,
margin=2cm]{geometry}
\usepackage{lipsum} %for dummy text
\usepackage[dvipsnames,table]{xcolor}
\definecolor{light-gray}{HTML}{FFFFFF}
\definecolor{light-blue}{HTML}{EBF5FB}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\usepackage{tabulary,longtable,afterpage}
\usepackage{url}
\makeatletter
\newcommand{\aftertwo}[1]{\afterpage{\if@firstcolumn #1
\else\afterpage{#1}\fi}}
\makeatother
\begin{document}
% Some text
\lipsum[1-8]
% A "longtblr" table
\aftertwo{
\onecolumn
\begin{longtblr}[
caption = {This is a caption.},
]{colspec = {llll Q[l,22mm] X[h, j] Q[l, 3em] },
colsep=4pt,
column{6}={preto={\minipage{\linewidth}}, appto={\endminipage}},
cells={font=\small},
row{1}={font=\itshape\small},
row{2,5-7}={bg=light-blue},
row{3-4}={bg=light-gray},
hlines
}
& Day
& Month
& Hours
& Feature 1
& Feature 2
& Feature 3\\
%-------------------------------------------------
Friday
& 5
& June
&
& This is a quite short text.
& This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times.
\centering
\begin{tblr}{ |c|c|c| }
\hline
cell1 & cell2 & cell3 \\
cell4 & cell5 & cell6 \\
cell7 & cell8 & cell9 \\
\hline
\end{tblr}
& Short text \\
%-------------------------------------------------
\SetCell[r=2]{l} Saturday
& \SetCell[r=2]{l} 6
& \SetCell[r=2]{l} June
& 14 -- 21
& B\textsubscript{1}
&
& B\textsubscript{3}
\\
&
&
&
& C\textsubscript{1}
& C\textsubscript{2}
& C\textsubscript{3} \\
%--------------------------------------------------
\SetCell[r=3]{l} Sunday
& \SetCell[r=3]{l} 7
& \SetCell[r=3]{l} June
& 08 -- 10
& D\textsubscript{1}
& D\textsubscript{2}
& D\textsubscript{3}
\\
&
&
& 10 -- 17
& E\textsubscript{1}
&
& E\textsubscript{3}
\\
&
&
&
& F\textsubscript{1}
& F\textsubscript{2}
& F\textsubscript{3} \\
% -------------------------------------------------
\end{longtblr}
\twocolumn
}
% End of the document
\end{document}
灰线表示页面布局。