具有不同行和列样式的长表

具有不同行和列样式的长表

我今天早些时候问过一个类似的问题;谢谢大家给我答案。由于我的问题仅限于表格的前三行,我在为其他行编写代码时遇到了困难,因为行和列的样式发生了变化。由于这花费了我很多时间,我请求你们帮我制作如图所示的表格(左边或右边,以可能为准)。

最后两列的文本是示例文本;实际文本很长。因此表格大约有 3 页。

以下是示例工作代码:

在此处输入图片描述

\begin{table}[htbp]
  \centering
  \caption{Add caption}
    \begin{tabular}{|l|p{6.72em}|p{15.335em}|l|}
    \toprule
    \multicolumn{2}{|c|}{\textbf{RIBA Work Stage}} & \multicolumn{1}{c|}{\textbf{Description of Key Tasks}} & \multicolumn{1}{c|}{\textbf{Core BIM Activities}} \\
    \midrule
    \multicolumn{1}{|c|}{\multirow{2}[4]{*}{\begin{sideways}\textbf{Preparation}\end{sideways}}} & \multicolumn{1}{c|}{\textbf{Appraisal}} & Task desciption for Appraisal & \multicolumn{1}{l|}{\multirow{2}[4]{*}{• BIM Activity 1\newline{}• BIM Activity 2\newline{}• Data drop 1}} \\
\cmidrule{2-3}          & \multicolumn{1}{c|}{\textbf{Design Brief}} & Task desciption for Design Brief &  \\
    \midrule
    \multicolumn{1}{|c|}{\multirow{3}[6]{*}{\begin{sideways}\textbf{Design}\end{sideways}}} & \multicolumn{1}{c|}{\textbf{Concept}} & Task desciption for Concept & \multicolumn{1}{p{11.665em}|}{• BIM Activity 1\newline{}• BIM Activity 2\newline{}• Data drop 2} \\
\cmidrule{2-4}          & \textbf{Design Development} & Task desciption for Design Development & \multicolumn{1}{l|}{\multirow{2}[4]{*}{• BIM Activity 1\newline{}• BIM Activity 2\newline{}• Data drop 3}} \\
\cmidrule{2-3}          & \textbf{Technical Design} & Task desciption for Technical Design &  \\
    \midrule
    \multicolumn{1}{|c|}{\multirow{3}[6]{*}{\begin{sideways}\textbf{Pre-Construction}\end{sideways}}} & \textbf{Production Information} & Task desciption for Production Information & \multicolumn{1}{l|}{\multirow{3}[6]{*}{• BIM Activity 1\newline{}• BIM Activity 2\newline{}• Data drop 4}} \\
\cmidrule{2-3}          & \textbf{Tender Documentation} & Task desciption for Tender Documentation &  \\
\cmidrule{2-3}          & \textbf{Tender Action} & Task desciption for Tender Action &  \\
    \midrule
    \multicolumn{1}{|c|}{\multirow{2}[4]{*}{\begin{sideways}\textbf{Construction}\end{sideways}}} & \multicolumn{1}{c|}{\textbf{Mobilisation}} & \multicolumn{1}{l|}{Task desciption for Mobilisation} & \multicolumn{1}{l|}{\multirow{2}[4]{*}{• BIM Activity 1\newline{}• BIM Activity 2\newline{}• Data drop 5}} \\
\cmidrule{2-3}          & \textbf{Construction to Practical Completion} & Task desciption for Construction to Practical Completion &  \\
    \midrule
    \begin{sideways}\textbf{Use}\end{sideways} & \textbf{Post Practical Completion} & Task desciption for Post Practical Completion & \multicolumn{1}{l|}{\multirow{2}[4]{*}{• BIM Activity 1\newline{}• BIM Activity 2\newline{}• Data drop 6}} \\
\cmidrule{1-3}    \begin{sideways}\textbf{R \& D}\end{sideways} & \textbf{Model Maintenance \& Development} & Task desciption for Model Maintenance \& Development &  \\
    \bottomrule
    \end{tabular}%
  \label{tab:addlabel}%
