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...

  • 1
    The correct loading order is: \usepackage[framemethod=TikZ, xcolor={RGB,table}]{mdframed} -- You forgot the brackets at xcolor={RGB,table} – Marco Daniel Jul 8 '13 at 11:19
  • yeah, wasn't sure about that (found no working example) ... – nutty about natty Jul 8 '13 at 11:23
  • @MarcoDaniel Can you reconcile that line with David's MWE ? I tried - but have yet to succeed. – nutty about natty Jul 8 '13 at 11:26
  • At the moment I have no TeX and I can't test anything. – Marco Daniel Jul 8 '13 at 13:25
  • 1
    Found the issue -- the package tikz loads xcolor and so all options related to xcolor are ignored. – Marco Daniel Jul 8 '13 at 16:26
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}
  • You've earned yourself the Saviour badge. – nutty about natty Jul 8 '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 8 '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 8 '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: 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 8 '13 at 14:53
  • 1
    oops \@ne appears twice in the original code so patch was in wrong place: fixed. – David Carlisle Jul 8 '13 at 16:01
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.