Coloring only Part of a Row in a Tablecoloring every other row of a table, with vertical linescoloring entire row of tabular*Axis part coloringBetter table code and coloring tableunwanted table coloring issuealternate row colors for only some columnsColoring table row ruins pm symbolColoring the *text* of the entire row in a tableCenter align only first table rowRow coloring problems in table (svmono class)

Is the Folding Boat truly seaworthy?

Can external light meter replace the need for push/pull?

Is there a drawback to Flail Snail's Shell defense?

Getting an entry level IT position later in life

Was Richard I's imprisonment by Leopold of Austria justified?

How can I refer to something in a book?

What is an air conditioner compressor hard start kit and how does it work?

Deadlock Priority High Chosen as deadlock victim

What can make Linux so unresponsive?

Did WWII Japanese soldiers engage in cannibalism of their enemies?

Best way to explain to my boss that I cannot attend a team summit because it is on Rosh Hashana or any other Jewish Holiday

Print only the last three columns from file

Did Captain America make out with his niece?

What word best describes someone who likes to do everything on his own?

Premier League simulation

How would a family travel from Indiana to Texas in 1911?

How to halve redstone signal strength?

What city skyline is this picture of?

How to help new students accept function notation

Probably terminated or laid off soon; confront or not?

Did silent film actors actually say their lines or did they simply improvise “dialogue” while being filmed?

Count number of occurences of particular numbers in list

Can chords be inferred from melody alone?

Does a 4 bladed prop have almost twice the thrust of a 2 bladed prop?



Coloring only Part of a Row in a Table


coloring every other row of a table, with vertical linescoloring entire row of tabular*Axis part coloringBetter table code and coloring tableunwanted table coloring issuealternate row colors for only some columnsColoring table row ruins pm symbolColoring the *text* of the entire row in a tableCenter align only first table rowRow coloring problems in table (svmono class)






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















Let's say you have this table:



enter image description here



I want to highlight only parts of certain rows. For example, I want to highlight the fourth row, but only highlight this row for the first six columns. Then for the last six columns, I want to highlight the last row.



I know you can use cellcolor, but it seems rather tedious to do this for every single column. Is there a more elegant way to color only specific cells from a row?



P.S. I know there is extra space toward the end of the table, I have to fix it :)



Here is the code:



documentclassarticle

usepackagetabularx
usepackagemultirow
usepackagepdflscape
usepackagebooktabs
usepackage[margin = 1in]geometry

begindocument

begintable[ht]

centering
defarraystretch1.5

begintabularxlinewidthlccccclccccc toprule
& multicolumn5c$K$-means Clustering & & multicolumn5cHierarchical Clustering \ cmidrule(r)2-6 cmidrule(lr)8-12
& $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups & & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\ midrule
$alpha = 1$ & $0.05873092$ & $11/31$ & $1.730157$ & $1$ & $0$ & $alpha = 1$ & $0.05873092$ & $11/31$ & $1.741681$ & $1$ & $0$ \
$alpha = 0.8$ & $0.0281825$ & $8/31$ & $1.735783$ & $7$ & $1$ & $alpha = 0.8$ & $0.02822086$ & $11/31$ & $1.732505$ & $108$ & $1$ \
$alpha = 0.6$ & $0.02425659$ & $8/31$ & $1.711518$ & $26$ & $2$ & $alpha = 0.6$ & $0.02380529$ & $11/31$ & $1.727994$ & $226$ & $1$ \
$alpha = 0.4$ & $0.021494$ & $7/31$ & $1.706627$ & $29$ & $2$ & $alpha = 0.4$ & $0.0214516$ & $11/31$ & $1.726991$ & $319$ & $1$ \
$alpha = 0.2$ & $0.02001998$ & $7/31$ & $1.70708$ & $32$ & $2$ & $alpha = 0.2$ & $0.02007049$ & $11/31$ & $1.72622$ & $393$ & $1$ \
$alpha = 0$ & $0.01946719$ & $7/31$ & $1.707758$ & $36$ & $2$ & $alpha = 0$ & $0.01921006$ & $11/31$ & $1.725663$ & $472$ & $1$ \ bottomrule
endtabularx

endtable

enddocument


EDIT made edits to MWE.










share|improve this question


























  • The MWE cannot produce the image showed. There are several errors, as the lack of booktabs package, not closing the float options and more. Can you fix this first, please? BTW, imho the bottom rule is perfect as is, but in texdoc booktabs you have how to make rules with another vertical spacing.

    – Fran
    Jul 28 at 7:54












  • @Fran: I suppose that the statement " extra space toward the end of the table" does refer to horizontal end of the table (lines continuing to the right margin) instead of the vertical end of the table.

    – leandriis
    Jul 28 at 7:57











  • @Aiden Kenny: In addition to the previous comment, the landscape environment is misssing. If I add it, your table is wider than the textwidth. So your MWE must either be missing some font size settings or you changed the margins using for example geometry. Please also add these settings. Could you please also add teh reason why you used math mode for all the numbers?

    – leandriis
    Jul 28 at 8:00












  • @leandriis The bottom line end well in the image. It is not clear what we had to solve in this example, beside a method to coloring specific a matrix of n × m cells with only one command.

    – Fran
    Jul 28 at 8:13






  • 1





    @AidenKenny: Thanks for updating the MWE. The siunitx package (that I used in the fourth table of my answer) can also handle negative numbers. Maybe you want to use that. You can of course incorporate that in all of the other layouts as well.

    – leandriis
    Jul 28 at 18:55


















3















Let's say you have this table:



enter image description here



I want to highlight only parts of certain rows. For example, I want to highlight the fourth row, but only highlight this row for the first six columns. Then for the last six columns, I want to highlight the last row.



I know you can use cellcolor, but it seems rather tedious to do this for every single column. Is there a more elegant way to color only specific cells from a row?



P.S. I know there is extra space toward the end of the table, I have to fix it :)



Here is the code:



documentclassarticle

usepackagetabularx
usepackagemultirow
usepackagepdflscape
usepackagebooktabs
usepackage[margin = 1in]geometry

begindocument

begintable[ht]

centering
defarraystretch1.5

begintabularxlinewidthlccccclccccc toprule
& multicolumn5c$K$-means Clustering & & multicolumn5cHierarchical Clustering \ cmidrule(r)2-6 cmidrule(lr)8-12
& $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups & & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\ midrule
$alpha = 1$ & $0.05873092$ & $11/31$ & $1.730157$ & $1$ & $0$ & $alpha = 1$ & $0.05873092$ & $11/31$ & $1.741681$ & $1$ & $0$ \
$alpha = 0.8$ & $0.0281825$ & $8/31$ & $1.735783$ & $7$ & $1$ & $alpha = 0.8$ & $0.02822086$ & $11/31$ & $1.732505$ & $108$ & $1$ \
$alpha = 0.6$ & $0.02425659$ & $8/31$ & $1.711518$ & $26$ & $2$ & $alpha = 0.6$ & $0.02380529$ & $11/31$ & $1.727994$ & $226$ & $1$ \
$alpha = 0.4$ & $0.021494$ & $7/31$ & $1.706627$ & $29$ & $2$ & $alpha = 0.4$ & $0.0214516$ & $11/31$ & $1.726991$ & $319$ & $1$ \
$alpha = 0.2$ & $0.02001998$ & $7/31$ & $1.70708$ & $32$ & $2$ & $alpha = 0.2$ & $0.02007049$ & $11/31$ & $1.72622$ & $393$ & $1$ \
$alpha = 0$ & $0.01946719$ & $7/31$ & $1.707758$ & $36$ & $2$ & $alpha = 0$ & $0.01921006$ & $11/31$ & $1.725663$ & $472$ & $1$ \ bottomrule
endtabularx

endtable

enddocument


EDIT made edits to MWE.










share|improve this question


























  • The MWE cannot produce the image showed. There are several errors, as the lack of booktabs package, not closing the float options and more. Can you fix this first, please? BTW, imho the bottom rule is perfect as is, but in texdoc booktabs you have how to make rules with another vertical spacing.

    – Fran
    Jul 28 at 7:54












  • @Fran: I suppose that the statement " extra space toward the end of the table" does refer to horizontal end of the table (lines continuing to the right margin) instead of the vertical end of the table.

    – leandriis
    Jul 28 at 7:57











  • @Aiden Kenny: In addition to the previous comment, the landscape environment is misssing. If I add it, your table is wider than the textwidth. So your MWE must either be missing some font size settings or you changed the margins using for example geometry. Please also add these settings. Could you please also add teh reason why you used math mode for all the numbers?

    – leandriis
    Jul 28 at 8:00












  • @leandriis The bottom line end well in the image. It is not clear what we had to solve in this example, beside a method to coloring specific a matrix of n × m cells with only one command.

    – Fran
    Jul 28 at 8:13






  • 1





    @AidenKenny: Thanks for updating the MWE. The siunitx package (that I used in the fourth table of my answer) can also handle negative numbers. Maybe you want to use that. You can of course incorporate that in all of the other layouts as well.

    – leandriis
    Jul 28 at 18:55














3












3








3








Let's say you have this table:



enter image description here



I want to highlight only parts of certain rows. For example, I want to highlight the fourth row, but only highlight this row for the first six columns. Then for the last six columns, I want to highlight the last row.



I know you can use cellcolor, but it seems rather tedious to do this for every single column. Is there a more elegant way to color only specific cells from a row?



P.S. I know there is extra space toward the end of the table, I have to fix it :)



Here is the code:



documentclassarticle

usepackagetabularx
usepackagemultirow
usepackagepdflscape
usepackagebooktabs
usepackage[margin = 1in]geometry

begindocument

begintable[ht]

centering
defarraystretch1.5

begintabularxlinewidthlccccclccccc toprule
& multicolumn5c$K$-means Clustering & & multicolumn5cHierarchical Clustering \ cmidrule(r)2-6 cmidrule(lr)8-12
& $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups & & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\ midrule
$alpha = 1$ & $0.05873092$ & $11/31$ & $1.730157$ & $1$ & $0$ & $alpha = 1$ & $0.05873092$ & $11/31$ & $1.741681$ & $1$ & $0$ \
$alpha = 0.8$ & $0.0281825$ & $8/31$ & $1.735783$ & $7$ & $1$ & $alpha = 0.8$ & $0.02822086$ & $11/31$ & $1.732505$ & $108$ & $1$ \
$alpha = 0.6$ & $0.02425659$ & $8/31$ & $1.711518$ & $26$ & $2$ & $alpha = 0.6$ & $0.02380529$ & $11/31$ & $1.727994$ & $226$ & $1$ \
$alpha = 0.4$ & $0.021494$ & $7/31$ & $1.706627$ & $29$ & $2$ & $alpha = 0.4$ & $0.0214516$ & $11/31$ & $1.726991$ & $319$ & $1$ \
$alpha = 0.2$ & $0.02001998$ & $7/31$ & $1.70708$ & $32$ & $2$ & $alpha = 0.2$ & $0.02007049$ & $11/31$ & $1.72622$ & $393$ & $1$ \
$alpha = 0$ & $0.01946719$ & $7/31$ & $1.707758$ & $36$ & $2$ & $alpha = 0$ & $0.01921006$ & $11/31$ & $1.725663$ & $472$ & $1$ \ bottomrule
endtabularx

endtable

enddocument


EDIT made edits to MWE.










share|improve this question
















Let's say you have this table:



enter image description here



I want to highlight only parts of certain rows. For example, I want to highlight the fourth row, but only highlight this row for the first six columns. Then for the last six columns, I want to highlight the last row.



I know you can use cellcolor, but it seems rather tedious to do this for every single column. Is there a more elegant way to color only specific cells from a row?



P.S. I know there is extra space toward the end of the table, I have to fix it :)



Here is the code:



documentclassarticle

usepackagetabularx
usepackagemultirow
usepackagepdflscape
usepackagebooktabs
usepackage[margin = 1in]geometry

begindocument

begintable[ht]

centering
defarraystretch1.5

begintabularxlinewidthlccccclccccc toprule
& multicolumn5c$K$-means Clustering & & multicolumn5cHierarchical Clustering \ cmidrule(r)2-6 cmidrule(lr)8-12
& $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups & & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\ midrule
$alpha = 1$ & $0.05873092$ & $11/31$ & $1.730157$ & $1$ & $0$ & $alpha = 1$ & $0.05873092$ & $11/31$ & $1.741681$ & $1$ & $0$ \
$alpha = 0.8$ & $0.0281825$ & $8/31$ & $1.735783$ & $7$ & $1$ & $alpha = 0.8$ & $0.02822086$ & $11/31$ & $1.732505$ & $108$ & $1$ \
$alpha = 0.6$ & $0.02425659$ & $8/31$ & $1.711518$ & $26$ & $2$ & $alpha = 0.6$ & $0.02380529$ & $11/31$ & $1.727994$ & $226$ & $1$ \
$alpha = 0.4$ & $0.021494$ & $7/31$ & $1.706627$ & $29$ & $2$ & $alpha = 0.4$ & $0.0214516$ & $11/31$ & $1.726991$ & $319$ & $1$ \
$alpha = 0.2$ & $0.02001998$ & $7/31$ & $1.70708$ & $32$ & $2$ & $alpha = 0.2$ & $0.02007049$ & $11/31$ & $1.72622$ & $393$ & $1$ \
$alpha = 0$ & $0.01946719$ & $7/31$ & $1.707758$ & $36$ & $2$ & $alpha = 0$ & $0.01921006$ & $11/31$ & $1.725663$ & $472$ & $1$ \ bottomrule
endtabularx

endtable

enddocument


EDIT made edits to MWE.







tables formatting color tabularx






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 28 at 18:45







Aiden Kenny

















asked Jul 28 at 3:07









Aiden KennyAiden Kenny

6557 bronze badges




6557 bronze badges















  • The MWE cannot produce the image showed. There are several errors, as the lack of booktabs package, not closing the float options and more. Can you fix this first, please? BTW, imho the bottom rule is perfect as is, but in texdoc booktabs you have how to make rules with another vertical spacing.

    – Fran
    Jul 28 at 7:54












  • @Fran: I suppose that the statement " extra space toward the end of the table" does refer to horizontal end of the table (lines continuing to the right margin) instead of the vertical end of the table.

    – leandriis
    Jul 28 at 7:57











  • @Aiden Kenny: In addition to the previous comment, the landscape environment is misssing. If I add it, your table is wider than the textwidth. So your MWE must either be missing some font size settings or you changed the margins using for example geometry. Please also add these settings. Could you please also add teh reason why you used math mode for all the numbers?

    – leandriis
    Jul 28 at 8:00












  • @leandriis The bottom line end well in the image. It is not clear what we had to solve in this example, beside a method to coloring specific a matrix of n × m cells with only one command.

    – Fran
    Jul 28 at 8:13






  • 1





    @AidenKenny: Thanks for updating the MWE. The siunitx package (that I used in the fourth table of my answer) can also handle negative numbers. Maybe you want to use that. You can of course incorporate that in all of the other layouts as well.

    – leandriis
    Jul 28 at 18:55


















  • The MWE cannot produce the image showed. There are several errors, as the lack of booktabs package, not closing the float options and more. Can you fix this first, please? BTW, imho the bottom rule is perfect as is, but in texdoc booktabs you have how to make rules with another vertical spacing.

    – Fran
    Jul 28 at 7:54












  • @Fran: I suppose that the statement " extra space toward the end of the table" does refer to horizontal end of the table (lines continuing to the right margin) instead of the vertical end of the table.

    – leandriis
    Jul 28 at 7:57











  • @Aiden Kenny: In addition to the previous comment, the landscape environment is misssing. If I add it, your table is wider than the textwidth. So your MWE must either be missing some font size settings or you changed the margins using for example geometry. Please also add these settings. Could you please also add teh reason why you used math mode for all the numbers?

    – leandriis
    Jul 28 at 8:00












  • @leandriis The bottom line end well in the image. It is not clear what we had to solve in this example, beside a method to coloring specific a matrix of n × m cells with only one command.

    – Fran
    Jul 28 at 8:13






  • 1





    @AidenKenny: Thanks for updating the MWE. The siunitx package (that I used in the fourth table of my answer) can also handle negative numbers. Maybe you want to use that. You can of course incorporate that in all of the other layouts as well.

    – leandriis
    Jul 28 at 18:55

















The MWE cannot produce the image showed. There are several errors, as the lack of booktabs package, not closing the float options and more. Can you fix this first, please? BTW, imho the bottom rule is perfect as is, but in texdoc booktabs you have how to make rules with another vertical spacing.

– Fran
Jul 28 at 7:54






The MWE cannot produce the image showed. There are several errors, as the lack of booktabs package, not closing the float options and more. Can you fix this first, please? BTW, imho the bottom rule is perfect as is, but in texdoc booktabs you have how to make rules with another vertical spacing.

– Fran
Jul 28 at 7:54














@Fran: I suppose that the statement " extra space toward the end of the table" does refer to horizontal end of the table (lines continuing to the right margin) instead of the vertical end of the table.

– leandriis
Jul 28 at 7:57





@Fran: I suppose that the statement " extra space toward the end of the table" does refer to horizontal end of the table (lines continuing to the right margin) instead of the vertical end of the table.

– leandriis
Jul 28 at 7:57













@Aiden Kenny: In addition to the previous comment, the landscape environment is misssing. If I add it, your table is wider than the textwidth. So your MWE must either be missing some font size settings or you changed the margins using for example geometry. Please also add these settings. Could you please also add teh reason why you used math mode for all the numbers?

– leandriis
Jul 28 at 8:00






@Aiden Kenny: In addition to the previous comment, the landscape environment is misssing. If I add it, your table is wider than the textwidth. So your MWE must either be missing some font size settings or you changed the margins using for example geometry. Please also add these settings. Could you please also add teh reason why you used math mode for all the numbers?

– leandriis
Jul 28 at 8:00














@leandriis The bottom line end well in the image. It is not clear what we had to solve in this example, beside a method to coloring specific a matrix of n × m cells with only one command.

– Fran
Jul 28 at 8:13





@leandriis The bottom line end well in the image. It is not clear what we had to solve in this example, beside a method to coloring specific a matrix of n × m cells with only one command.

– Fran
Jul 28 at 8:13




1




1





@AidenKenny: Thanks for updating the MWE. The siunitx package (that I used in the fourth table of my answer) can also handle negative numbers. Maybe you want to use that. You can of course incorporate that in all of the other layouts as well.

– leandriis
Jul 28 at 18:55






@AidenKenny: Thanks for updating the MWE. The siunitx package (that I used in the fourth table of my answer) can also handle negative numbers. Maybe you want to use that. You can of course incorporate that in all of the other layouts as well.

– leandriis
Jul 28 at 18:55











2 Answers
2






active

oldest

votes


