\end{table}%

答案1

可以在多页表中使用我之前的答案中的代码。只需将外部表更改为长桌而不是表格,并按照手册中的说明定义标题和第一个标题。但是,请注意,由于我使用嵌套表格来拆分单元格,因此分页符将位于我所谓的部分之间,IE. 它可能最多移动三行。如果部分内的文本很长,则页面底部可能会出现大量空白。

我成功地实现了更好的整体对齐,但不得不放弃(至少暂时)第 2 行文本的垂直居中。第一个旋转的文本粘在上面的行中,但我认为你会添加更多文本,所以这个问题会自行解决。如果没有,只需删除\raisebox,即使用:

\rotatebox[origin=c]{90}{Preparation} 

我进一步更新和精简了代码,但它仍然相当复杂,因为在两列和三列和行之间切换了好几次。此外,我定义了一些新的列类型,使表格前言更具可读性。

注意!当您填写更多文本时,您必须手动调整第一列中旋转文本的垂直对齐方式:

 \raisebox{0pt}[0pt][0pt]{\rotatebox[origin=c]{90}{Preparation}} & 
 \multicolumn{2}{c}{\begin{tabular}[t]{@{}>{\bfseries}MZ@{}}

增加第一个参数的值,直到\raisebox{0pt}适合为止。如您所见,如果您小心谨慎,它可以很好地适应分页。

在此处输入图片描述在此处输入图片描述

\documentclass{article}
\usepackage{array, booktabs, longtable}
\usepackage{enumitem}
\usepackage{array}
\usepackage{rotating}
\usepackage{geometry}

\newcolumntype{N}{>{\bfseries}p{0.3cm}}
\newcolumntype{M}{>{\raggedright}p{3cm}}
\newcolumntype{Z}{p{4.75cm}}
\newcolumntype{L}{p{5cm}}

\begin{document}

\begin{longtable}{@{}NMZL@{}}
\caption{Add caption\label{tab:addlabeladd}}\\
\toprule
&
\small\bfseries RIBA Work Stage &
\small\bfseries Description of Key Tasks &
\small\bfseries Core BIM Activities\\ \midrule
\endfirsthead

%\toprule
%&
%\small\bfseries RIBA Work Stage &
%\small\bfseries Description of Key Tasks &
%\small\bfseries Core BIM Activities\\ \midrule
\midrule
\endhead


%%% Section 1
\raisebox{0pt}[0pt][0pt]{\rotatebox[origin=c]{90}{Preparation}} & 
\multicolumn{2}{c}{\begin{tabular}[t]{@{}>{\bfseries}MZ@{}}
    Appraisal &
    Task desciption for Appraisal\\ \midrule
    Design Brief &
    Task desciption for Design Brief.\\
\end{tabular}}&
\begin{minipage}[t]{5cm}
    \begin{itemize}[labelsep=*, leftmargin=*, nosep]
    \item BIM Activity 1
    \item BIM Activity 2
    \item Data drop 1
    \end{itemize}
\end{minipage}\\
\midrule

%%% Section 2A
& 
\textbf{Concept} &
Task desciption for Concept
&
\begin{minipage}[t]{\hsize}
    \begin{itemize}[labelsep=*, leftmargin=*, nosep]
    \item BIM Activity 1. Here we add some text. And event more text, and more.
    \item BIM Activity 2. Here we add some text. And event more text, and more.
    \item BIM Activity 3. Here we add some text. And event more text, and more.
    \item Data drop 2
    \end{itemize}
\end{minipage}\\\cmidrule{2-3}
%%% Section 2B
\raisebox{\normalbaselineskip}[0pt][0pt]{\rotatebox[origin=c]{90}{Design}} & 
\multicolumn{2}{c}{\begin{tabular}[t]{@{}>{\bfseries}MZ@{}}
    Design Development &
    Task desciption for Design Development \\ \midrule
    Technical Design &
    Task desciption for Technical Design \\
\end{tabular}}&
\begin{minipage}[t]{\hsize}
    \begin{itemize}[labelsep=*, leftmargin=*, nosep]
    \item BIM Activity 1
    \item BIM Activity 2
    \item Data drop 3
    \end{itemize}
\end{minipage}\\
\midrule

%%% Section 3
\raisebox{-50pt}[0pt][0pt]{\rotatebox[origin=c]{90}{\mbox{Pre-Construction}}}
& 
\multicolumn{2}{c}{\begin{tabular}[t]{@{}>{\bfseries}MZ@{}}
    Production Information &
    Task desciption for Production Information \\ \midrule
    Tender Documentation&
    Task desciption for Tender Documentation\\ \midrule
    Tender Action &
    Task desciption for Tender Action \\
\end{tabular}}&
\begin{minipage}[t]{\hsize}
    \begin{itemize}[labelsep=*, leftmargin=*, nosep]
    \item BIM Activity 1. Here we add some text. And event more text, and more.
    \item BIM Activity 2. Here we add some text. And event more text, and more.
    \item BIM Activity 3. Here we add some text. And event more text, and more.
    \item Data drop 4
    \end{itemize}
\end{minipage}\\
\midrule

%%% Section 4
\raisebox{-50pt}[0pt][0pt]{\rotatebox[origin=c]{90}{Construction}} & 
\multicolumn{2}{@{}c@{}}{\begin{tabular}[t]{@{}>{\bfseries}MZ@{}}
    Mobilisation &
    Task desciption for Mobilisation \\ \midrule
    Construction to Practical  Completion&
    Task desciption for Construction to Practical  Completion\\
\end{tabular}}&
\begin{minipage}[t]{\hsize}
    \begin{itemize}[labelsep=*, leftmargin=*, nosep]
    \item BIM Activity 1. Here we add some text. And event more text, and more.
    \item BIM Activity 2. Here we add some text. And event more text, and more.
    \item BIM Activity 3. Here we add some text. And event more text, and more.
    \item Data drop 5
    \end{itemize}
\end{minipage}\\
\midrule

%%% Section 5
\multicolumn{3}{@{}c@{}}{\begin{tabular}[t]{@{}N>{\bfseries}MZ@{}}
\raisebox{-5pt}[0pt][0pt]{\rotatebox[origin=c]{90}{Use}} & 
    Practical  Completion &
    Task desciption for Practical  Completion \\ \midrule
\raisebox{-15pt}[0pt][0pt]{\rotatebox[origin=c]{90}{R\&D}} & 
    Model Maintenance \& Developement&
    Task desciption for Model Maintenance \& Developement\\
\end{tabular}}&

\begin{minipage}[t]{\hsize}
    \begin{itemize}[labelsep=*, leftmargin=*, nosep]
    \item BIM Activity 1. Here we add some text. And event more text, and more.
    \item BIM Activity 2. Here we add some text. And event more text, and more.
    \item Data drop 6
    \end{itemize}
\end{minipage}\\
\midrule

\end{longtable}%

\end{document}

答案2

我会根据对您上一个问题的回答重新设计您的表格。与它相比,我会tabularxxltabular第一列的内容替换它并将其移到新行中:

\documentclass{article}
\usepackage{ragged2e}
\usepackage{booktabs, makecell, multirow, xltabular}
\renewcommand\theadfont{\bfseries}
\renewcommand\theadgape{}
\newcolumntype{R}{>{\RaggedRight}X}
\newcommand\mcc[1]{\multicolumn{3}{c}{\emph{#1}}}
\usepackage{enumitem}

\begin{document}
    \begingroup
\setlist[itemize]{nosep, wide,
                  before=\vspace{-\baselineskip},
                  after=\vspace{-\baselineskip}
                  }
\begin{xltabular}{\linewidth}{@{} >{\small\bfseries%
                                    \raggedright\arraybackslash%
                                    \hsize=0.5\hsize}X
                                  >{\hsize=0.8\hsize}R
                                  >{\hsize=0.7\hsize}R
                              @{}}
% table preamble
\caption{Add caption}
\label{tab:addlabel}                        \\
    \toprule
\thead{RIBA\\ Work Stage}
    &   \thead{Description of\\ Key Tasks}
        &   \thead{Core BIM\\Activities}    \\
    \midrule
\endfirsthead
\caption[]{Add caption (cont.)}                       \\
    \toprule
\thead{RIBA\\ Work Stage}
    &   \thead{Description of\\ Key Tasks}
        &   \thead{Core BIM\\Activities}    \\
    \midrule
\endhead
\multicolumn{3}{r}{\footnotesize\textit{continue on the next page}}\\*
\endfoot
    \bottomrule
\endlastfoot
% table body
    \mcc{Preparation}                       \\
    \cmidrule{1-3}
Appraisal
    &   Task desciption for Appraisal 
        &   \multirow{2}{=}{%
            \begin{itemize}
        \item   BIM Activity 1
        \item   BIM Activity 2
        \item   Data drop 1
            \end{itemize}   }       \\
    \addlinespace[6pt]          
Design Brief
    &   Task desciption for Design Brief 
         &                           \\
    \midrule
    \mcc{Design}                    \\
    \cmidrule{1-3}
Concept
    &   Task desciption for Concept
        \vspace{2\baselineskip}
        &   \multirow{2}{=}{%
            \begin{itemize}
        \item   BIM Activity 1
        \item   BIM Activity 2
        \item   Data drop 2
            \end{itemize}   }       \\
    \addlinespace[6pt]
Design Development
    & Task desciption for Design Development
        &   \multirow{2}{=}{%
            \begin{itemize}
        \item   BIM Activity 1
        \item   BIM Activity 2
        \item   Data drop 3
            \end{itemize}   }       \\
    \addlinespace[6pt]
Technical Design
    & Task desciption for Technical Design 
        &                           \\
    \midrule
    \mcc{Pre-Construction}          \\
    \cmidrule{1-3}
 Production Information
    & Task desciption for Production Information 
        &   \multirow{2}{=}{%
            \begin{itemize}
        \item   BIM Activity 1
        \item   BIM Activity 2
        \item   Data drop 4
            \end{itemize}   }       \\
    \addlinespace[6pt]
Tender Documentation
    & Task desciption for Tender Documentation 
        &                           \\
Tender Action
    & Task desciption for Tender Action 
        &                           \\
    \midrule
    \mcc{Construction}              \\
    \cmidrule{1-3}
Mobilisation
    &   Task desciption for Mobilisation
        &   \multirow{2}{=}{%
            \begin{itemize}
        \item   BIM Activity 1
        \item   BIM Activity 2
        \item   Data drop 5
            \end{itemize}   }       \\
    \addlinespace
Construction to Practical Completion
    &   Task desciption for Construction to Practical Completion 
        &                           \\
    \midrule
    \mcc{Use}                       \\
    \cmidrule{1-3}
Post Practical Completion
    &   Task desciption for Post Practical Completion 
        \vspace{1\baselineskip}
        &   \multirow{2}{=}{%
            \begin{itemize}
        \item   BIM Activity 1
        \item   BIM Activity 2
        \item   Data drop 6
            \end{itemize}   }       \\
    \midrule
\pagebreak  \\
    \mcc{R \& D}                    \\
    \cmidrule{1-3}
Model Maintenance \& Development
    & Task desciption for Model Maintenance \& Development 
        &                           \\
\end{xltabular} 
    \endgroup
\end{document}

在上面的 MWE 中,您可以看到,一些单元格被添加了\vspace{...\baselineskip}。当单元格的高度小于下一列包含itemize列表的多行单元格的高度时,将增加该单元格的高度。这将禁止列表突出到下一行。

在此处输入图片描述

在此处输入图片描述

相关内容