1

I want to draw a multicolumn table, such that for every row, the second and third columns are divided into two parts, and there is a dashed line separating the two parts. Currently, I have something like this:

\documentclass[a4paper]{paper}

\usepackage{multirow}
\usepackage{makecell}
\usepackage{arydshln}

\begin{document}

\begin{table}[h]
\centering
\begin{tabular}{|*{7}{c|}}
\hline
\multirowcell{2}{Function} & \multicolumn{1}{c|}{Input(s)} & \multicolumn{1}{c|}{Output(s)} & \multicolumn{4}{c|}{Operations} \\
\cdashline{2-3} \cline{4-7}
& Type(s) & Type(s) & M & S & a & I \\
\hline
$\mathtt{j\_inv}$ & $(A, C)$ \\ $K \times K$ & $j(E)$ \\ $K$ & 3 & 4 & 8 & 1 \\ \hline
\end{tabular}
\caption{Summary of functions}
\label{tab:functions}
\end{table}

\end{document}

The point is that the table header is exactly as I want, but then in the second row when I start to actually write the values, I do not know how to make the second and third column divided into two parts like their header, and divided by a dashed line. Simply, I put the newline symbol between the two parts, but it does not give the desired effect of course. Any ideas how to achieve what I want?

5
  • Could you please post a code that does not throw errors?
    – user121799
    Commented Apr 3, 2018 at 15:52
  • @marmot This code is not supposed to throw error, I believe. It compiles successfully, but the end result is not what I desire. The header is all fine, take the second row which includes values, for the second column I have written $(A, C)$ \\ $K, how this should be displayed is that ` $(A, C)$` should be at the top, then a dashed line comes and then $K$ underneath the dashed line. Similar idea for the third column too. I achieve that for the headers, but don't know how to achieve that for the actual values.
    – pixel
    Commented Apr 3, 2018 at 15:54
  • Well it does not compile on my TeXLive 2017 distribution with either pdflatex, xelatex or lualatex.
    – user121799
    Commented Apr 3, 2018 at 15:56
  • @marmot How about now? I believe arydshln needs to be loaded last.
    – pixel
    Commented Apr 3, 2018 at 15:58
  • Yes, now it compiles. ;-)
    – user121799
    Commented Apr 3, 2018 at 15:59

2 Answers 2

1

Most likely I am missing something. You have already found out in the header how to split a cell. Why can't you just repeat it?

\documentclass[a4paper]{paper}

\usepackage{multirow}
\usepackage{makecell}
\usepackage{arydshln}

\begin{document}

\begin{table}[h]
\centering
\begin{tabular}{|*{7}{c|}}
\hline
\multirowcell{2}{Function} & \multicolumn{1}{c|}{Input(s)} & \multicolumn{1}{c|}{Output(s)} & \multicolumn{4}{c|}{Operations} \\
\cdashline{2-3} \cline{4-7}
& Type(s) & Type(s) & M & S & a & I \\
\hline
\multirowcell{2}{$\mathtt{j\_inv}$} & $(A, C)$ &
$K \times K$ & $j(E)$ & & &\\ 
\cdashline{2-3} \cline{4-7}
& $K$ & 3 & 4 & 8 & 1 &\\ 
\hline
\end{tabular}
\caption{Summary of functions}
\label{tab:functions}
\end{table}

\end{document}

enter image description here

If this is not the output you want, you may benefit from posting an annotated table in which you explain what you want to achieve.

1
  • Thanks, this is the output I want, I was trying to use \multicolumn again in the second row. That was my mistake.
    – pixel
    Commented Apr 3, 2018 at 16:08
0

Here is a solution with {NiceTabular} of nicematrix.

In {NiceTabular}, you merge cells both horizontally and vertically with the command \Block. For the rows, you give the number of logical rows (and not the number of physical lines as with \multicolumn).

With the key hvlines, all the rules are drawn, excepted in the blocks (constructed by \Block).

Since nicematrix creates PGF/Tikz nodes under the cells, rows ans columns of the array, it's possible to use Tikz to draw whatever (dashed) rule you want after the construction of the array.

\documentclass[a4paper]{paper}
\usepackage{nicematrix,tikz}

\begin{document}

\begin{table}[h]
\centering
\begin{NiceTabular}{ccccccc}[hvlines,cell-space-limits=3pt]
\Block{2-1}{Function} & \Block{2-1}{} Input(s) & \Block{2-1}{} Output(s) & Operations \\
& Type(s) & Type(s) & M & S & a & I \\
\Block{2-1}{$\mathtt{j\_inv}$} & \Block{2-1}{} $(A, C)$ & \Block{2-1}{} $K \times K$ & $j(E)$ \\
& $K$ & 3 & 4 & 8 & 1 \\ 
\CodeAfter
  \tikz \draw [dashed] (2-|2) -- (2-|4)   (4-|2) -- (4-|4) ;
\end{NiceTabular}
\caption{Summary of functions}
\label{tab:functions}
\end{table}

\end{document}

You need several compilations (because of the PGF/Tikz nodes).

Output of the above code

You must log in to answer this question.

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