6














As far as I know, the colortbl package only offers methods to easily color a whole row or a whole column. If you only want to color parts of it, there is the cellcolor command. If you don't want to repeat it with the same color definition over and over again, you could use an abbreviation. (Might also come in handy, if you later on decide that you want to change the color). Please also note that I have removed the superfluous $ that surrounded every number in your original example code. Also, I guessed the settings for the geometry package as they were not given in your example.



enter image description here



documentclassarticle
usepackage[margin=2cm]geometry
usepackagetabularx
usepackagepdflscape
usepackagebooktabs
usepackage[table]xcolor
newcommandmycccellcolorlightgray

begindocument
beginlandscape
begintable[ht]
centering
defarraystretch1.5
begintabularxlinewidthlccccclccccc toprule
& multicolumn5c$K$-means Clustering & & multicolumn5cHierarchical Clustering \ cmidrule(r)2-6 cmidrule(lr)8-12
& $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups & & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\ midrule
$alpha = 1$ & 0.05873092 & 11/31 & 1.730157 & 1 & 0 & $alpha = 1$ & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
$alpha = 0.8$ & 0.0281825 & 8/31 & 1.735783 & 7 & 1 & $alpha = 0.8$ & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
$alpha = 0.6$ & 0.02425659 & 8/31 & 1.711518 & 26 & 2 & $alpha = 0.6$ & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
mycc$alpha = 0.4$ & mycc 0.021494 & mycc 7/31 & mycc 1.706627 & mycc 29 & mycc 2 & $alpha = 0.4$ & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
$alpha = 0.2$ & 0.02001998 & 7/31 & 1.70708 & 32 & 2 & $alpha = 0.2$ & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
$alpha = 0$ & 0.01946719 & 7/31 & 1.707758 & 36 & 2 & mycc$alpha = 0$ & mycc 0.01921006 & mycc 11/31 & mycc 1.725663 & mycc 472 & mycc 1 \ bottomrule
endtabularx

endtable
endlandscape
enddocument



You seem to have already noticed that the horizontal lines continue all the way to the right margin even though the table's contents are not that wide. This is due to your usage of tabularx that I have not corrected in the above MWE. If you want your table to be as wide as the textwidth and are open to a slight redesign of your table, you might be interested in the following MWE (that also just needs one rowcolor command to color the mentioned cells):



enter image description here



documentclassarticle
usepackage[margin=2cm]geometry
usepackagepdflscape
usepackagebooktabs
usepackage[table]xcolor

begindocument


beginlandscape
begintable[ht]
centering
defarraystretch1.5
begintabularlccccc toprule
& multicolumn5cHierarchical Clustering \ cmidrule(lr)2-6
& $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\ midrule
$alpha = 1$ & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
$alpha = 0.8$ & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
$alpha = 0.6$ & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
rowcolorlightgray$alpha = 0.4$ & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
$alpha = 0.2$ & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
$alpha = 0$ & 0.01921006 & 11/31 & 1.725663 & 472 & 1 \ bottomrule
endtabular
hfill
begintabularlccccc toprule
& multicolumn5c$K$-means Clustering \ cmidrule(r)2-6
& $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups \ midrule
$alpha = 1$ & 0.05873092 & 11/31 & 1.730157 & 1 & 0 \
$alpha = 0.8$ & 0.0281825 & 8/31 & 1.735783 & 7 & 1 \
$alpha = 0.6$ & 0.02425659 & 8/31 & 1.711518 & 26 & 2 \
$alpha = 0.4$ & 0.021494 & 7/31 & 1.706627 & 29 & 2 \
$alpha = 0.2$ & 0.02001998 & 7/31 & 1.70708 & 32 & 2 \
rowcolorlightgray $alpha = 0$ & 0.01946719 & 7/31 & 1.707758 & 36 & 2 \ bottomrule
endtabular
endtable
endlandscape


enddocument



Starting from this redesign you might also want to rethink if a landscape orientation is really necessary, as your table can fit into the text block of a portrait page (even with standard margins) perfectly fine:



enter image description here



documentclassarticle
usepackagebooktabs
usepackage[table]xcolor

begindocument


begintable[ht]
centering
defarraystretch1.5
begintabularlccccc toprule
& multicolumn5cHierarchical Clustering \ cmidrule(lr)2-6
& $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\ midrule
$alpha = 1$ & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
$alpha = 0.8$ & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
$alpha = 0.6$ & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
rowcolorlightgray$alpha = 0.4$ & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
$alpha = 0.2$ & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
$alpha = 0$ & 0.01921006 & 11/31 & 1.725663 & 472 & 1 \ midrule
& multicolumn5c $K$-means Clustering \ cmidrule(r)2-6
& $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups \ midrule
$alpha = 1$ & 0.05873092 & 11/31 & 1.730157 & 1 & 0 \
$alpha = 0.8$ & 0.0281825 & 8/31 & 1.735783 & 7 & 1 \
$alpha = 0.6$ & 0.02425659 & 8/31 & 1.711518 & 26 & 2 \
$alpha = 0.4$ & 0.021494 & 7/31 & 1.706627 & 29 & 2 \
$alpha = 0.2$ & 0.02001998 & 7/31 & 1.70708 & 32 & 2 \
rowcolorlightgray$alpha = 0$ & 0.01946719 & 7/31 & 1.707758 & 36 & 2 \ bottomrule
endtabular
endtable



enddocument



Finally, here is the layout I personally would go for. Here I have used the S type columns from the siunitx package in order to align the numbers with respect to the decimal marker and used >(l<) in order to automatically set the comments of the first column in math mode.



enter image description here



documentclassarticle

usepackagebooktabs
usepackagesiunitx
usepackage[table]xcolor

begindocument
begintable[ht]
centering
begintabular@quad>(l<)S[table-format=1.8]cS[table-format=1.6]S[table-format=3]c toprule

& $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\ midrule
multicolumn6@lHierarchical Clustering \
alpha = 1 & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
alpha = 0.8 & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
alpha = 0.6 & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
rowcolorlightgrayalpha = 0.4 & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
alpha = 0.2 & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
alpha = 0 & 0.01921006 & 11/31 & 1.725663 & 472 & 1 \ midrule
multicolumn6@l$K$-means Clustering \
alpha = 1 & 0.05873092 & 11/31 & 1.730157 & 1 & 0 \
alpha = 0.8 & 0.0281825 & 8/31 & 1.735783 & 7 & 1 \
alpha = 0.6 & 0.02425659 & 8/31 & 1.711518 & 26 & 2 \
alpha = 0.4 & 0.021494 & 7/31 & 1.706627 & 29 & 2 \
alpha = 0.2 & 0.02001998 & 7/31 & 1.70708 & 32 & 2 \
rowcolorlightgrayalpha = 0 & 0.01946719 & 7/31 & 1.707758 & 36 & 2 \ bottomrule
endtabular
endtable
enddocument





share|improve this answer






















  • 1





    Choosing a format for a table is always a difficult task. I like having it in landscape since I have other tables that go along with it (not shown in MWE), and in landscape it all fits nicely on one page. I do like the idea of separating the long table into two separate ones! I will experiment with all of your answers and see which one is best :)

    – Aiden Kenny
    Jul 28 at 18:55


















4














To bunch of examples in @leandriis's answer let me add two more examples:



