如何更改单个表中单个水平线的颜色和粗细

如何更改单个表中单个水平线的颜色和粗细

我想改变颜色和厚度单身的 \hline在一个单身的桌子。

在他的回答中如何同时改变表格上 \hline 的粗细和颜色?,Heiko Oberdiek 发出命令\noalign{\global\arrayrulewidth=1mm},但全部后续\hline也将采用相同的格式。

此外,在随后的表格、\cline垂直线均采用该格式。

以下是 MWE:

        \documentclass[11pt]{book}
    \usepackage[table]{xcolor}
    %\usepackage{colortbl}%Automatically loaded by the option ``table'' in xcolor.  
    \usepackage{tabularx}
    \usepackage{booktabs}
    \begin{document}
    \begin{tabular}{@{} lclcc @{}}
        \toprule
    %Row0
            \colorbox{green}{Input}: You tell me: 
        &   \hspace{3mm}then\hspace{3mm}
        &   \colorbox{pink}{Output}: I'll tell you:
        &   
        &   
        \\ 
        \midrule
    %Row1
            \colorbox{green}{The company you keep}
        &   
        &   \colorbox{pink}{what you are}
        &   
        &   (Dutch)
        \\ 
\arrayrulecolor{white} \hline
    %Row2
            \colorbox{green}{Who's your friend}
        &   
        &   \colorbox{pink}{who you are}
        &   
        &   (Russian)
        \\ 
\arrayrulecolor{white} \hline
%   %Row3
            \colorbox{green}{Your company}
        &   
        &   \colorbox{pink}{who you are}
        &   
        &   (Irish)
        \\ 
\noalign{\global\arrayrulewidth=1mm}%Heiko Oberdiek at \url{https://tex.stackexchange.com/questions/337788/how-do-i-change-the-thickness-and-color-of-hline-on-a-table-simultaneously}
\arrayrulecolor{white} \hline
%   %Row4
            \colorbox{green}{What you are eager to buy}
        &   
        &   \colorbox{pink}{what you are}
        &   
        &   (Mexican)
        \\ 
\arrayrulecolor{white} \hline
    %Row5
            \colorbox{green}{With whom you go}
        &   
        &   \colorbox{pink}{what you do}
        &   
        &   (English)
        \\ 
  \arrayrulecolor{white}\hline
    %Row6
            \colorbox{green}{Who your father is}
        &   
        &   \colorbox{pink}{who you are}
        &   
        &   (Philippine) 
        \\ 
\arrayrulecolor{white} \hline
    %Row6
            \colorbox{green}{What you eat}
        &   
        &   \colorbox{pink}{what you are}
        &   
        &   (French) 
        \\ 
\arrayrulecolor{black}\bottomrule
    \end{tabular}

\bigskip

  \begin{tabular}{@{} |c|ccccc| @{}}
    \cline{2-6}
 \multicolumn{1}{c|}{likes}   & \colorbox{pink}{walking} & \colorbox{pink}{playing music} & \colorbox{pink}{playing chess} & \colorbox{pink}{reading}& \colorbox{pink}{learning calculus} \\ 
    \midrule
    \colorbox{green}{Andy} & yes & yes & no & no & no \\ 
    \colorbox{green}{Beth} & no & no & no & no & no \\ 
    \colorbox{green}{Cathy} & yes & no & no & yes & yes \\ 
    \bottomrule
 \end{tabular}
\end{document}

其 PDF 版本如下: 在此处输入图片描述

答案1

在此处输入图片描述

 \documentclass[11pt]{book}
\usepackage[table]{xcolor}
%\usepackage{colortbl}%Automatically loaded by the option ``table'' in xcolor.  
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{nicematrix,tikz}

\begin{document}
    \tikzset
    {  
        dashed 1/.style = 
        {
            red ,
            %        dash pattern = on 2pt off 3pt ,
            line width = 3 pt 
        } ,
        dashed 2/.style = 
        {
            blue ,
            %        dash pattern = on 1pt off 1pt ,
            line width = 3pt 
        }
    }
    
\begin{NiceTabular}{@{} lclcc @{}}
        \toprule
        %Row0
        \colorbox{green}{Input}: You tell me: 
        &   \hspace{3mm}then\hspace{3mm}
        &   \colorbox{pink}{Output}: I'll tell you:
        &   
        &   
        \\ 
        \midrule
        %Row1
        \colorbox{green}{The company you keep}
        &   
        &   \colorbox{pink}{what you are}
        &   
        &   (Dutch)
        \\ 
        \arrayrulecolor{white} \hline
        %Row2
        \colorbox{green}{Who's your friend}
        &   
        &   \colorbox{pink}{who you are}
        &   
        &   (Russian)
        \\ 
        \arrayrulecolor{white} \hline
        %   %Row3
        \colorbox{green}{Your company}
        &   
        &   \colorbox{pink}{who you are}
        &   
        &   (Irish)
        \\ 
%       \noalign{\global\arrayrulewidth=2mm}%Heiko Oberdiek at \url{https://tex.stackexchange.com/questions/337788/how-do-i-change-the-thickness-and-color-of-hline-on-a-table-simultaneously}
        \arrayrulecolor{white} \hline
        %   %Row4
        \colorbox{green}{What you are eager to buy}
        &   
        &   \colorbox{pink}{what you are}
        &   
        &   (Mexican)
        \\ 
        \arrayrulecolor{white} \hline
        %Row5
        \colorbox{green}{With whom you go}
        &   
        &   \colorbox{pink}{what you do}
        &   
        &   (English)
        \\ 
        \arrayrulecolor{white}\hline
        %Row6
        \colorbox{green}{Who your father is}
        &   
        &   \colorbox{pink}{who you are}
        &   
        &   (Philippine) 
        \\ 
        \arrayrulecolor{white} \hline
        %Row6
        \colorbox{green}{What you eat}
        &   
        &   \colorbox{pink}{what you are}
        &   
        &   (French) 
        \\ 
        \arrayrulecolor{black}\bottomrule
        \CodeAfter
        \begin{tikzpicture}
            %\draw [dashed 1] (1-|2) -- (3-|2) ;
            %\draw [dashed 2] (1-|3) -- (3-|3) ;
            \draw [dashed 1] (5-|1) -- (5-|6) ;
            \draw [dashed 2] (6-|1) -- (6-|6) ;
        \end{tikzpicture}
\end{NiceTabular}
    
    \bigskip
    
    \begin{tabular}{@{} |c|ccccc| @{}}
        \cline{2-6}
        \multicolumn{1}{c|}{likes}   & \colorbox{pink}{walking} & \colorbox{pink}{playing music} & \colorbox{pink}{playing chess} & \colorbox{pink}{reading}& \colorbox{pink}{learning calculus} \\ 
        \midrule
        \colorbox{green}{Andy} & yes & yes & no & no & no \\ 
        \colorbox{green}{Beth} & no & no & no & no & no \\ 
        \colorbox{green}{Cathy} & yes & no & no & yes & yes \\ 
        \bottomrule
    \end{tabular}
\end{document}

相关内容