3

As a follow up to my recent question: Now I'd like to put some color on to that line/rule. In the MWE below, \arrayrulecolor{blue}\mycline{1-1} throws an error (undefined control sequence with respect to \arrayrulecolor). How can I make \mycline accept a color?

% \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}

Cf. also:

Note that in theory mdframed should load xcolor which in turn should load colortbl (cf. the resp. documentation files). But there seem multiple ways of calling these packages; and apart from how they are called/loaded the order in which they are called/loaded also matters...

David Carlisle
  • 757,742

2 Answers2

4

Your MWE generates an unknown option error for mdfamed with the version I have, so I removed that and loaded colortbl which otherwise wasn't loaded. Since colortbl redefines \cline The patch in the previous answer didn't match and you need a modified one.

enter image description here

\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}
David Carlisle
  • 757,742
  • You've earned yourself the Saviour badge. – nutty about natty Jul 08 '13 at 11:16
  • How can this be reconciled with Marco's comment, above? Using the one-liner of \usepackage[framemethod=TikZ, xcolor={RGB,table}]{mdframed} ? Note the added curly braces. – nutty about natty Jul 08 '13 at 11:33
  • @nuttyaboutnatty Marco's comment is same as mine. You had an undefined mdffamed option table, you need to fix that and load colortbl, I just removed it and loaded colortbl and he fixed it so the option is passed to xcolor which then loads colortbl. Moral is, don't ignore error messages. – David Carlisle Jul 08 '13 at 12:04
  • Sorry for opening this question up again, but it doesn't actually help with my problem (yet): See the MWE posted here: http://paste.ubuntu.com/5855584/ (uncommented \rule{\mycustomlength}{0.4pt} and got rid of the corresponding \mycline{1-1} in that line). I want the length of \rule (as it appears in that MWE), *not* of \mycline (as it appears in that MWE). Notice that, in contrast to \myrule, \rule does *not* touch the borders of the tabular column. This is the behaviour I want: no "touch". How to correct? – nutty about natty Jul 08 '13 at 14:53
  • Your previous answer to my previous already did feature the "no-touch" feature... (cf. this MWE) - So I guess it's just yet another minor change needed... but which? – nutty about natty Jul 08 '13 at 14:57
  • 1
    oops \@ne appears twice in the original code so patch was in wrong place: fixed. – David Carlisle Jul 08 '13 at 16:01
  • Removing the | unfortunately rocks the boat and introduces a ~2mm shift to the right of those (difficult) lines: How to make your solution neat again for \begin{tabularx}{\textwidth}{@{}*{1}{p{\mycustomlength}}*{1}{X}@{}} (without |p...) ? – nutty about natty Jul 08 '13 at 18:03
  • you need to add space either side of the leaders to match the inter column material, usually,\hpace{\arrayrulewidth} or \hspace{\tabcolsep or both. – David Carlisle Jul 08 '13 at 19:58
2

To understand the error related to mdframed I want to provide a small answer.

Options are separated by commas, so your input

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

is passing the options to mdframed:

  1. framemethod=TikZ == known
  2. xcolor=RGB == known
  3. table== unknown

If you want to pass a value to an option which contains a comma, you have to embrace it. So the correct syntax is:

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

Now you are passing two options to mdframed.


But why does it have no effect? I decided to implement the option xcolor in the following way: If the package xcolor is already loaded, ignore all options. The package TikZ loads xcolor and so the options of xcolor are ignored. To add options to xcolor you can do the following:

  1. Load xcolor separately

    \usepackage[table,RGB]{xcolor}
    \usepackage[framemethod=TikZ]{mdframed}
    
  2. Pass options to xcolor via \PassOptionsToPackage

    \PassOptionsToPackage{table,RGB}{xcolor}
    \usepackage[framemethod=TikZ]{mdframed}
    
  3. Change the order of the options:

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

I recommend the first method.

Marco Daniel
  • 95,681