2

I just try to learn to work with nicematrix. but I am not yet very familiar with it. I have two questions/problems.

  1. how can I make every road the same width. As it seems to me the column V10 is smaller than the column V500.
  2. how can I align the text in the first row to the left site?
\documentclass[a4paper, 11pt]{article}
\usepackage[left=2cm,top=2cm,right=2cm, bottom=2cm]{geometry}


\usepackage{booktabs}
\usepackage{nicematrix,tikz}



\begin{document}
\begin{table}
\scriptsize
\renewcommand{\arraystretch}{1.4}
\begin{NiceTabular*}{\textwidth}{@{}>{\scriptsize\bfseries}c*{5}{@{\extracolsep{\fill}}c}@{}}[colortbl-like]
\toprule 
\Block{2-1}<\bfseries>{Substance} & \Block{2-1}<\bfseries>{Bulk density } & \multicolumn{3}{c}{\textbf{Tapped density }} & \\ 
\cmidrule(lr){3-5}
& & $V_{10}$ & $V_{500}$& $V_{1250}$ & $\Delta$ $V_{500}$ - $V_{1250}$\\
\midrule
 Substance A &  & & & & \\
 Sub B &  & & & & \\
Substance A and B &  & & & & \\
\bottomrule
\end{NiceTabular*}
\end{table}
\end{document}

like this

With the aswer I got this. I changed lc{3} to lc{4} to achieve the same width for the last column to. But somehow this doesnt seem to work.

\begin{table}[H]
\renewcommand{\arraystretch}{1.4}
\begin{NiceTabular}{@{}>{\scriptsize\bfseries}ll*{4}{wc{2.2cm}}c@{}}[colortbl-like]
\toprule 
\Block{2-1}<\bfseries>{Substance} & \Block{2-1}<\bfseries>{Bulk density\\ [$\si{\gram\per\cubic\centi\meter}$]} & \multicolumn{3}{c}{\textbf{Tapped density [$\si{\gram\per\cubic\centi\meter}$]}} & \\ 
\cmidrule(lr){3-5}
& & $V_{10}$ & $V_{500}$& $V_{1250}$ & $\Delta$ $V_{500}$ - $V_{1250}$\\
\midrule
Acetaminophen &  & & & & \\
Magnesium sterate &  & & & & \\
Methyl cellulose &  & & & & \\
Polyvynilpyrrolidone &  & & & & \\
Microcrystalline cellulose &  & & & & \\
Mannitol &  & & & & \\
\bottomrule
\end{NiceTabular}
\end{table}
2
  • 1
    I assume you wanted to say "column V10" instead of "row V10"... Commented Mar 30, 2021 at 8:37
  • yes exactly. sorry for the mistake
    – Elia
    Commented Mar 30, 2021 at 8:40

1 Answer 1

2

You probably want the columns V10, V500 and V1250 with the same width. A simple way to do that is to fix the width of those columns with the specificier wc{...} (which is a standard specifier of the package array, upon which nicematrix relies).

\documentclass[a4paper, 11pt]{article}
\usepackage[left=2cm,top=2cm,right=2cm, bottom=2cm]{geometry}

\usepackage{lipsum}

\usepackage{booktabs}
\usepackage{nicematrix,tikz}

\begin{document}

\lipsum[1]
\begin{table}
\scriptsize
\renewcommand{\arraystretch}{1.4}
\begin{NiceTabular*}{\textwidth}{@{}>{\scriptsize\bfseries}l@{\extracolsep{\fill}}c*{3}{wc{2cm}}c@{}}
\toprule 
\RowStyle{\bfseries}
\Block{2-1}{Substance} & \Block{2-1}{Bulk density} & \Block{1-3}{Tapped density } & \\ 
\cmidrule(lr){3-5}
& & $V_{10}$ & $V_{500}$& $V_{1250}$ & $\Delta$ $V_{500}$ - $V_{1250}$\\
\midrule
Substance A \\
Sub B \\
Substance A and B \\
\bottomrule
\end{NiceTabular*}
\end{table}
\end{document}

Output of the above code

3
  • Thank you very much! I'm still trying to find different ways to adapt a table. And as you said it's good to know that I shouldn't systematically set the width of a tabular. The reason I did this here to have the option to do an enumeration.
    – Elia
    Commented Mar 30, 2021 at 8:54
  • When I add instead of lc*{3} lc*{4} why is there an error? I try to get the whole line filled with the table (see question above)
    – Elia
    Commented Mar 30, 2021 at 9:13
  • 2
    You have an error because you don't use all the columns specified in your preamble (why declaring more columns that actually used?). Nevertheless, I have modified my answer since you actually need a tabular with the width of the text. Commented Mar 30, 2021 at 9:25

You must log in to answer this question.

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