如何创建可合并单元格的自定义表格环境

如何创建可合并单元格的自定义表格环境

我正在尝试创建具有以下属性的自定义表环境:

  • 它可能很长(即超过一页),所以我需要使用 longtable
  • 它可能有(也可能没有)长排。

我在长排上遇到了问题,这就是我得到的: 在此处输入图片描述

我知道我错在哪里了。 \multirow 在表格或类似环境中设置一段文本,跨越多行。如果行小于一段文本,我们会遇到这个问题:

    \documentclass[a4paper,14pt]{extarticle}
    \usepackage{amsmath}
    \usepackage{mathtext}
    \usepackage[T2A]{fontenc}
    \usepackage[russian]{babel}
    \usepackage{g0019}
    \usepackage{supertabular}
    \usepackage{graphics}
    \usepackage{float}
    \usepackage{caption}
    \usepackage{multirow}
    \usepackage{makecell}
    \input{glyphtounicode}
    \pdfgentounicode=1  
    \usepackage{pdflscape}
    \usepackage{gensymb}
    \usepackage{longtable} 
    \usepackage[normalem]{ulem}
    \usepackage{moresections}
    \usepackage{textcomp}
    \usepackage{array}
    \usepackage{rotating}
    \usepackage{ifthen}
    \usepackage{anyfontsize}
    \usepackage{ragged2e}
    \usepackage{indentfirst}
    \usepackage{setspace}

    %% Captions setup
    \DeclareCaptionLabelFormat{gosttable}{Table #2} 
    \DeclareCaptionLabelFormat{continued}{Continued table #2}
    \DeclareCaptionLabelSeparator{gost}{~---~}
    \captionsetup{labelsep=gost}
    \captionsetup[table]{labelformat=gosttable, margin={6ex,0pt}, indention=-5ex}

    \begin{document}

    \renewcommand\theadfont{\normalsize\scshape}
    \begin{landscape}
    \begin{longtable}[c]{|p{0.145455\linewidth}|p{0.381818\linewidth}|p{0.145455\linewidth}|p{0.145455\linewidth}|}
    \caption{Tabel 1} 
    \label{tab:Tabel1}  \\ 
    \hline
    \thead[c]{\parbox{0.145455\textwidth}{\textbf{Purpose}
    }} & \thead[c]{\parbox{0.381818\textwidth}{\textbf{Description}
    }} & \thead[c]{\parbox{0.145455\textwidth}{\textbf{Where is reflected}
    }} & \thead[c]{\parbox{0.145455\textwidth}{\textbf{The way to achieve}
    }}\\ \hline 
    \endfirsthead
    \captionsetup{labelformat=continued}\caption{} \\
    \hline
    \thead[c]{\parbox{0.145455\textwidth}{\textbf{Цель}
    }} & \thead[c]{\parbox{0.381818\textwidth}{\textbf{Description}
    }} & \thead[c]{\parbox{0.145455\textwidth}{\textbf{Where is reflected}
    }} & \thead[c]{\parbox{0.145455\textwidth}{\textbf{The way to achieve}
    }}\\ \hline 
    \endhead
    Consider additional questions
     & If necessary, consider additional aspects of development, such as the use of previously developed software, attestation of tools
     & Software Transfer Plan 
     & Reflect decisions taken in the plans
    \\ \hline 
    \multirow[lt]{3}{*}{\begin{minipage}{\linewidth}Identify software development standards
    \vspace*{0pt} 
     \end{minipage}} & \multirow[lt]{3}{*}{\begin{minipage}{\linewidth}Identify development standards that will provide security requirements for the system in terms of the software being developed
    \vspace*{0pt} 
    \end{minipage}} & Standards for the development of software requirements
     & \multirow[lt]{3}{*}{\begin{minipage}{\linewidth}Three standards have been developed
    \vspace*{0pt} 
     \end{minipage}}\\* \cline{3-3} 
     &  & Standards for the software design process
     & \\* \cline{3-3} 
     &  & Standards for software encoding
     & \\ \hline 
    \multirow[lt]{2}{*}{\begin{minipage}{\linewidth}Coordination of software development plans
    \vspace*{0pt} 
    \end{minipage}} & \multirow[lt]{2}{*}{\begin{minipage}{\linewidth} Coordinate the development and modification of software plans. The results of the software planning process are monitored to ensure that the software plans and software development standards meet the requirements of this standard and ensure the coherent implementation of the software lifecycle processes  
    \vspace*{0pt} 
     \end{minipage}} & Software Quality Assurance Protocols  
     & \multirow[lt]{2}{*}{\begin{minipage}{\linewidth} Report the verification results in the Verification Report
    \vspace*{0pt} 
     \end{minipage}}\\* \cline{3-3} 
     &  & Results of software verification  
     & \\ \hline 
    \end{longtable} 
    \end{landscape} 
    \end{document}

我已经尝试过在表中使用表格,并且这种方法适合这个表格, 在此处输入图片描述

    \documentclass[a4paper,14pt]{extarticle}
    \usepackage{amsmath}
    \usepackage{mathtext}
    \usepackage[T2A]{fontenc}
    \usepackage[russian]{babel}
    \usepackage{g0019}
    \usepackage{supertabular}
    \usepackage{graphics}
    \usepackage{float}
    \usepackage{caption}
    \usepackage{multirow}
    \usepackage{makecell}
    \input{glyphtounicode}
    \pdfgentounicode=1  
    \usepackage{pdflscape}
    \usepackage{gensymb}
    \usepackage{longtable} 
    \usepackage[normalem]{ulem}
    \usepackage{moresections}
    \usepackage{textcomp}
    \usepackage{array}
    \usepackage{rotating}
    \usepackage{ifthen}
    \usepackage{anyfontsize}
    \usepackage{ragged2e}
    \usepackage{indentfirst}
    \usepackage{setspace}

    %% Captions setup
    \DeclareCaptionLabelFormat{gosttable}{Table #2} 
    \DeclareCaptionLabelFormat{continued}{Continued table #2}
    \DeclareCaptionLabelSeparator{gost}{~---~}
    \captionsetup{labelsep=gost}
    \captionsetup[table]{labelformat=gosttable, margin={6ex,0pt}, indention=-5ex}

    \begin{document}

    \renewcommand\theadfont{\normalsize\scshape}

    \begin{landscape}
    \begin{longtable}[c]{|p{0.145455\linewidth}|p{0.381818\linewidth}|p{0.145455\linewidth}|p{0.145455\linewidth}|}
    \caption{Процесс планирования ПО} 
    \label{tab:ПроцесспланированияПО}  \\ 
    \hline
    \thead[c]{\parbox{0.145455\textwidth}{\textbf{Purpose}
    }} & \thead[c]{\parbox{0.381818\textwidth}{\textbf{Description}
    }} & \thead[c]{\parbox{0.145455\textwidth}{\textbf{Where is reflected}
    }} & \thead[c]{\parbox{0.145455\textwidth}{\textbf{The way to achieve}
    }}\\ \hline 
    \endfirsthead
    \captionsetup{labelformat=continued}\caption{} \\
    \hline
    \thead[c]{\parbox{0.145455\textwidth}{\textbf{Цель}
    }} & \thead[c]{\parbox{0.381818\textwidth}{\textbf{Description}
    }} & \thead[c]{\parbox{0.145455\textwidth}{\textbf{Where is reflected}
    }} & \thead[c]{\parbox{0.145455\textwidth}{\textbf{The way to achieve}
    }}\\ \hline 
    \endhead
    Consider additional questions
    & If necessary, consider additional aspects of development, such as the use of previously developed software, attestation of tools
    & Software Transfer Plan 
    & Reflect decisions taken in the plans
    \\ \hline
    {\begin{minipage}{\linewidth}Identify software development standards 
    \vspace*{0pt} 
     \end{minipage} & {\begin{minipage}{\linewidth}dentify development standards that will provide security requirements for the system in terms of the software being developed 
    \vspace*{0pt} 
     \end{minipage} & \begin{minipage}{\linewidth}
    \begin{tabular}{p{\textwidth}@{\hskip 0cm}}
    Standards for the development of software requirements \\ \hline 
    Standards for the software design process \\ \hline 
    Standards for software encoding  
    \end{tabular} 
    \end{minipage} & {\begin{minipage}{\linewidth}Three standards have been developed 
    \vspace*{0pt} 
     \end{minipage} 
    \\ \hline 
    {\begin{minipage}{\linewidth}Coordination of software development plans 
    \vspace*{0pt} 
     \end{minipage} & {\begin{minipage}{\linewidth}Coordinate the development and modification of software plans. The results of the software planning process are monitored to ensure that the software plans and software development standards meet the requirements of this standard and ensure the coherent implementation of the software lifecycle processe 
    \vspace*{0pt} 
    \end{minipage} & \begin{minipage}{\linewidth}
    \begin{tabular}{p{\textwidth}@{\hskip 0cm}}
    Software Quality Assurance Protocols \\ \hline  
    Results of software verification
    \end{tabular} 
    \end{minipage} & {\begin{minipage}{\linewidth}Report the verification results in the Verification Report 
    \vspace*{0pt} 
    \end{minipage}
    \ \hline 
    \end{longtable} 
    \end{document}

但文档中有不适合的不同类型的表格。例如: 在此处输入图片描述

    \documentclass[a4paper,14pt]{extarticle}
    \usepackage{amsmath}
    \usepackage{mathtext}
    \usepackage[T2A]{fontenc}
    \usepackage[russian]{babel}
    \usepackage{g0019}
    \usepackage{supertabular}
    \usepackage{graphics}
    \usepackage{float}
    \usepackage{caption}
    \usepackage{multirow}
    \usepackage{makecell}
    \input{glyphtounicode}
    \pdfgentounicode=1  
    \usepackage{pdflscape}
    \usepackage{gensymb}
    \usepackage{longtable} 
    \usepackage[normalem]{ulem}
    \usepackage{moresections}
    \usepackage{textcomp}
    \usepackage{array}
    \usepackage{rotating}
    \usepackage{ifthen}
    \usepackage{anyfontsize}
    \usepackage{ragged2e}
    \usepackage{indentfirst}
    \usepackage{setspace}

    %% Captions setup
    \DeclareCaptionLabelFormat{gosttable}{Table #2} 
    \DeclareCaptionLabelFormat{continued}{Continued table #2}
    \DeclareCaptionLabelSeparator{gost}{~---~}
    \captionsetup{labelsep=gost}
    \captionsetup[table]{labelformat=gosttable, margin={6ex,0pt}, indention=-5ex}

    \begin{document}

    \renewcommand\theadfont{\normalsize\scshape}

    \begin{longtable}[c]{|p{0.300000\linewidth}|@{}p{0.300000\linewidth}|@{}p{0.300000\linewidth}|}
    \caption{table 2} 
    \label{tab:table2}  \\ 
    \hline
    \multicolumn{2}{|c|}{\thead{\textbf{Options}
    }}  & \multirowthead{2}{\parbox{0.300000\textwidth}{\centering \textbf{The project to develop on-board software}
    }}\\* \cline{1-2} 
    \thead[c]{\parbox{0.300000\textwidth}{\textbf{Area}
    }} & \thead[c]{\parbox{0.300000\textwidth}{\textbf{Field name}
    }} & \\ \hline 
    \endfirsthead
    \captionsetup{labelformat=continued}\caption{} \\
    \hline
    \multicolumn{2}{|c|}{\thead{\textbf{Options}
    }}  & \multirowthead{2}{\parbox{0.300000\textwidth}{\centering \textbf{The project to develop on-board software}
    }}\\* \cline{1-2} 
    \thead[c]{\parbox{0.300000\textwidth}{\textbf{Area}
    }} & \thead[c]{\parbox{0.300000\textwidth}{\textbf{Field name}
    }} & \\ \hline 
    \endhead
    \begin{minipage}{\linewidth}Information \vspace*{0pt} 
    \end{minipage}& \begin{minipage}{\linewidth}
    \begin{tabular}{p{\textwidth}@{\hskip 0cm}} 
    Description \\ 
    \hline
    Object's Unique identificator \\ 
    \hline
    Home page \\ 
    \hline
    Public \\ 
    \hline
    Parent project \\ 
    \hline
    Inherit participants
    \end{tabular} 
    \end{minipage}
    \hline
    \end{longtable} 
    \end{document}

我能做些什么?

答案1

第一张表的替代解决方案:

  • 对于表格,利用文本的所有可用宽度
  • multirow不使用细胞,
  • 由于第三列中的单元格仍保留在列表中,因此它们合并到一个包含列表的单元格中。列表可以有项目符号,但也可以没有项目符号
  • 为列表定义了新的列类型I(itemize)

使用列表中没有项目符号的结果:

在此处输入图片描述

并附有项目符号:

在此处输入图片描述

\documentclass[a4paper,12pt]{article} % <--
\usepackage{caption}
\usepackage{ragged2e}
\usepackage{enumitem}
\usepackage[utf8]{inputenc}
\usepackage{array,booktabs, longtable}
\newcolumntype{P}[1]{>{\RaggedRight}p{#1}}

% added packages and column definitions
\usepackage{enumitem}       % for nice list
\newlist{tabitemize}{itemize}{1}% <-- defined new list
\setlist[tabitemize]{topsep =0pt,     % <-- new list setup
                     itemsep=3pt,
                     leftmargin = *,
                     %  label      = {}, % uncomment if you don't like to have bullets
                     label  = $\bullet$ ,%   comment if you don't like to have bullets
                     before = \vspace{-\baselineskip},
                     after  = \vspace{-\baselineskip}
                     }
\newcolumntype{I}[1]{>{\RaggedRight\tabitemize} p{#1}<{\endtabitemize}}
\newcommand\mch[1]{\multicolumn{1}%
                               {>{\scshape}c}%
                               {\begin{tabular}{c}#1\end{tabular}}}  % <-- for columns headers
\usepackage{pdflscape}
\begin{document}

\begin{landscape}
\setlength\tabcolsep{4pt}
\begin{longtable}{@{}
                  P{\dimexpr0.15\linewidth-2\tabcolsep-1.25\arrayrulewidth}
                  P{\dimexpr0.40\linewidth-2\tabcolsep-1.25\arrayrulewidth}
                  I{\dimexpr0.25\linewidth-2\tabcolsep-1.25\arrayrulewidth}
                  P{\dimexpr0.20\linewidth-2\tabcolsep-1.25\arrayrulewidth}
                  @{}
                  }
\caption{Tabel 1}
\label{tab:Tabel1}  \\
    \toprule
\mch{Purpose}
    &   \mch{Description}
        &   \mch{Where is\\ reflected}
            &   \mch{The way\\ to achieve}      \\
  \midrule
\endfirsthead
\caption*{Table~\thetable: Tabel 1}
\label{tab:Tabel1}  \\
    \toprule
\mch{Purpose}
    &   \mch{Description}
        &   \mch{Where is\\ reflected}
            &   \mch{The way to\\ achieve}      \\
  \midrule
\endhead
    \midrule
\endfoot
    \bottomrule
\endlastfoot
Consider additional questions
    &   If necessary, consider additional aspects of development, such as the use of previously developed software, attestation of tools
        &   \item   Software Transfer Plan
            & Reflect decisions taken in the plans
    \\ \addlinespace[9pt]
Identify software development standards
    & Identify development standards that will provide security requirements for the system in terms of the software being developed
        &   \item   Three standards have been developed
            \item   Standards for software design process
            \item   Standards for software encoding
            & Standards for the development of software requirements
    \\  \addlinespace[9pt]
Coordination of software development plans
    &   Coordinate the development and modification of software plans. The results of the software planning process are monitored to ensure that the software plans and software development standards meet the requirements of this standard and ensure the coherent implementation of the software lifecycle processes
        &   \item   Software Quality Assurance Protocols
            \item   Results of software verification
            & Report the verification results in the Verification Report
    \\
\end{longtable}
\end{landscape}

答案2

排版第一个表格的一种可能性是:

\documentclass[]{article}

\usepackage[]{longtable}
\usepackage{lscape}
\usepackage{booktabs}
\usepackage{array}

\newif\ifInMyOnecell
\newcommand\myonecell[2]
  {\InMyOnecelltrue\begin{tabular}[t]{@{} #1 @{}}#2\end{tabular}}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\newcommand*\nextrow{\\\noalign{\ifInMyOnecell\smallskip\else\medskip\fi}}

\begin{document}
    \begin{landscape}
    \begin{longtable}[c]
      {
        L{0.145455\linewidth}
        p{0.37\linewidth}
        L{0.25\linewidth}
        L{0.145455\linewidth}
      }
    \caption{Tabel 1} 
    \label{tab:Tabel1}  \\ 
    \toprule
    Purpose & Description & Where is reflected & The way to achieve\\
    \midrule 
    \endfirsthead
    \toprule
    Purpose & Description & Where is reflected & The way to achieve\\
    \midrule 
    \endhead
    Consider additional questions
      & If necessary, consider additional aspects of development, such as the
        use of previously developed software, attestation of tools
      & Software Transfer Plan 
      & Reflect decisions taken in the plans
    \nextrow
    Identify software development standards
      & Identify development standards that will provide security requirements
        for the system in terms of the software being developed
      & \myonecell{L{\linewidth}}
          {%
            Standards for the development of software requirements
            \nextrow
            Standards for the software design process
            \nextrow
            Standards for software encoding
          }
      & Three standards have been developed
    \nextrow
    Coordination of software development plans
      & Coordinate the development and modification of software plans. The
        results of the software planning process are monitored to ensure that
        the software plans and software development standards meet the
        requirements of this standard and ensure the coherent implementation of
        the software lifecycle processes
      & \myonecell{L{\linewidth}}
          {%
            Software Quality Assurance Protocols
            \nextrow
            Results of software verification  
          }
       & Report the verification results in the Verification Report
    \\
    \bottomrule
  \end{longtable} 
\end{landscape}

\end{document}

在此处输入图片描述

相关内容