Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
757 views
in Technique[技术] by (71.8m points)

latex - Multiple arrayrulecolor per line with booktabs

Taking this to tex.stackexhange.

The problem

Let's say I want to have more than rules in two different colors in the same row ... how can I make it work?

Here is a minimal example:

documentclass{article}
usepackage{colortbl}
usepackage{booktabs} 


egin{document}

    egin{table}[ht]
        egin{tabular}{llll}
            oprule
            A & B & alpha & beta\
            arrayrulecolor{black} cmidrule[1pt](l){1-1} arrayrulecolor{red} cmidrule[1pt](r){2-2} arrayrulecolor{black} cmidrule[1pt](l){3-3} arrayrulecolor{black} cmidrule[1pt](r){4-4}
            1 & 5 & 10 &    100\
            2 & 6 & 11 &    101\
            2 & 7 & 12 &    102\
            3 & 8 & 13 &    103\
            ottomrule
        end{tabular}
    end{table}

end{document}

What happens is that with each call of arrayrulecolor{}, the corresponding cmidrule is moved down. Is there a solution to this?

result

The problem with the earlier solution

The solution mentioned in the comments has some trouble when you have different widths in one row. Consider this example:

documentclass{article}
usepackage{colortbl}
usepackage{booktabs} 


ewcommand{corcmidrule}[1][2pt]{% corcmidrule[<len>]
    \[dimexpr-
ormalbaselineskip-elowrulesep-aboverulesep-#1
elax]%
}

egin{document}

    egin{table}[ht]
        egin{tabular}{llll}
            oprule
            A & B & alpha & beta\
            arrayrulecolor{black}cmidrule[1pt](l){1-1} 
            corcmidrule[2pt]arrayrulecolor{black}cmidrule[2pt](r){2-2} 
            corcmidrule[5pt]arrayrulecolor{black}cmidrule[5pt](l){3-3} 
            corcmidrule[1pt]arrayrulecolor{black}cmidrule[1pt](r){4-4}
            1 & 5 & 10 &    100\
            2 & 6 & 11 &    101\
            2 & 7 & 12 &    102\
            3 & 8 & 13 &    103\
            ottomrule
        end{tabular}
    end{table}

end{document}

enter image description here

What's wrong with this? Consider what it looks like without the macro:

documentclass{article}
usepackage{colortbl}
usepackage{booktabs} 


ewcommand{corcmidrule}[1][2pt]{% corcmidrule[<len>]
    \[dimexpr-
ormalbaselineskip-elowrulesep-aboverulesep-#1
elax]%
}

egin{document}

    egin{table}[ht]
        egin{tabular}{llll}
            oprule
            A & B & alpha & beta\
            arrayrulecolor{black}cmidrule[1pt](l){1-1} 
            cmidrule[2pt](r){2-2} 
            cmidrule[5pt](l){3-3} 
            cmidrule[1pt](r){4-4}
            1 & 5 & 10 &    100\
            2 & 6 & 11 &    101\
            2 & 7 & 12 &    102\
            3 & 8 & 13 &    103\
            ottomrule
        end{tabular}
    end{table}
    
end{document}

enter image description here

The macro might need a modification.

question from:https://stackoverflow.com/questions/65948190/multiple-arrayrulecolor-per-line-with-booktabs

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...