# How to create custom table environment with a possibility to merge cells

I'm trying to create a custom table environment that has the following properties:

• It may be very long (i.e., longer than a page) and so I need to use a longtable
• It may (or may not) have long row.

I'm having problems on the long row, this is what I got:

I'm understanding where I'm wrong. \multirow sets a piece of text in a tabular or similar environment, spanning multiple rows. If rows are smaller than a piece of text, we having this problem:

    \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}

\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{The way to achieve}
}}\\ \hline
\captionsetup{labelformat=continued}\caption{} \\
\hline
}} & \thead[c]{\parbox{0.145455\textwidth}{\textbf{The way to achieve}
}}\\ \hline
& 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}


I have tried use table in table and this method is suitable for this table,

    \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}

\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{The way to achieve}
}}\\ \hline
\captionsetup{labelformat=continued}\caption{} \\
\hline
}} & \thead[c]{\parbox{0.145455\textwidth}{\textbf{The way to achieve}
}}\\ \hline
& 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}


but the document has tables of a different kind for which it does not fit. For example:

    \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}

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


What can I do?

• Welcome to TeX.SE. In its current form, your code isn't compilable, forcing would-be answer providers to guess which document class ought to be used, which LaTeX packages should be loaded, and which fonts should be employed. Such guesswork is not likely to be all that accurate. Also, how or were is the page style uspdlandheadings defined? Is the page style issue even relevant? Hence, please provide more information about your document setup.
– Mico
Aug 2, 2018 at 7:36
• as far as i can understand your question, there is no need to define new table environment. it be sufficient to proper use of existed ones and remove all clutters from your code. Aug 2, 2018 at 7:38
• Don't use \multirow to merge multiple rows if it's only one column having more than one row. Instead use something like \begin{tabular}{@{}p{0.145455\linewidth}@{}} First row in that column \\\hline Second row in that column\end{tabular} Aug 2, 2018 at 7:43
• And don't spam so many rules. Tables tend to look better if there are less rules (3 rules are sufficient most of the time). Aug 2, 2018 at 7:44

an alternative solution for your first table:

• for table is exploited all available width of text
• multirow cells are not used,
• since cells in third columns remains me on list, they are merged in one cell containing list. lists can have bullets, but they can be also without it
• for lists is defined new column type I (itemize)

result without bullets at used lists:

and with bullets:

\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
\caption*{Table~\thetable: Tabel 1}
\label{tab:Tabel1}  \\
\toprule
\mch{Purpose}
&   \mch{Description}
&   \mch{Where is\\ reflected}
&   \mch{The way to\\ achieve}      \\
\midrule
\midrule
\endfoot
\bottomrule
\endlastfoot
&   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
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
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}

• Nice idea to use itemize. Aug 2, 2018 at 11:07

One possibility to typeset your first table:

\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
\toprule
Purpose & Description & Where is reflected & The way to achieve\\
\midrule
& 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}


• Thanks! Good idea. I've learned "Publication quality tables in LATEX". It's real great package, but I need all rules in the tables. This is government standard's requirement. Aug 3, 2018 at 13:16