2

I'm using ctable and I would like to have a frame around tables matching the main color of the document. The problem is that ctable has the property framefg that accepts the RGB values of the color, like so

\ctable[framefg = 1 0 0]{...

This while very nice does not allow me to simply put framefg = red for example. The following is what I would like to be able to do:

\documentclass{article}

\usepackage{ctable}
\usepackage{xcolor}
\definecolor{maincolor}{RGB}{243,102,25}

\begin{document}
\ctable[%
  caption = Testing the frame color,
  framerule = 1pt,
  framefg = maincolor,
  framesep = 10pt
]{cc}{}{%
  \FL
  \multicolumn{2}{c}{Header}\ML
  a & b\NN 
  c & d\LL
}
\end{document}

In the resulting PDF below the table there appears

maincolor=“relax0¿0 1“XKV@tempa@toks0¿0 1–XKV@prefix0¿0 1,XKV@fams0¿01 0pt

while the error given is

Undefined control sequence. \XKV@resa ->\@nil
Undefined control sequence. \XKV@for@n ...ndafter \XKV@f@r \fi #2{#3}#1,\@nil
Extra \else. ...ter \expandafter \XKV@wh@list \else 
                                                  \def \XKV@tfam {}\expandaf...

and some more.

I have then gone to read the source of ctable and found on page 12

34\def\@CTfgcolor#1 #2 #3={%
35\definecolor{@CTframefg}{rgb}{#1,#2,#3}
36\def\@CTfgactual{@CTframefg}}

basically answering my question as to why it doesn't work. I then tried (naively since I didn't really know if it would work) to redefine @CTframefg to my color like so, in the preamble

\makeatletter
\colorlet{@CTframefg}{maincolor}
\def\@CTfgactual{@CTframefg}
\makeatother

and commenting out the framefg option in the \ctable call earlier. The document compiled succesfully but the frame color was the default black, not the one I was expecting.

Are there any workarounds to this? I really would like to use a named color since I am trying to create a template for many documents, where I would just need to change the one definition of maincolor and have the whole document follow it.

1
  • Very good your question....and also your comment into the answer :-)...and greetings from Sicily :-) – Sebastiano Feb 9 '20 at 16:48
3

You could add such a key.

\documentclass{article}
\usepackage{ctable}
\makeatletter
\define@key{suCT}{framefgcol}{\@dfltCTfgcolorcol#1=}
\def\@dfltCTfgcolorcol#1={\colorlet{@dfltCTframefg}{#1}}%
\def\@CTfgcolorcol#1={%
  \colorlet{@CTframefg}{#1}%
  \def\@CTfgactual{@CTframefg}}
\define@key{CT}{framefgcol}{\@CTfgcolorcol#1=}  
\makeatother

\definecolor{maincolor}{RGB}{243,102,25}

\setupctable{framefgcol=maincolor}
\begin{document}
\ctable[%
  caption = Testing the frame color,
  framerule = 1pt,
%  framefgcol = maincolor,
  framesep = 10pt
]{cc}{}{%
  \FL
  \multicolumn{2}{c}{Header}\ML
  a & b\NN 
  c & d\LL
}
\end{document}

enter image description here

5
  • 1
    You sir are fantastic, that works beautifully! I definitely would not have thought about creating a new key. Thanks a lot! – gjkf Feb 9 '20 at 13:43
  • I just incurred in another problem. If I use \setupctable{framefgcol=maincolor} I get the error Paragraph ended before \@dfltCTfgcolor was complete while if I use that key as an optional parameter to \ctable no error is raised. Since I would like to setup all tables to have this behaviour, any idea on how to fix this? – gjkf Feb 9 '20 at 18:46
  • 1
    @gjkf My bad, I should have tested it. Fixed it now. – user194703 Feb 9 '20 at 18:55
  • No worries, thank you so much, I will later implement it into my document and in case of other problems I will report them. In any case, thank you a lot. – gjkf Feb 9 '20 at 19:05
  • @gjkf You're welcome! (And please let me know if there are further issues.) – user194703 Feb 9 '20 at 19:06

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.