問題與MWE

問題與MWE

問題與MWE

我想將下longtblr表的寬度增加到允許的最大頁面寬度,我猜它應該與文字一樣寬,即從頁面的左邊距到右邊距。換句話說,我想讓下表從左邊距到右邊距與文字一樣寬。

但是,我會有一個限制。我想保持相同的後續列的寬度

colspec={m{0.9cm} m{0.1cm} m{0.6cm} m{1cm} m{3cm} m{6cm} m{1.5cm}},

除了第六列(稱為Feature 2),它現在6cm很寬。因此,我們的想法是只使用第 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 列的寬度。在你的情況下,我會減少 zje 第五列和最後一列的寬度,對於第六列,我將使用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}

在此輸入影像描述

灰線表示頁面佈局。

相關內容