为表格中的整行添加边框

为表格中的整行添加边框

我有一张有多行的表格(回归表)。我想添加一个彩色边框来突出显示一个特定变量。我找到了一种一次给一个单元格添加边框的方法,但是有没有办法在整行周围添加边框?

编辑:这是我的表格上的一些细节:

\begin{tabular}{rcccccccc|cccccccc}

       &                                                       \multicolumn{ 8}{c}{section 1} &                                                           \multicolumn{ 8}{c}{section 2} \\

       &            &            &            &            &            &            &            &            &            &            &            &            &            &            &            &            \\

       &        (1) &        (2) &        (3) &        (4) &        (5) &        (6) &        (7) &        (8) &        (9) &       (10) &       (11) &       (12) &       (13) &       (14) &       (15) &       (16) \\

       &            &            &            &            &            &            &            &            &            &            &            &            &            &            &            &            \\

regression coef 1 &         no &         no &         no &         no &         no &             no &         no &         no &         no &         no &         no &         no &         no &         no &         no &         no \\

       &            &            &            &            &            &            &            &            &            &            &            &            &            &            &            &            \\

regression coef 2 & {\bf 1234} & {\bf 1234} & {\bf 1234} & {\bf 1234} & {\bf 1234} & {\bf 1234} & {\bf 1234} & {\bf 1234} &            &            &            &            &            &            &            &            \\

       & {\bf [2]} & {\bf [2]} & {\bf [2]} & {\bf [2]} & {\bf [2]} & {\bf [2]} & {\bf [2]} & {\bf [2]} &            &            &            &            &            &            &            &            \\

\end{tabular}

答案1

您可以\tikzmark在所需位置放置一些标记,然后使用这些标记绘制框架;一个小例子:

\documentclass{article}
\usepackage{tikz}
\usepackage{pdflscape}

\newcommand\tikzmark[1]{%
  \tikz[remember picture,overlay] \node (#1) {};}

\begin{document}

\begin{landscape}
\begin{tabular}{rcccccccc|cccccccc}
& \multicolumn{ 8}{c}{section 1} & \multicolumn{ 8}{c}{section 2} \\
&            &            &            &            &            &            &            &            &            &            &            &            &            &            &            &            \\
&        (1) &        (2) &        (3) &        (4) &        (5) &        (6) &        (7) &        (8) &        (9) &       (10) &       (11) &       (12) &       (13) &       (14) &       (15) &       (16) \\
&            &            &            &            &            &            &            &            &            &            &            &            &            &            &            &            \\
regression coef 1 &         no &         no &         no &         no &         no &             no &         no &         no &         no &         no &         no &         no &         no &         no &         no &         no \\
&            &            &            &            &            &            &            &            &            &            &            &            &            &            &            &            \\
\tikzmark{a}regression coef 2 & \bfseries 1234 & \bfseries 1234 & \bfseries 1234 & \bfseries 1234 & \bfseries 1234 & \bfseries 1234 & \bfseries 1234 & \bfseries 1234 &            &            &            &            &            &            &            &  \\
& \bfseries [2] & \bfseries [2] & \bfseries [2] & \bfseries [2] & \bfseries [2] & \bfseries [2] & \bfseries [2] & \bfseries [2] &            &            &            &            &            &            &            & \phantom{noo}\tikzmark{b} \\
\end{tabular}

\begin{tikzpicture}[remember picture,overlay]
\draw[line width=1pt,draw=orange!70!black,rounded corners=4pt]
 ([xshift=-3pt,yshift=7pt]a.north) rectangle ([xshift=3pt,yshift=-5pt]b.south);
\end{tikzpicture}
\end{landscape}

\end{document}

在此处输入图片描述

该代码需要运行两次才能稳定下来。

附注:\bf是已弃用的命令;您应改用\bfseries。此外,表格单元格定义组,因此您无需使用括号明确分组。

答案2

你可以使用更漂亮的边框tikz,但经典的方式是我们\hline

在此处输入图片描述

\documentclass{article}
\usepackage{pdflscape}


\begin{document}

\begin{landscape}
\begin{tabular}{rcccccccc|cccccccc}
& \multicolumn{ 8}{c}{section 1} & \multicolumn{ 8}{c}{section 2} \\
&            &            &            &            &            &            &            &            &            &            &            &            &            &            &            &            \\
&        (1) &        (2) &        (3) &        (4) &        (5) &        (6) &        (7) &        (8) &        (9) &       (10) &       (11) &       (12) &       (13) &       (14) &       (15) &       (16) \\
&            &            &            &            &            &            &            &            &            &            &            &            &            &            &            &            \\
regression coef 1 &         no &         no &         no &         no &         no &             no &         no &         no &         no &         no &         no &         no &         no &         no &         no &         no \\
&            &            &            &            &            &            &            &            &            &            &            &            &            &            &            &            \\
\hline
\multicolumn{1}{|r}{regression coef 2 }& \bfseries 1234 & \bfseries 1234 & \bfseries 1234 & \bfseries 1234 & \bfseries 1234 & \bfseries 1234 & \bfseries 1234 & \bfseries 1234 &            &            &            &            &            &            &            &\multicolumn{1}{c|}{}  \\
\hline
& \bfseries [2] & \bfseries [2] & \bfseries [2] & \bfseries [2] & \bfseries [2] & \bfseries [2] & \bfseries [2] & \bfseries [2] &            &            &            &            &            &            &            & 
\end{tabular}


\end{landscape}

\end{document}

答案3

与。{NiceTabular}nicematrix

\documentclass{article}
\usepackage{nicematrix,tikz}
\usepackage{pdflscape}

\begin{document}

\begin{landscape}
\begin{NiceTabular}{rcccccccc|cccccccc}
& \multicolumn{8}{c}{section 1} & \multicolumn{8}{c}{section 2} \\
&            &            &            &            &            &            &            &            &            &            &            &            &            &            &            &            \\
&        (1) &        (2) &        (3) &        (4) &        (5) &        (6) &        (7) &        (8) &        (9) &       (10) &       (11) &       (12) &       (13) &       (14) &       (15) &       (16) \\
&            &            &            &            &            &            &            &            &            &            &            &            &            &            &            &            \\
regression coef 1 &         no &         no &         no &         no &         no &             no &         no &         no &         no &         no &         no &         no &         no &         no &         no &         no \\
&            &            &            &            &            &            &            &            &
                                                                                            &            & &            &            &            &            &            \\
regression coef 2 & \RowStyle{\bfseries}1234 & 1234 & 1234 & 1234 & 1234 & 1234 & 1234 & 1234 \\
& \RowStyle{\bfseries} [2] & [2] & [2] & [2] & [2] & [2] & [2] & [2] &            &            &            &
&            &            &            & \phantom{noo} \\
\CodeAfter
  \tikz \draw [red!50!black,rounded corners] (7-|1) rectangle (last-|last) ;
\end{NiceTabular}

\end{landscape}

\end{document}

您需要多次编译(因为nicematrix使用 PGF/Tikz 节点)。

上述代码的输出

相关内容