documentclassarticle
usepackagebooktabs,tabularx
usepackagesiunitx
usepackage[table]xcolor
newcommandmycccellcolorlightgray
newcommandmyccs[2]cellcolorlightgraytablenum[table-format=#1]#2
%---------------- show page layout. don't use in a real document!
usepackageshowframe
renewcommandShowFrameLinethickness0.15pt
renewcommand*ShowFrameColorcolorred

begindocument
begintable[ht]
small
captionWith use of textttsiunitx and its option texttttablenum and texttttabularx
setlengthtabcolsep2.4pt
centering
begintabularxlinewidth@
>columncolorwhite[0pt][tabcolsep]l
S[table-format=1.8]
r
S[table-format=1.6]
S[table-format=3]
>centeringX
@quad
l
S[table-format=1.8]
r
S[table-format=1.6]
S[table-format=3]
>columncolorwhite[tabcolsep][0pt]centeringarraybackslashX
@
toprule
& multicolumn5c$K$-means Clustering &
& multicolumn5cHierarchical Clustering \
cmidrule(r)2-6 cmidrule(r)8-12
$alpha$ & $lambda$ & MC & Deviance & SC & SG &
$alpha$ & $lambda$ & MC & Deviance & SC & SG \
midrule
1 & 0.05873092 & 11/31 & 1.730157 & 1 & 0 &
1 & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
0.8 & 0.0281825 & 8/31 & 1.735783 & 7 & 1 &
0.8 & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
0.6 & 0.02425659 & 8/31 & 1.711518 & 26 & 2 &
0.6 & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
mycc0.4
& myccs1.80.021494
& mycc7/31
& myccs1.61.706627
& myccs329
& mycc2 &
0.4 & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
0.2 & 0.02001998 & 7/31 & 1.70708 & 32 & 2 &
0.2 & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
0 & 0.01946719 & 7/31 & 1.707758 & 36 & 2 &
mycc0
& myccs1.80.01921006
& mycc11/31
& myccs1.61.725663
& myccs3472
& mycc1 \
midrule[heavyrulewidth]
multicolumn12plinewidth
MC: Missclass.,
SG: Sig. Coef.,
SG: Sig. Groups
endtabularx
endtable

begintable[ht]
captionWith use of textttsiunitx and texttttabular
centering
begintabularS[table-format=1.1]
S[table-format=1.8]
c
S[table-format=1.6]
S[table-format=3]
c
toprule
$alpha$ & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\
midrule
multicolumn6@lHierarchical Clustering \
1 & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
0.8 & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
0.6 & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
rowcolorlightgray
0.4 & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
0.2 & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
0 & 0.01921006 & 11/31 & 1.725663 & 472 & 1 \
midrule
multicolumn6@l$K$-means Clustering \
1 & 0.05873092 & 11/31 & 1.730157 & 1 & 0 \
0.8 & 0.0281825 & 8/31 & 1.735783 & 7 & 1 \
0.6 & 0.02425659 & 8/31 & 1.711518 & 26 & 2 \
0.4 & 0.021494 & 7/31 & 1.706627 & 29 & 2 \
0.2 & 0.02001998 & 7/31 & 1.70708 & 32 & 2 \
rowcolorlightgray
0 & 0.01946719 & 7/31 & 1.707758 & 36 & 2 \
bottomrule
endtabular
endtable
enddocument


enter image description here



(red lines indicate text borders)






share|improve this answer



























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "85"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f501787%2fcoloring-only-part-of-a-row-in-a-table%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    6














    As far as I know, the colortbl package only offers methods to easily color a whole row or a whole column. If you only want to color parts of it, there is the cellcolor command. If you don't want to repeat it with the same color definition over and over again, you could use an abbreviation. (Might also come in handy, if you later on decide that you want to change the color). Please also note that I have removed the superfluous $ that surrounded every number in your original example code. Also, I guessed the settings for the geometry package as they were not given in your example.



    enter image description here



    documentclassarticle
    usepackage[margin=2cm]geometry
    usepackagetabularx
    usepackagepdflscape
    usepackagebooktabs
    usepackage[table]xcolor
    newcommandmycccellcolorlightgray

    begindocument
    beginlandscape
    begintable[ht]
    centering
    defarraystretch1.5
    begintabularxlinewidthlccccclccccc toprule
    & multicolumn5c$K$-means Clustering & & multicolumn5cHierarchical Clustering \ cmidrule(r)2-6 cmidrule(lr)8-12
    & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups & & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\ midrule
    $alpha = 1$ & 0.05873092 & 11/31 & 1.730157 & 1 & 0 & $alpha = 1$ & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
    $alpha = 0.8$ & 0.0281825 & 8/31 & 1.735783 & 7 & 1 & $alpha = 0.8$ & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
    $alpha = 0.6$ & 0.02425659 & 8/31 & 1.711518 & 26 & 2 & $alpha = 0.6$ & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
    mycc$alpha = 0.4$ & mycc 0.021494 & mycc 7/31 & mycc 1.706627 & mycc 29 & mycc 2 & $alpha = 0.4$ & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
    $alpha = 0.2$ & 0.02001998 & 7/31 & 1.70708 & 32 & 2 & $alpha = 0.2$ & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
    $alpha = 0$ & 0.01946719 & 7/31 & 1.707758 & 36 & 2 & mycc$alpha = 0$ & mycc 0.01921006 & mycc 11/31 & mycc 1.725663 & mycc 472 & mycc 1 \ bottomrule
    endtabularx

    endtable
    endlandscape
    enddocument



    You seem to have already noticed that the horizontal lines continue all the way to the right margin even though the table's contents are not that wide. This is due to your usage of tabularx that I have not corrected in the above MWE. If you want your table to be as wide as the textwidth and are open to a slight redesign of your table, you might be interested in the following MWE (that also just needs one rowcolor command to color the mentioned cells):



    enter image description here



    documentclassarticle
    usepackage[margin=2cm]geometry
    usepackagepdflscape
    usepackagebooktabs
    usepackage[table]xcolor

    begindocument


    beginlandscape
    begintable[ht]
    centering
    defarraystretch1.5
    begintabularlccccc toprule
    & multicolumn5cHierarchical Clustering \ cmidrule(lr)2-6
    & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\ midrule
    $alpha = 1$ & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
    $alpha = 0.8$ & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
    $alpha = 0.6$ & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
    rowcolorlightgray$alpha = 0.4$ & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
    $alpha = 0.2$ & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
    $alpha = 0$ & 0.01921006 & 11/31 & 1.725663 & 472 & 1 \ bottomrule
    endtabular
    hfill
    begintabularlccccc toprule
    & multicolumn5c$K$-means Clustering \ cmidrule(r)2-6
    & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups \ midrule
    $alpha = 1$ & 0.05873092 & 11/31 & 1.730157 & 1 & 0 \
    $alpha = 0.8$ & 0.0281825 & 8/31 & 1.735783 & 7 & 1 \
    $alpha = 0.6$ & 0.02425659 & 8/31 & 1.711518 & 26 & 2 \
    $alpha = 0.4$ & 0.021494 & 7/31 & 1.706627 & 29 & 2 \
    $alpha = 0.2$ & 0.02001998 & 7/31 & 1.70708 & 32 & 2 \
    rowcolorlightgray $alpha = 0$ & 0.01946719 & 7/31 & 1.707758 & 36 & 2 \ bottomrule
    endtabular
    endtable
    endlandscape


    enddocument



    Starting from this redesign you might also want to rethink if a landscape orientation is really necessary, as your table can fit into the text block of a portrait page (even with standard margins) perfectly fine:



    enter image description here



    documentclassarticle
    usepackagebooktabs
    usepackage[table]xcolor

    begindocument


    begintable[ht]
    centering
    defarraystretch1.5
    begintabularlccccc toprule
    & multicolumn5cHierarchical Clustering \ cmidrule(lr)2-6
    & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\ midrule
    $alpha = 1$ & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
    $alpha = 0.8$ & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
    $alpha = 0.6$ & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
    rowcolorlightgray$alpha = 0.4$ & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
    $alpha = 0.2$ & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
    $alpha = 0$ & 0.01921006 & 11/31 & 1.725663 & 472 & 1 \ midrule
    & multicolumn5c $K$-means Clustering \ cmidrule(r)2-6
    & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups \ midrule
    $alpha = 1$ & 0.05873092 & 11/31 & 1.730157 & 1 & 0 \
    $alpha = 0.8$ & 0.0281825 & 8/31 & 1.735783 & 7 & 1 \
    $alpha = 0.6$ & 0.02425659 & 8/31 & 1.711518 & 26 & 2 \
    $alpha = 0.4$ & 0.021494 & 7/31 & 1.706627 & 29 & 2 \
    $alpha = 0.2$ & 0.02001998 & 7/31 & 1.70708 & 32 & 2 \
    rowcolorlightgray$alpha = 0$ & 0.01946719 & 7/31 & 1.707758 & 36 & 2 \ bottomrule
    endtabular
    endtable



    enddocument



    Finally, here is the layout I personally would go for. Here I have used the S type columns from the siunitx package in order to align the numbers with respect to the decimal marker and used >(l<) in order to automatically set the comments of the first column in math mode.



    enter image description here



    documentclassarticle

    usepackagebooktabs
    usepackagesiunitx
    usepackage[table]xcolor

    begindocument
    begintable[ht]
    centering
    begintabular@quad>(l<)S[table-format=1.8]cS[table-format=1.6]S[table-format=3]c toprule

    & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\ midrule
    multicolumn6@lHierarchical Clustering \
    alpha = 1 & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
    alpha = 0.8 & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
    alpha = 0.6 & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
    rowcolorlightgrayalpha = 0.4 & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
    alpha = 0.2 & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
    alpha = 0 & 0.01921006 & 11/31 & 1.725663 & 472 & 1 \ midrule
    multicolumn6@l$K$-means Clustering \
    alpha = 1 & 0.05873092 & 11/31 & 1.730157 & 1 & 0 \
    alpha = 0.8 & 0.0281825 & 8/31 & 1.735783 & 7 & 1 \
    alpha = 0.6 & 0.02425659 & 8/31 & 1.711518 & 26 & 2 \
    alpha = 0.4 & 0.021494 & 7/31 & 1.706627 & 29 & 2 \
    alpha = 0.2 & 0.02001998 & 7/31 & 1.70708 & 32 & 2 \
    rowcolorlightgrayalpha = 0 & 0.01946719 & 7/31 & 1.707758 & 36 & 2 \ bottomrule
    endtabular
    endtable
    enddocument





    share|improve this answer






















    • 1





      Choosing a format for a table is always a difficult task. I like having it in landscape since I have other tables that go along with it (not shown in MWE), and in landscape it all fits nicely on one page. I do like the idea of separating the long table into two separate ones! I will experiment with all of your answers and see which one is best :)

      – Aiden Kenny
      Jul 28 at 18:55















    6














    As far as I know, the colortbl package only offers methods to easily color a whole row or a whole column. If you only want to color parts of it, there is the cellcolor command. If you don't want to repeat it with the same color definition over and over again, you could use an abbreviation. (Might also come in handy, if you later on decide that you want to change the color). Please also note that I have removed the superfluous $ that surrounded every number in your original example code. Also, I guessed the settings for the geometry package as they were not given in your example.



    enter image description here



    documentclassarticle
    usepackage[margin=2cm]geometry
    usepackagetabularx
    usepackagepdflscape
    usepackagebooktabs
    usepackage[table]xcolor
    newcommandmycccellcolorlightgray

    begindocument
    beginlandscape
    begintable[ht]
    centering
    defarraystretch1.5
    begintabularxlinewidthlccccclccccc toprule
    & multicolumn5c$K$-means Clustering & & multicolumn5cHierarchical Clustering \ cmidrule(r)2-6 cmidrule(lr)8-12
    & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups & & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\ midrule
    $alpha = 1$ & 0.05873092 & 11/31 & 1.730157 & 1 & 0 & $alpha = 1$ & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
    $alpha = 0.8$ & 0.0281825 & 8/31 & 1.735783 & 7 & 1 & $alpha = 0.8$ & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
    $alpha = 0.6$ & 0.02425659 & 8/31 & 1.711518 & 26 & 2 & $alpha = 0.6$ & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
    mycc$alpha = 0.4$ & mycc 0.021494 & mycc 7/31 & mycc 1.706627 & mycc 29 & mycc 2 & $alpha = 0.4$ & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
    $alpha = 0.2$ & 0.02001998 & 7/31 & 1.70708 & 32 & 2 & $alpha = 0.2$ & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
    $alpha = 0$ & 0.01946719 & 7/31 & 1.707758 & 36 & 2 & mycc$alpha = 0$ & mycc 0.01921006 & mycc 11/31 & mycc 1.725663 & mycc 472 & mycc 1 \ bottomrule
    endtabularx

    endtable
    endlandscape
    enddocument



    You seem to have already noticed that the horizontal lines continue all the way to the right margin even though the table's contents are not that wide. This is due to your usage of tabularx that I have not corrected in the above MWE. If you want your table to be as wide as the textwidth and are open to a slight redesign of your table, you might be interested in the following MWE (that also just needs one rowcolor command to color the mentioned cells):



    enter image description here



    documentclassarticle
    usepackage[margin=2cm]geometry
    usepackagepdflscape
    usepackagebooktabs
    usepackage[table]xcolor

    begindocument


    beginlandscape
    begintable[ht]
    centering
    defarraystretch1.5
    begintabularlccccc toprule
    & multicolumn5cHierarchical Clustering \ cmidrule(lr)2-6
    & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\ midrule
    $alpha = 1$ & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
    $alpha = 0.8$ & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
    $alpha = 0.6$ & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
    rowcolorlightgray$alpha = 0.4$ & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
    $alpha = 0.2$ & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
    $alpha = 0$ & 0.01921006 & 11/31 & 1.725663 & 472 & 1 \ bottomrule
    endtabular
    hfill
    begintabularlccccc toprule
    & multicolumn5c$K$-means Clustering \ cmidrule(r)2-6
    & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups \ midrule
    $alpha = 1$ & 0.05873092 & 11/31 & 1.730157 & 1 & 0 \
    $alpha = 0.8$ & 0.0281825 & 8/31 & 1.735783 & 7 & 1 \
    $alpha = 0.6$ & 0.02425659 & 8/31 & 1.711518 & 26 & 2 \
    $alpha = 0.4$ & 0.021494 & 7/31 & 1.706627 & 29 & 2 \
    $alpha = 0.2$ & 0.02001998 & 7/31 & 1.70708 & 32 & 2 \
    rowcolorlightgray $alpha = 0$ & 0.01946719 & 7/31 & 1.707758 & 36 & 2 \ bottomrule
    endtabular
    endtable
    endlandscape


    enddocument



    Starting from this redesign you might also want to rethink if a landscape orientation is really necessary, as your table can fit into the text block of a portrait page (even with standard margins) perfectly fine:



    enter image description here



    documentclassarticle
    usepackagebooktabs
    usepackage[table]xcolor

    begindocument


    begintable[ht]
    centering
    defarraystretch1.5
    begintabularlccccc toprule
    & multicolumn5cHierarchical Clustering \ cmidrule(lr)2-6
    & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\ midrule
    $alpha = 1$ & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
    $alpha = 0.8$ & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
    $alpha = 0.6$ & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
    rowcolorlightgray$alpha = 0.4$ & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
    $alpha = 0.2$ & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
    $alpha = 0$ & 0.01921006 & 11/31 & 1.725663 & 472 & 1 \ midrule
    & multicolumn5c $K$-means Clustering \ cmidrule(r)2-6
    & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups \ midrule
    $alpha = 1$ & 0.05873092 & 11/31 & 1.730157 & 1 & 0 \
    $alpha = 0.8$ & 0.0281825 & 8/31 & 1.735783 & 7 & 1 \
    $alpha = 0.6$ & 0.02425659 & 8/31 & 1.711518 & 26 & 2 \
    $alpha = 0.4$ & 0.021494 & 7/31 & 1.706627 & 29 & 2 \
    $alpha = 0.2$ & 0.02001998 & 7/31 & 1.70708 & 32 & 2 \
    rowcolorlightgray$alpha = 0$ & 0.01946719 & 7/31 & 1.707758 & 36 & 2 \ bottomrule
    endtabular
    endtable



    enddocument



    Finally, here is the layout I personally would go for. Here I have used the S type columns from the siunitx package in order to align the numbers with respect to the decimal marker and used >(l<) in order to automatically set the comments of the first column in math mode.



    enter image description here



    documentclassarticle

    usepackagebooktabs
    usepackagesiunitx
    usepackage[table]xcolor

    begindocument
    begintable[ht]
    centering
    begintabular@quad>(l<)S[table-format=1.8]cS[table-format=1.6]S[table-format=3]c toprule

    & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\ midrule
    multicolumn6@lHierarchical Clustering \
    alpha = 1 & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
    alpha = 0.8 & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
    alpha = 0.6 & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
    rowcolorlightgrayalpha = 0.4 & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
    alpha = 0.2 & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
    alpha = 0 & 0.01921006 & 11/31 & 1.725663 & 472 & 1 \ midrule
    multicolumn6@l$K$-means Clustering \
    alpha = 1 & 0.05873092 & 11/31 & 1.730157 & 1 & 0 \
    alpha = 0.8 & 0.0281825 & 8/31 & 1.735783 & 7 & 1 \
    alpha = 0.6 & 0.02425659 & 8/31 & 1.711518 & 26 & 2 \
    alpha = 0.4 & 0.021494 & 7/31 & 1.706627 & 29 & 2 \
    alpha = 0.2 & 0.02001998 & 7/31 & 1.70708 & 32 & 2 \
    rowcolorlightgrayalpha = 0 & 0.01946719 & 7/31 & 1.707758 & 36 & 2 \ bottomrule
    endtabular
    endtable
    enddocument





    share|improve this answer






















    • 1





      Choosing a format for a table is always a difficult task. I like having it in landscape since I have other tables that go along with it (not shown in MWE), and in landscape it all fits nicely on one page. I do like the idea of separating the long table into two separate ones! I will experiment with all of your answers and see which one is best :)

      – Aiden Kenny
      Jul 28 at 18:55













    6












    6








    6







    As far as I know, the colortbl package only offers methods to easily color a whole row or a whole column. If you only want to color parts of it, there is the cellcolor command. If you don't want to repeat it with the same color definition over and over again, you could use an abbreviation. (Might also come in handy, if you later on decide that you want to change the color). Please also note that I have removed the superfluous $ that surrounded every number in your original example code. Also, I guessed the settings for the geometry package as they were not given in your example.



    enter image description here



    documentclassarticle
    usepackage[margin=2cm]geometry
    usepackagetabularx
    usepackagepdflscape
    usepackagebooktabs
    usepackage[table]xcolor
    newcommandmycccellcolorlightgray

    begindocument
    beginlandscape
    begintable[ht]
    centering
    defarraystretch1.5
    begintabularxlinewidthlccccclccccc toprule
    & multicolumn5c$K$-means Clustering & & multicolumn5cHierarchical Clustering \ cmidrule(r)2-6 cmidrule(lr)8-12
    & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups & & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\ midrule
    $alpha = 1$ & 0.05873092 & 11/31 & 1.730157 & 1 & 0 & $alpha = 1$ & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
    $alpha = 0.8$ & 0.0281825 & 8/31 & 1.735783 & 7 & 1 & $alpha = 0.8$ & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
    $alpha = 0.6$ & 0.02425659 & 8/31 & 1.711518 & 26 & 2 & $alpha = 0.6$ & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
    mycc$alpha = 0.4$ & mycc 0.021494 & mycc 7/31 & mycc 1.706627 & mycc 29 & mycc 2 & $alpha = 0.4$ & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
    $alpha = 0.2$ & 0.02001998 & 7/31 & 1.70708 & 32 & 2 & $alpha = 0.2$ & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
    $alpha = 0$ & 0.01946719 & 7/31 & 1.707758 & 36 & 2 & mycc$alpha = 0$ & mycc 0.01921006 & mycc 11/31 & mycc 1.725663 & mycc 472 & mycc 1 \ bottomrule
    endtabularx

    endtable
    endlandscape
    enddocument



    You seem to have already noticed that the horizontal lines continue all the way to the right margin even though the table's contents are not that wide. This is due to your usage of tabularx that I have not corrected in the above MWE. If you want your table to be as wide as the textwidth and are open to a slight redesign of your table, you might be interested in the following MWE (that also just needs one rowcolor command to color the mentioned cells):



    enter image description here



    documentclassarticle
    usepackage[margin=2cm]geometry
    usepackagepdflscape
    usepackagebooktabs
    usepackage[table]xcolor

    begindocument


    beginlandscape
    begintable[ht]
    centering
    defarraystretch1.5
    begintabularlccccc toprule
    & multicolumn5cHierarchical Clustering \ cmidrule(lr)2-6
    & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\ midrule
    $alpha = 1$ & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
    $alpha = 0.8$ & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
    $alpha = 0.6$ & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
    rowcolorlightgray$alpha = 0.4$ & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
    $alpha = 0.2$ & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
    $alpha = 0$ & 0.01921006 & 11/31 & 1.725663 & 472 & 1 \ bottomrule
    endtabular
    hfill
    begintabularlccccc toprule
    & multicolumn5c$K$-means Clustering \ cmidrule(r)2-6
    & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups \ midrule
    $alpha = 1$ & 0.05873092 & 11/31 & 1.730157 & 1 & 0 \
    $alpha = 0.8$ & 0.0281825 & 8/31 & 1.735783 & 7 & 1 \
    $alpha = 0.6$ & 0.02425659 & 8/31 & 1.711518 & 26 & 2 \
    $alpha = 0.4$ & 0.021494 & 7/31 & 1.706627 & 29 & 2 \
    $alpha = 0.2$ & 0.02001998 & 7/31 & 1.70708 & 32 & 2 \
    rowcolorlightgray $alpha = 0$ & 0.01946719 & 7/31 & 1.707758 & 36 & 2 \ bottomrule
    endtabular
    endtable
    endlandscape


    enddocument



    Starting from this redesign you might also want to rethink if a landscape orientation is really necessary, as your table can fit into the text block of a portrait page (even with standard margins) perfectly fine:



    enter image description here



    documentclassarticle
    usepackagebooktabs
    usepackage[table]xcolor

    begindocument


    begintable[ht]
    centering
    defarraystretch1.5
    begintabularlccccc toprule
    & multicolumn5cHierarchical Clustering \ cmidrule(lr)2-6
    & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\ midrule
    $alpha = 1$ & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
    $alpha = 0.8$ & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
    $alpha = 0.6$ & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
    rowcolorlightgray$alpha = 0.4$ & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
    $alpha = 0.2$ & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
    $alpha = 0$ & 0.01921006 & 11/31 & 1.725663 & 472 & 1 \ midrule
    & multicolumn5c $K$-means Clustering \ cmidrule(r)2-6
    & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups \ midrule
    $alpha = 1$ & 0.05873092 & 11/31 & 1.730157 & 1 & 0 \
    $alpha = 0.8$ & 0.0281825 & 8/31 & 1.735783 & 7 & 1 \
    $alpha = 0.6$ & 0.02425659 & 8/31 & 1.711518 & 26 & 2 \
    $alpha = 0.4$ & 0.021494 & 7/31 & 1.706627 & 29 & 2 \
    $alpha = 0.2$ & 0.02001998 & 7/31 & 1.70708 & 32 & 2 \
    rowcolorlightgray$alpha = 0$ & 0.01946719 & 7/31 & 1.707758 & 36 & 2 \ bottomrule
    endtabular
    endtable



    enddocument



    Finally, here is the layout I personally would go for. Here I have used the S type columns from the siunitx package in order to align the numbers with respect to the decimal marker and used >(l<) in order to automatically set the comments of the first column in math mode.



    enter image description here



    documentclassarticle

    usepackagebooktabs
    usepackagesiunitx
    usepackage[table]xcolor

    begindocument
    begintable[ht]
    centering
    begintabular@quad>(l<)S[table-format=1.8]cS[table-format=1.6]S[table-format=3]c toprule

    & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\ midrule
    multicolumn6@lHierarchical Clustering \
    alpha = 1 & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
    alpha = 0.8 & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
    alpha = 0.6 & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
    rowcolorlightgrayalpha = 0.4 & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
    alpha = 0.2 & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
    alpha = 0 & 0.01921006 & 11/31 & 1.725663 & 472 & 1 \ midrule
    multicolumn6@l$K$-means Clustering \
    alpha = 1 & 0.05873092 & 11/31 & 1.730157 & 1 & 0 \
    alpha = 0.8 & 0.0281825 & 8/31 & 1.735783 & 7 & 1 \
    alpha = 0.6 & 0.02425659 & 8/31 & 1.711518 & 26 & 2 \
    alpha = 0.4 & 0.021494 & 7/31 & 1.706627 & 29 & 2 \
    alpha = 0.2 & 0.02001998 & 7/31 & 1.70708 & 32 & 2 \
    rowcolorlightgrayalpha = 0 & 0.01946719 & 7/31 & 1.707758 & 36 & 2 \ bottomrule
    endtabular
    endtable
    enddocument





    share|improve this answer















    As far as I know, the colortbl package only offers methods to easily color a whole row or a whole column. If you only want to color parts of it, there is the cellcolor command. If you don't want to repeat it with the same color definition over and over again, you could use an abbreviation. (Might also come in handy, if you later on decide that you want to change the color). Please also note that I have removed the superfluous $ that surrounded every number in your original example code. Also, I guessed the settings for the geometry package as they were not given in your example.



    enter image description here



    documentclassarticle
    usepackage[margin=2cm]geometry
    usepackagetabularx
    usepackagepdflscape
    usepackagebooktabs
    usepackage[table]xcolor
    newcommandmycccellcolorlightgray

    begindocument
    beginlandscape
    begintable[ht]
    centering
    defarraystretch1.5
    begintabularxlinewidthlccccclccccc toprule
    & multicolumn5c$K$-means Clustering & & multicolumn5cHierarchical Clustering \ cmidrule(r)2-6 cmidrule(lr)8-12
    & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups & & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\ midrule
    $alpha = 1$ & 0.05873092 & 11/31 & 1.730157 & 1 & 0 & $alpha = 1$ & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
    $alpha = 0.8$ & 0.0281825 & 8/31 & 1.735783 & 7 & 1 & $alpha = 0.8$ & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
    $alpha = 0.6$ & 0.02425659 & 8/31 & 1.711518 & 26 & 2 & $alpha = 0.6$ & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
    mycc$alpha = 0.4$ & mycc 0.021494 & mycc 7/31 & mycc 1.706627 & mycc 29 & mycc 2 & $alpha = 0.4$ & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
    $alpha = 0.2$ & 0.02001998 & 7/31 & 1.70708 & 32 & 2 & $alpha = 0.2$ & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
    $alpha = 0$ & 0.01946719 & 7/31 & 1.707758 & 36 & 2 & mycc$alpha = 0$ & mycc 0.01921006 & mycc 11/31 & mycc 1.725663 & mycc 472 & mycc 1 \ bottomrule
    endtabularx

    endtable
    endlandscape
    enddocument



    You seem to have already noticed that the horizontal lines continue all the way to the right margin even though the table's contents are not that wide. This is due to your usage of tabularx that I have not corrected in the above MWE. If you want your table to be as wide as the textwidth and are open to a slight redesign of your table, you might be interested in the following MWE (that also just needs one rowcolor command to color the mentioned cells):



    enter image description here



    documentclassarticle
    usepackage[margin=2cm]geometry
    usepackagepdflscape
    usepackagebooktabs
    usepackage[table]xcolor

    begindocument


    beginlandscape
    begintable[ht]
    centering
    defarraystretch1.5
    begintabularlccccc toprule
    & multicolumn5cHierarchical Clustering \ cmidrule(lr)2-6
    & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\ midrule
    $alpha = 1$ & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
    $alpha = 0.8$ & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
    $alpha = 0.6$ & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
    rowcolorlightgray$alpha = 0.4$ & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
    $alpha = 0.2$ & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
    $alpha = 0$ & 0.01921006 & 11/31 & 1.725663 & 472 & 1 \ bottomrule
    endtabular
    hfill
    begintabularlccccc toprule
    & multicolumn5c$K$-means Clustering \ cmidrule(r)2-6
    & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups \ midrule
    $alpha = 1$ & 0.05873092 & 11/31 & 1.730157 & 1 & 0 \
    $alpha = 0.8$ & 0.0281825 & 8/31 & 1.735783 & 7 & 1 \
    $alpha = 0.6$ & 0.02425659 & 8/31 & 1.711518 & 26 & 2 \
    $alpha = 0.4$ & 0.021494 & 7/31 & 1.706627 & 29 & 2 \
    $alpha = 0.2$ & 0.02001998 & 7/31 & 1.70708 & 32 & 2 \
    rowcolorlightgray $alpha = 0$ & 0.01946719 & 7/31 & 1.707758 & 36 & 2 \ bottomrule
    endtabular
    endtable
    endlandscape


    enddocument



    Starting from this redesign you might also want to rethink if a landscape orientation is really necessary, as your table can fit into the text block of a portrait page (even with standard margins) perfectly fine:



    enter image description here



    documentclassarticle
    usepackagebooktabs
    usepackage[table]xcolor

    begindocument


    begintable[ht]
    centering
    defarraystretch1.5
    begintabularlccccc toprule
    & multicolumn5cHierarchical Clustering \ cmidrule(lr)2-6
    & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\ midrule
    $alpha = 1$ & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
    $alpha = 0.8$ & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
    $alpha = 0.6$ & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
    rowcolorlightgray$alpha = 0.4$ & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
    $alpha = 0.2$ & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
    $alpha = 0$ & 0.01921006 & 11/31 & 1.725663 & 472 & 1 \ midrule
    & multicolumn5c $K$-means Clustering \ cmidrule(r)2-6
    & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups \ midrule
    $alpha = 1$ & 0.05873092 & 11/31 & 1.730157 & 1 & 0 \
    $alpha = 0.8$ & 0.0281825 & 8/31 & 1.735783 & 7 & 1 \
    $alpha = 0.6$ & 0.02425659 & 8/31 & 1.711518 & 26 & 2 \
    $alpha = 0.4$ & 0.021494 & 7/31 & 1.706627 & 29 & 2 \
    $alpha = 0.2$ & 0.02001998 & 7/31 & 1.70708 & 32 & 2 \
    rowcolorlightgray$alpha = 0$ & 0.01946719 & 7/31 & 1.707758 & 36 & 2 \ bottomrule
    endtabular
    endtable



    enddocument



    Finally, here is the layout I personally would go for. Here I have used the S type columns from the siunitx package in order to align the numbers with respect to the decimal marker and used >(l<) in order to automatically set the comments of the first column in math mode.



    enter image description here



    documentclassarticle

    usepackagebooktabs
    usepackagesiunitx
    usepackage[table]xcolor

    begindocument
    begintable[ht]
    centering
    begintabular@quad>(l<)S[table-format=1.8]cS[table-format=1.6]S[table-format=3]c toprule

    & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\ midrule
    multicolumn6@lHierarchical Clustering \
    alpha = 1 & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
    alpha = 0.8 & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
    alpha = 0.6 & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
    rowcolorlightgrayalpha = 0.4 & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
    alpha = 0.2 & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
    alpha = 0 & 0.01921006 & 11/31 & 1.725663 & 472 & 1 \ midrule
    multicolumn6@l$K$-means Clustering \
    alpha = 1 & 0.05873092 & 11/31 & 1.730157 & 1 & 0 \
    alpha = 0.8 & 0.0281825 & 8/31 & 1.735783 & 7 & 1 \
    alpha = 0.6 & 0.02425659 & 8/31 & 1.711518 & 26 & 2 \
    alpha = 0.4 & 0.021494 & 7/31 & 1.706627 & 29 & 2 \
    alpha = 0.2 & 0.02001998 & 7/31 & 1.70708 & 32 & 2 \
    rowcolorlightgrayalpha = 0 & 0.01946719 & 7/31 & 1.707758 & 36 & 2 \ bottomrule
    endtabular
    endtable
    enddocument






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jul 28 at 18:54









    Aiden Kenny

    6557 bronze badges




    6557 bronze badges










    answered Jul 28 at 8:45









    leandriisleandriis

    17.7k1 gold badge11 silver badges37 bronze badges




    17.7k1 gold badge11 silver badges37 bronze badges










    • 1





      Choosing a format for a table is always a difficult task. I like having it in landscape since I have other tables that go along with it (not shown in MWE), and in landscape it all fits nicely on one page. I do like the idea of separating the long table into two separate ones! I will experiment with all of your answers and see which one is best :)

      – Aiden Kenny
      Jul 28 at 18:55












    • 1





      Choosing a format for a table is always a difficult task. I like having it in landscape since I have other tables that go along with it (not shown in MWE), and in landscape it all fits nicely on one page. I do like the idea of separating the long table into two separate ones! I will experiment with all of your answers and see which one is best :)

      – Aiden Kenny
      Jul 28 at 18:55







    1




    1





    Choosing a format for a table is always a difficult task. I like having it in landscape since I have other tables that go along with it (not shown in MWE), and in landscape it all fits nicely on one page. I do like the idea of separating the long table into two separate ones! I will experiment with all of your answers and see which one is best :)

    – Aiden Kenny
    Jul 28 at 18:55





    Choosing a format for a table is always a difficult task. I like having it in landscape since I have other tables that go along with it (not shown in MWE), and in landscape it all fits nicely on one page. I do like the idea of separating the long table into two separate ones! I will experiment with all of your answers and see which one is best :)

    – Aiden Kenny
    Jul 28 at 18:55













    4














    To bunch of examples in @leandriis's answer let me add two more examples:



    documentclassarticle
    usepackagebooktabs,tabularx
    usepackagesiunitx
    usepackage[table]xcolor
    newcommandmycccellcolorlightgray
    newcommandmyccs[2]cellcolorlightgraytablenum[table-format=#1]#2
    %---------------- show page layout. don't use in a real document!
    usepackageshowframe
    renewcommandShowFrameLinethickness0.15pt
    renewcommand*ShowFrameColorcolorred

    begindocument
    begintable[ht]
    small
    captionWith use of textttsiunitx and its option texttttablenum and texttttabularx
    setlengthtabcolsep2.4pt
    centering
    begintabularxlinewidth@
    >columncolorwhite[0pt][tabcolsep]l
    S[table-format=1.8]
    r
    S[table-format=1.6]
    S[table-format=3]
    >centeringX
    @quad
    l
    S[table-format=1.8]
    r
    S[table-format=1.6]
    S[table-format=3]
    >columncolorwhite[tabcolsep][0pt]centeringarraybackslashX
    @
    toprule
    & multicolumn5c$K$-means Clustering &
    & multicolumn5cHierarchical Clustering \
    cmidrule(r)2-6 cmidrule(r)8-12
    $alpha$ & $lambda$ & MC & Deviance & SC & SG &
    $alpha$ & $lambda$ & MC & Deviance & SC & SG \
    midrule
    1 & 0.05873092 & 11/31 & 1.730157 & 1 & 0 &
    1 & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
    0.8 & 0.0281825 & 8/31 & 1.735783 & 7 & 1 &
    0.8 & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
    0.6 & 0.02425659 & 8/31 & 1.711518 & 26 & 2 &
    0.6 & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
    mycc0.4
    & myccs1.80.021494
    & mycc7/31
    & myccs1.61.706627
    & myccs329
    & mycc2 &
    0.4 & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
    0.2 & 0.02001998 & 7/31 & 1.70708 & 32 & 2 &
    0.2 & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
    0 & 0.01946719 & 7/31 & 1.707758 & 36 & 2 &
    mycc0
    & myccs1.80.01921006
    & mycc11/31
    & myccs1.61.725663
    & myccs3472
    & mycc1 \
    midrule[heavyrulewidth]
    multicolumn12plinewidth
    MC: Missclass.,
    SG: Sig. Coef.,
    SG: Sig. Groups
    endtabularx
    endtable

    begintable[ht]
    captionWith use of textttsiunitx and texttttabular
    centering
    begintabularS[table-format=1.1]
    S[table-format=1.8]
    c
    S[table-format=1.6]
    S[table-format=3]
    c
    toprule
    $alpha$ & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\
    midrule
    multicolumn6@lHierarchical Clustering \
    1 & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
    0.8 & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
    0.6 & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
    rowcolorlightgray
    0.4 & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
    0.2 & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
    0 & 0.01921006 & 11/31 & 1.725663 & 472 & 1 \
    midrule
    multicolumn6@l$K$-means Clustering \
    1 & 0.05873092 & 11/31 & 1.730157 & 1 & 0 \
    0.8 & 0.0281825 & 8/31 & 1.735783 & 7 & 1 \
    0.6 & 0.02425659 & 8/31 & 1.711518 & 26 & 2 \
    0.4 & 0.021494 & 7/31 & 1.706627 & 29 & 2 \
    0.2 & 0.02001998 & 7/31 & 1.70708 & 32 & 2 \
    rowcolorlightgray
    0 & 0.01946719 & 7/31 & 1.707758 & 36 & 2 \
    bottomrule
    endtabular
    endtable
    enddocument


    enter image description here



    (red lines indicate text borders)






    share|improve this answer





























      4














      To bunch of examples in @leandriis's answer let me add two more examples:



      documentclassarticle
      usepackagebooktabs,tabularx
      usepackagesiunitx
      usepackage[table]xcolor
      newcommandmycccellcolorlightgray
      newcommandmyccs[2]cellcolorlightgraytablenum[table-format=#1]#2
      %---------------- show page layout. don't use in a real document!
      usepackageshowframe
      renewcommandShowFrameLinethickness0.15pt
      renewcommand*ShowFrameColorcolorred

      begindocument
      begintable[ht]
      small
      captionWith use of textttsiunitx and its option texttttablenum and texttttabularx
      setlengthtabcolsep2.4pt
      centering
      begintabularxlinewidth@
      >columncolorwhite[0pt][tabcolsep]l
      S[table-format=1.8]
      r
      S[table-format=1.6]
      S[table-format=3]
      >centeringX
      @quad
      l
      S[table-format=1.8]
      r
      S[table-format=1.6]
      S[table-format=3]
      >columncolorwhite[tabcolsep][0pt]centeringarraybackslashX
      @
      toprule
      & multicolumn5c$K$-means Clustering &
      & multicolumn5cHierarchical Clustering \
      cmidrule(r)2-6 cmidrule(r)8-12
      $alpha$ & $lambda$ & MC & Deviance & SC & SG &
      $alpha$ & $lambda$ & MC & Deviance & SC & SG \
      midrule
      1 & 0.05873092 & 11/31 & 1.730157 & 1 & 0 &
      1 & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
      0.8 & 0.0281825 & 8/31 & 1.735783 & 7 & 1 &
      0.8 & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
      0.6 & 0.02425659 & 8/31 & 1.711518 & 26 & 2 &
      0.6 & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
      mycc0.4
      & myccs1.80.021494
      & mycc7/31
      & myccs1.61.706627
      & myccs329
      & mycc2 &
      0.4 & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
      0.2 & 0.02001998 & 7/31 & 1.70708 & 32 & 2 &
      0.2 & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
      0 & 0.01946719 & 7/31 & 1.707758 & 36 & 2 &
      mycc0
      & myccs1.80.01921006
      & mycc11/31
      & myccs1.61.725663
      & myccs3472
      & mycc1 \
      midrule[heavyrulewidth]
      multicolumn12plinewidth
      MC: Missclass.,
      SG: Sig. Coef.,
      SG: Sig. Groups
      endtabularx
      endtable

      begintable[ht]
      captionWith use of textttsiunitx and texttttabular
      centering
      begintabularS[table-format=1.1]
      S[table-format=1.8]
      c
      S[table-format=1.6]
      S[table-format=3]
      c
      toprule
      $alpha$ & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\
      midrule
      multicolumn6@lHierarchical Clustering \
      1 & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
      0.8 & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
      0.6 & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
      rowcolorlightgray
      0.4 & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
      0.2 & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
      0 & 0.01921006 & 11/31 & 1.725663 & 472 & 1 \
      midrule
      multicolumn6@l$K$-means Clustering \
      1 & 0.05873092 & 11/31 & 1.730157 & 1 & 0 \
      0.8 & 0.0281825 & 8/31 & 1.735783 & 7 & 1 \
      0.6 & 0.02425659 & 8/31 & 1.711518 & 26 & 2 \
      0.4 & 0.021494 & 7/31 & 1.706627 & 29 & 2 \
      0.2 & 0.02001998 & 7/31 & 1.70708 & 32 & 2 \
      rowcolorlightgray
      0 & 0.01946719 & 7/31 & 1.707758 & 36 & 2 \
      bottomrule
      endtabular
      endtable
      enddocument


      enter image description here



      (red lines indicate text borders)






      share|improve this answer



























        4












        4








        4







        To bunch of examples in @leandriis's answer let me add two more examples:



        documentclassarticle
        usepackagebooktabs,tabularx
        usepackagesiunitx
        usepackage[table]xcolor
        newcommandmycccellcolorlightgray
        newcommandmyccs[2]cellcolorlightgraytablenum[table-format=#1]#2
        %---------------- show page layout. don't use in a real document!
        usepackageshowframe
        renewcommandShowFrameLinethickness0.15pt
        renewcommand*ShowFrameColorcolorred

        begindocument
        begintable[ht]
        small
        captionWith use of textttsiunitx and its option texttttablenum and texttttabularx
        setlengthtabcolsep2.4pt
        centering
        begintabularxlinewidth@
        >columncolorwhite[0pt][tabcolsep]l
        S[table-format=1.8]
        r
        S[table-format=1.6]
        S[table-format=3]
        >centeringX
        @quad
        l
        S[table-format=1.8]
        r
        S[table-format=1.6]
        S[table-format=3]
        >columncolorwhite[tabcolsep][0pt]centeringarraybackslashX
        @
        toprule
        & multicolumn5c$K$-means Clustering &
        & multicolumn5cHierarchical Clustering \
        cmidrule(r)2-6 cmidrule(r)8-12
        $alpha$ & $lambda$ & MC & Deviance & SC & SG &
        $alpha$ & $lambda$ & MC & Deviance & SC & SG \
        midrule
        1 & 0.05873092 & 11/31 & 1.730157 & 1 & 0 &
        1 & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
        0.8 & 0.0281825 & 8/31 & 1.735783 & 7 & 1 &
        0.8 & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
        0.6 & 0.02425659 & 8/31 & 1.711518 & 26 & 2 &
        0.6 & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
        mycc0.4
        & myccs1.80.021494
        & mycc7/31
        & myccs1.61.706627
        & myccs329
        & mycc2 &
        0.4 & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
        0.2 & 0.02001998 & 7/31 & 1.70708 & 32 & 2 &
        0.2 & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
        0 & 0.01946719 & 7/31 & 1.707758 & 36 & 2 &
        mycc0
        & myccs1.80.01921006
        & mycc11/31
        & myccs1.61.725663
        & myccs3472
        & mycc1 \
        midrule[heavyrulewidth]
        multicolumn12plinewidth
        MC: Missclass.,
        SG: Sig. Coef.,
        SG: Sig. Groups
        endtabularx
        endtable

        begintable[ht]
        captionWith use of textttsiunitx and texttttabular
        centering
        begintabularS[table-format=1.1]
        S[table-format=1.8]
        c
        S[table-format=1.6]
        S[table-format=3]
        c
        toprule
        $alpha$ & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\
        midrule
        multicolumn6@lHierarchical Clustering \
        1 & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
        0.8 & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
        0.6 & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
        rowcolorlightgray
        0.4 & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
        0.2 & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
        0 & 0.01921006 & 11/31 & 1.725663 & 472 & 1 \
        midrule
        multicolumn6@l$K$-means Clustering \
        1 & 0.05873092 & 11/31 & 1.730157 & 1 & 0 \
        0.8 & 0.0281825 & 8/31 & 1.735783 & 7 & 1 \
        0.6 & 0.02425659 & 8/31 & 1.711518 & 26 & 2 \
        0.4 & 0.021494 & 7/31 & 1.706627 & 29 & 2 \
        0.2 & 0.02001998 & 7/31 & 1.70708 & 32 & 2 \
        rowcolorlightgray
        0 & 0.01946719 & 7/31 & 1.707758 & 36 & 2 \
        bottomrule
        endtabular
        endtable
        enddocument


        enter image description here



        (red lines indicate text borders)






        share|improve this answer













        To bunch of examples in @leandriis's answer let me add two more examples:



        documentclassarticle
        usepackagebooktabs,tabularx
        usepackagesiunitx
        usepackage[table]xcolor
        newcommandmycccellcolorlightgray
        newcommandmyccs[2]cellcolorlightgraytablenum[table-format=#1]#2
        %---------------- show page layout. don't use in a real document!
        usepackageshowframe
        renewcommandShowFrameLinethickness0.15pt
        renewcommand*ShowFrameColorcolorred

        begindocument
        begintable[ht]
        small
        captionWith use of textttsiunitx and its option texttttablenum and texttttabularx
        setlengthtabcolsep2.4pt
        centering
        begintabularxlinewidth@
        >columncolorwhite[0pt][tabcolsep]l
        S[table-format=1.8]
        r
        S[table-format=1.6]
        S[table-format=3]
        >centeringX
        @quad
        l
        S[table-format=1.8]
        r
        S[table-format=1.6]
        S[table-format=3]
        >columncolorwhite[tabcolsep][0pt]centeringarraybackslashX
        @
        toprule
        & multicolumn5c$K$-means Clustering &
        & multicolumn5cHierarchical Clustering \
        cmidrule(r)2-6 cmidrule(r)8-12
        $alpha$ & $lambda$ & MC & Deviance & SC & SG &
        $alpha$ & $lambda$ & MC & Deviance & SC & SG \
        midrule
        1 & 0.05873092 & 11/31 & 1.730157 & 1 & 0 &
        1 & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
        0.8 & 0.0281825 & 8/31 & 1.735783 & 7 & 1 &
        0.8 & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
        0.6 & 0.02425659 & 8/31 & 1.711518 & 26 & 2 &
        0.6 & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
        mycc0.4
        & myccs1.80.021494
        & mycc7/31
        & myccs1.61.706627
        & myccs329
        & mycc2 &
        0.4 & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
        0.2 & 0.02001998 & 7/31 & 1.70708 & 32 & 2 &
        0.2 & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
        0 & 0.01946719 & 7/31 & 1.707758 & 36 & 2 &
        mycc0
        & myccs1.80.01921006
        & mycc11/31
        & myccs1.61.725663
        & myccs3472
        & mycc1 \
        midrule[heavyrulewidth]
        multicolumn12plinewidth
        MC: Missclass.,
        SG: Sig. Coef.,
        SG: Sig. Groups
        endtabularx
        endtable

        begintable[ht]
        captionWith use of textttsiunitx and texttttabular
        centering
        begintabularS[table-format=1.1]
        S[table-format=1.8]
        c
        S[table-format=1.6]
        S[table-format=3]
        c
        toprule
        $alpha$ & $lambda$ & Misclass. & Deviance & Sig. Coef. & Sig. Groups\
        midrule
        multicolumn6@lHierarchical Clustering \
        1 & 0.05873092 & 11/31 & 1.741681 & 1 & 0 \
        0.8 & 0.02822086 & 11/31 & 1.732505 & 108 & 1 \
        0.6 & 0.02380529 & 11/31 & 1.727994 & 226 & 1 \
        rowcolorlightgray
        0.4 & 0.0214516 & 11/31 & 1.726991 & 319 & 1 \
        0.2 & 0.02007049 & 11/31 & 1.72622 & 393 & 1 \
        0 & 0.01921006 & 11/31 & 1.725663 & 472 & 1 \
        midrule
        multicolumn6@l$K$-means Clustering \
        1 & 0.05873092 & 11/31 & 1.730157 & 1 & 0 \
        0.8 & 0.0281825 & 8/31 & 1.735783 & 7 & 1 \
        0.6 & 0.02425659 & 8/31 & 1.711518 & 26 & 2 \
        0.4 & 0.021494 & 7/31 & 1.706627 & 29 & 2 \
        0.2 & 0.02001998 & 7/31 & 1.70708 & 32 & 2 \
        rowcolorlightgray
        0 & 0.01946719 & 7/31 & 1.707758 & 36 & 2 \
        bottomrule
        endtabular
        endtable
        enddocument


        enter image description here



        (red lines indicate text borders)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jul 28 at 11:45









        ZarkoZarko

        142k8 gold badges79 silver badges191 bronze badges




        142k8 gold badges79 silver badges191 bronze badges






























            draft saved

            draft discarded
















































            Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f501787%2fcoloring-only-part-of-a-row-in-a-table%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

            Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

            Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?