5

I currently have this table:

\begin{table}
\centering
\begin{tabular}{ |c|c| }
\hline
no test & no test \\
\hline
no test & \begin{tabular}{c|c} D1 & 1.23 \\ \hline D2 & 1.23 \\ \end{tabular} \\
\hline
\end{tabular}
\end{table} 

Giving:

enter image description here

hline in the nested tabular does not span the entire cell width.

Of course multirow/multicolumn would be a choice. However, this is a "mutable" table, to which I will need to add "sub-rows" each time new data arrives, but I do not know in advance where. So, it could become something like:

enter image description here

For such purpose, multirow/multicolumn seems that would require constantly changing their row/column numbers.

How can this be solved in such a way that minimizes the work each time a new "sub-row" is added?

Thanks.

1

3 Answers 3

7

Something like this:

enter image description here

For this you need to eliminate table column separation in column in which you nested table. This is done with use of @{}:

\begin{table}
\centering
\begin{tabular}{ |c|@{}c@{}| }% <-- aded @{}
\hline
no test & no test \\
\hline
no test & 
    \begin{tabular}{c|c} D1 & 1.23 \\ \hline D2 & 1.23 \\ \end{tabular} \\
\hline
\end{tabular}
\end{table}
2

Just replace in the main table preamble c with @{}c@{} for each column which contains a nested tabular. Note this requires the array package.

I also improved the table loading the cellspace package, which defines minimal vertical padding between a row and the above and below cells in columns with a specifier prefixed by the letter S:

\documentclass[11pt]{article}

\usepackage[utf8]{inputenc}
\usepackage{array}

\begin{document}

\begin{table}
\centering
\begin{tabular}{ |c|@{}c@{}| }
\hline
no test & no test \\
\hline
no test & \begin{tabular}{c|c} D1 & 1.23 \\ \hline D2 & 1.23 \\ \end{tabular} \\
\hline
\end{tabular}
\end{table}

\end{document}

enter image description here

0

Here is a way to create that tabular with {NiceTabular} of nicematrix.

In {NiceTabular}, you merge cells both horizontally and vertically with the command \Block. With the key hvlines, all the rules are drawn, except in the blocks (constructed by \Block).

\documentclass[10pt]{article}
\usepackage{geometry}
\usepackage{nicematrix}

\begin{document}

\begin{center}
\renewcommand{\arraystretch}{1.4}
\begin{NiceTabular}{cccc}[hvlines]
A1 & 1.23 & \Block{2-2}{no test} \\
A2 & 1.23 \\
\Block{3-2}{no test} && D1 & 1.23 \\
                     && D1 & 1.23 \\
                     && D1 & 1.23 \\
\end{NiceTabular}
\end{center}

\end{document}

You need several compilations (because nicematrix uses PGF/TikZ nodes under the hood).

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .