如何为 mdframed 包含的表格中的 (自定义) 线条/规则着色?

如何为 mdframed 包含的表格中的 (自定义) 线条/规则着色?

作为后续行动我最近提出的问题:现在我想给该线条/规则添加一些颜色。在下面的 MWE 中,\arrayrulecolor{blue}\mycline{1-1}抛出错误(undefined control sequence相对于\arrayrulecolor)。我怎样才能\mycline接受颜色?

% \PassOptionsToPackage{table}{xcolor}

\documentclass[a4paper]{article}

% \usepackage{booktabs}
% \usepackage{array}

 \newlength{\mycustomlength}
 \settowidth\mycustomlength{blaaaaaaaa}

\makeatletter
\def\mycline#1{\expandafter\my@cline\@cline#1\@nil}

\def\my@cline#1\leaders#2\hfill{%
#1\hfill\leaders#2\hskip\mycustomlength\hfill\kern\z@}
\makeatother

%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[framemethod=TikZ, xcolor=RGB,table]{mdframed}

% \usepackage[RGB]{xcolor}
\definecolor{mycolor}{RGB}{0,111,222}

\mdfsetup{skipabove=\topskip,skipbelow=\topskip, nobreak=true, innertopmargin=0.5\baselineskip, innerbottommargin=0.5\baselineskip, frametitleaboveskip=3pt, frametitlebelowskip=2pt, skipabove=\topskip,skipbelow=\topskip}

\mdfdefinestyle{my_style}{%
     linecolor=mycolor,middlelinewidth=0.7pt, frametitlebackgroundcolor=mycolor}

\usepackage{tabularx}

\usepackage{multirow}

%------------------------------------

\begin{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{mdframed}[style=my_style,frametitle=\color{white}{OOO}]

\begin{tabularx}{\textwidth}{@{}*{1}{|p{\mycustomlength}|}*{1}{X}@{}}

\textbf{AAAAAA} & \\
\mycline{1-1}
%%%\arrayrulecolor{blue}\mycline{1-1}
% \cline{1-1}
aaaaaaaaa & \textbf{aaaa} \\
aaaa & \textbf{aa} \\
\\
\textbf{BBBB} & \\
% \rule{\mycustomlength}{0.4pt}
% & \\
% \\
% \cline{1-1}
\mycline{1-1}
bbb & bbbbbbbbb \textbf{b} \\
bbbbb & \textbf{B} \\


\end{tabularx}
% \end{tabulary}

\end{mdframed}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% \lipsum

\end{document}

另请参阅:

注意理论上 mdframed应该加载xcolor,然后又应该加载colortbl (参见相应文档文件)。但似乎有多种调用这些包的方法;除了如何它们被调用/加载的顺序也很重要......

答案1

您的 MWE 为我拥有的版本生成了 mdfamed 的未知选项错误,因此我删除了该错误并加载了colortbl原本不会加载的版本。由于colortbl重新定义了\cline上一个答案中的补丁不匹配,您需要修改一个。

在此处输入图片描述

\documentclass[a4paper]{article}

% \usepackage{booktabs}
% \usepackage{array}

\usepackage{colortbl}
 \newlength{\mycustomlength}
 \settowidth\mycustomlength{blaaaaaaaa}

\makeatletter
\def\mycline#1{\expandafter\my@cline\@cline#1\@nil}



\def\my@cline#1\@multispan\@ne#2{%
#1\@multispan\@ne
{\CT@arc@\hfill\leaders\hrule\@height\arrayrulewidth\hskip\mycustomlength\hfill\kern\z@}}%


\makeatother

%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[framemethod=TikZ, xcolor=RGB]{mdframed}

% \usepackage[RGB]{xcolor}
\definecolor{mycolor}{RGB}{0,111,222}

\mdfsetup{skipabove=\topskip,skipbelow=\topskip, nobreak=true, innertopmargin=0.5\baselineskip, innerbottommargin=0.5\baselineskip, frametitleaboveskip=3pt, frametitlebelowskip=2pt, skipabove=\topskip,skipbelow=\topskip}

\mdfdefinestyle{my_style}{%
     linecolor=mycolor,middlelinewidth=0.7pt, frametitlebackgroundcolor=mycolor}

\usepackage{tabularx}

\usepackage{multirow}

%------------------------------------

\begin{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{mdframed}[style=my_style,frametitle=\color{white}{OOO}]

\arrayrulecolor{blue}

\begin{tabularx}{\textwidth}{@{}*{1}{|p{\mycustomlength}|}*{1}{X}@{}}

\textbf{AAAAAA} & \\
\mycline{1-1}
%%%\arrayrulecolor{blue}\mycline{1-1}
% \cline{1-1}
aaaaaaaaa & \textbf{aaaa} \\
aaaa & \textbf{aa} \\
\\
\textbf{BBBB} & \\
% \rule{\mycustomlength}{0.4pt}
% & \\
% \\
% \cline{1-1}
\mycline{1-1}
bbb & bbbbbbbbb \textbf{b} \\
bbbbb & \textbf{B} \\


\end{tabularx}
% \end{tabulary}

\end{mdframed}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% \lipsum

\end{document}

答案2

为了了解与之相关的错误,mdframed我想提供一个小答案。

选项之间用逗号分隔,因此输入

\usepackage[framemethod=TikZ, xcolor=RGB,table]{mdframed}

将选项传递给mdframed

  1. framemethod=TikZ==已知
  2. xcolor=RGB==已知
  3. table== 未知

如果要将值传递给包含逗号的选项,则必须包含它。因此正确的语法是:

\usepackage[framemethod=TikZ, xcolor={RGB,table}]{mdframed}

现在您正在向 传递两个选项mdframed


但为什么没有效果呢?我决定xcolor以以下方式实现该选项:如果包xcolor已加载,则忽略所有选项。TikZ 会加载包xcolor,因此的选项xcolor将被忽略。要添加选项,xcolor您可以执行以下操作:

  1. xcolor单独加载

    \usepackage[table,RGB]{xcolor}
    \usepackage[framemethod=TikZ]{mdframed}
    
  2. 将选项传递给xcolorvia\PassOptionsToPackage

    \PassOptionsToPackage{table,RGB}{xcolor}
    \usepackage[framemethod=TikZ]{mdframed}
    
  3. 更改选项的顺序:

     \usepackage[xcolor={RGB,table},framemethod=TikZ]{mdframed}
    

我推荐第一种方法。

相关内容