我想将标题置于下表的中心:
\documentclass[10pt]{article}
\usepackage{nicematrix}
\begin{document}
\begin{NiceTabular}{l|Wr{2cm}|Wr{2cm}}
% \RowStyle{\centering}
& column 1 & column 2 \\
row 1 & 0\% & 1\% \\
row 2 & 2\% & 3\%
\end{NiceTabular}
\end{document}
但是,如果我取消注释该行
! LaTeX Error: Something's wrong--perhaps a missing \item.
我认为这是由于重复的对齐规范造成的,但我不知道如何修复它。
答案1
Withmulticolumn
语法
\multicolumn{1}{c}{column 1}
在哪里
{1} is the number of column to be merged - in this case one column
{c} is the positioning of the text - in this case centering denoted by `c`
{column1} is the text to occupy the centered column
平均能量损失
\documentclass[10pt]{article}
\usepackage{nicematrix}
\begin{document}
\begin{NiceTabular}{l|Wr{2cm}|Wr{2cm}}
% \RowStyle{\centering}
& \multicolumn{1}{c}{column 1} & \multicolumn{1}{c}{column 2}\\
row 1 & 0\% & 1\% \\
row 2 & 2\% & 3\%
\end{NiceTabular}
\end{document}
对于bold
标题使用包makecell
并重新定义theadfont
如下
平均能量损失
\documentclass[10pt]{article}
\usepackage{nicematrix}
\usepackage{makecell}
\renewcommand\theadfont{\bfseries}
\begin{document}
\begin{NiceTabular}{l|Wr{2cm}|Wr{2cm}}
% \RowStyle{\centering}
& \multicolumn{1}{c}{\thead{column 1}} & \multicolumn{1}{c}{\thead{column 2}}\\
row 1 & 0\% & 1\% \\
row 2 & 2\% & 3\%
\end{NiceTabular}
\end{document}
一抹色彩将强调标题,并消除使用垂直线的需要
为了与标题的深色背景形成对比,可以添加蓝色字体,并重新定义theadfont
如下
平均能量损失
\documentclass[10pt]{article}
\usepackage{nicematrix}
\usepackage{makecell}
\renewcommand\theadfont{\color{blue!20!white}\bfseries}
\begin{document}
\begin{NiceTabular}{lWr{2cm}Wr{2cm}}[%
code-before = \rowcolor{black!60}{1}]
% \RowStyle{\centering}
& \multicolumn{1}{c}{\thead{column 1}} & \multicolumn{1}{c}{\thead{column 2}}\\
row 1 & 0\% & 1\% \\
row 2 & 2\% & 3\%
\end{NiceTabular}
\end{document}