Color fraction of table cell











up vote
3
down vote

favorite












Is there some way to color only part of a table cell? For example, the top third, or bottom half of a cell?



For example:



renewcommand{arraystretch}{3.0}
begin{tabularx}{10cm}{|X|X|}
hline
Row 1 & cellcolor{blue!25} 1/3 colored \
hline
Row 2 & uncolored \
hline
end{tabularx}

renewcommand{arraystretch}{1.0}
begin{tabularx}{10cm}{|X|X|}
hline
&cellcolor{blue!25} \
& \
& \
hline
& \
& \
& \
hline
end{tabularx}

renewcommand{arraystretch}{1.0}
begin{tabularx}{10cm}{|X|X|}
hline
Row 1 &cellcolor{blue!25} 1/3 colored\
& \
& \
hline
Row 2 & uncolored \
& \
& \
hline
end{tabularx}


enter image description here



The first case shows how the text should appear, but clearly the cell is fully colored. In the second case, I split the two rows into six rows so that one third of the original cell can be individually colored. But when adding the text, it is no longer center in the middle of the true cells because it is put in the subcells.



What is the best way to do this?










share|improve this question


















  • 1




    Welcome to TeX.SX! Can you please expand the code snippets that you have posted to a full minimal working example. It is much easier to help you if we can start with some compilable code that illustrates your problem. A MWE should start with a documentclass command, include any necessary packages and be as small as possible to demonstrate your problem. At the moment we have to guess what packages etc you are using before we can compile your code.
    – Andrew
    Nov 12 at 22:10















up vote
3
down vote

favorite












Is there some way to color only part of a table cell? For example, the top third, or bottom half of a cell?



For example:



renewcommand{arraystretch}{3.0}
begin{tabularx}{10cm}{|X|X|}
hline
Row 1 & cellcolor{blue!25} 1/3 colored \
hline
Row 2 & uncolored \
hline
end{tabularx}

renewcommand{arraystretch}{1.0}
begin{tabularx}{10cm}{|X|X|}
hline
&cellcolor{blue!25} \
& \
& \
hline
& \
& \
& \
hline
end{tabularx}

renewcommand{arraystretch}{1.0}
begin{tabularx}{10cm}{|X|X|}
hline
Row 1 &cellcolor{blue!25} 1/3 colored\
& \
& \
hline
Row 2 & uncolored \
& \
& \
hline
end{tabularx}


enter image description here



The first case shows how the text should appear, but clearly the cell is fully colored. In the second case, I split the two rows into six rows so that one third of the original cell can be individually colored. But when adding the text, it is no longer center in the middle of the true cells because it is put in the subcells.



What is the best way to do this?










share|improve this question


















  • 1




    Welcome to TeX.SX! Can you please expand the code snippets that you have posted to a full minimal working example. It is much easier to help you if we can start with some compilable code that illustrates your problem. A MWE should start with a documentclass command, include any necessary packages and be as small as possible to demonstrate your problem. At the moment we have to guess what packages etc you are using before we can compile your code.
    – Andrew
    Nov 12 at 22:10













up vote
3
down vote

favorite









up vote
3
down vote

favorite











Is there some way to color only part of a table cell? For example, the top third, or bottom half of a cell?



For example:



renewcommand{arraystretch}{3.0}
begin{tabularx}{10cm}{|X|X|}
hline
Row 1 & cellcolor{blue!25} 1/3 colored \
hline
Row 2 & uncolored \
hline
end{tabularx}

renewcommand{arraystretch}{1.0}
begin{tabularx}{10cm}{|X|X|}
hline
&cellcolor{blue!25} \
& \
& \
hline
& \
& \
& \
hline
end{tabularx}

renewcommand{arraystretch}{1.0}
begin{tabularx}{10cm}{|X|X|}
hline
Row 1 &cellcolor{blue!25} 1/3 colored\
& \
& \
hline
Row 2 & uncolored \
& \
& \
hline
end{tabularx}


enter image description here



The first case shows how the text should appear, but clearly the cell is fully colored. In the second case, I split the two rows into six rows so that one third of the original cell can be individually colored. But when adding the text, it is no longer center in the middle of the true cells because it is put in the subcells.



What is the best way to do this?










share|improve this question













Is there some way to color only part of a table cell? For example, the top third, or bottom half of a cell?



For example:



renewcommand{arraystretch}{3.0}
begin{tabularx}{10cm}{|X|X|}
hline
Row 1 & cellcolor{blue!25} 1/3 colored \
hline
Row 2 & uncolored \
hline
end{tabularx}

renewcommand{arraystretch}{1.0}
begin{tabularx}{10cm}{|X|X|}
hline
&cellcolor{blue!25} \
& \
& \
hline
& \
& \
& \
hline
end{tabularx}

renewcommand{arraystretch}{1.0}
begin{tabularx}{10cm}{|X|X|}
hline
Row 1 &cellcolor{blue!25} 1/3 colored\
& \
& \
hline
Row 2 & uncolored \
& \
& \
hline
end{tabularx}


enter image description here



The first case shows how the text should appear, but clearly the cell is fully colored. In the second case, I split the two rows into six rows so that one third of the original cell can be individually colored. But when adding the text, it is no longer center in the middle of the true cells because it is put in the subcells.



What is the best way to do this?







tikz-pgf tables color tabularx






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 at 21:38









O Ganter

525




525








  • 1




    Welcome to TeX.SX! Can you please expand the code snippets that you have posted to a full minimal working example. It is much easier to help you if we can start with some compilable code that illustrates your problem. A MWE should start with a documentclass command, include any necessary packages and be as small as possible to demonstrate your problem. At the moment we have to guess what packages etc you are using before we can compile your code.
    – Andrew
    Nov 12 at 22:10














  • 1




    Welcome to TeX.SX! Can you please expand the code snippets that you have posted to a full minimal working example. It is much easier to help you if we can start with some compilable code that illustrates your problem. A MWE should start with a documentclass command, include any necessary packages and be as small as possible to demonstrate your problem. At the moment we have to guess what packages etc you are using before we can compile your code.
    – Andrew
    Nov 12 at 22:10








1




1




Welcome to TeX.SX! Can you please expand the code snippets that you have posted to a full minimal working example. It is much easier to help you if we can start with some compilable code that illustrates your problem. A MWE should start with a documentclass command, include any necessary packages and be as small as possible to demonstrate your problem. At the moment we have to guess what packages etc you are using before we can compile your code.
– Andrew
Nov 12 at 22:10




Welcome to TeX.SX! Can you please expand the code snippets that you have posted to a full minimal working example. It is much easier to help you if we can start with some compilable code that illustrates your problem. A MWE should start with a documentclass command, include any necessary packages and be as small as possible to demonstrate your problem. At the moment we have to guess what packages etc you are using before we can compile your code.
– Andrew
Nov 12 at 22:10










1 Answer
1






active

oldest

votes

















up vote
5
down vote



accepted










If you want to have a lot of control over shading of the cells then I recommend using a matrix of nodes from the tikz package --- see chapter 57.1 of the very comprehensive manual. For example, you can produce:



enter image description here



using the code:



documentclass{article}
usepackage{tikz}
usetikzlibrary{matrix,calc}

begin{document}

begin{tikzpicture}
matrix (M)[matrix of nodes]{
Row 1 & 1/3 colored \
Row 2 & uncolored \
Row 3 & uncolored \
Row 4 & uncolored \
Row 5 & uncolored \
Row 6 & uncolored \
};
% cell (1,2) with bluish background
draw[opacity=0.2,fill=blue!50](M-1-2.north west) rectangle (M-1-2.south east);
% bottom third of cell (2,2) with bluish background
draw[opacity=0.2,fill=blue!50] ($ (M-2-2.north west)!0.67!(M-2-2.south west) $)
rectangle(M-2-2.south east);
% triangular shading of cell (4,2)
draw[opacity=0.5, fill=green!50,draw=yellow, thick]
(M-4-2.north west)--(M-4-2.south west)--(M-4-2.north east)--cycle;
% crossing out cells in rows 5 and 6
draw[thick, red](M-5-1.north west)--(M-6-2.south east);
draw[thick, red](M-6-1.south west)--(M-5-2.north east);
end{tikzpicture}

end{document}





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',
    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%2f459690%2fcolor-fraction-of-table-cell%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    5
    down vote



    accepted










    If you want to have a lot of control over shading of the cells then I recommend using a matrix of nodes from the tikz package --- see chapter 57.1 of the very comprehensive manual. For example, you can produce:



    enter image description here



    using the code:



    documentclass{article}
    usepackage{tikz}
    usetikzlibrary{matrix,calc}

    begin{document}

    begin{tikzpicture}
    matrix (M)[matrix of nodes]{
    Row 1 & 1/3 colored \
    Row 2 & uncolored \
    Row 3 & uncolored \
    Row 4 & uncolored \
    Row 5 & uncolored \
    Row 6 & uncolored \
    };
    % cell (1,2) with bluish background
    draw[opacity=0.2,fill=blue!50](M-1-2.north west) rectangle (M-1-2.south east);
    % bottom third of cell (2,2) with bluish background
    draw[opacity=0.2,fill=blue!50] ($ (M-2-2.north west)!0.67!(M-2-2.south west) $)
    rectangle(M-2-2.south east);
    % triangular shading of cell (4,2)
    draw[opacity=0.5, fill=green!50,draw=yellow, thick]
    (M-4-2.north west)--(M-4-2.south west)--(M-4-2.north east)--cycle;
    % crossing out cells in rows 5 and 6
    draw[thick, red](M-5-1.north west)--(M-6-2.south east);
    draw[thick, red](M-6-1.south west)--(M-5-2.north east);
    end{tikzpicture}

    end{document}





    share|improve this answer

























      up vote
      5
      down vote



      accepted










      If you want to have a lot of control over shading of the cells then I recommend using a matrix of nodes from the tikz package --- see chapter 57.1 of the very comprehensive manual. For example, you can produce:



      enter image description here



      using the code:



      documentclass{article}
      usepackage{tikz}
      usetikzlibrary{matrix,calc}

      begin{document}

      begin{tikzpicture}
      matrix (M)[matrix of nodes]{
      Row 1 & 1/3 colored \
      Row 2 & uncolored \
      Row 3 & uncolored \
      Row 4 & uncolored \
      Row 5 & uncolored \
      Row 6 & uncolored \
      };
      % cell (1,2) with bluish background
      draw[opacity=0.2,fill=blue!50](M-1-2.north west) rectangle (M-1-2.south east);
      % bottom third of cell (2,2) with bluish background
      draw[opacity=0.2,fill=blue!50] ($ (M-2-2.north west)!0.67!(M-2-2.south west) $)
      rectangle(M-2-2.south east);
      % triangular shading of cell (4,2)
      draw[opacity=0.5, fill=green!50,draw=yellow, thick]
      (M-4-2.north west)--(M-4-2.south west)--(M-4-2.north east)--cycle;
      % crossing out cells in rows 5 and 6
      draw[thick, red](M-5-1.north west)--(M-6-2.south east);
      draw[thick, red](M-6-1.south west)--(M-5-2.north east);
      end{tikzpicture}

      end{document}





      share|improve this answer























        up vote
        5
        down vote



        accepted







        up vote
        5
        down vote



        accepted






        If you want to have a lot of control over shading of the cells then I recommend using a matrix of nodes from the tikz package --- see chapter 57.1 of the very comprehensive manual. For example, you can produce:



        enter image description here



        using the code:



        documentclass{article}
        usepackage{tikz}
        usetikzlibrary{matrix,calc}

        begin{document}

        begin{tikzpicture}
        matrix (M)[matrix of nodes]{
        Row 1 & 1/3 colored \
        Row 2 & uncolored \
        Row 3 & uncolored \
        Row 4 & uncolored \
        Row 5 & uncolored \
        Row 6 & uncolored \
        };
        % cell (1,2) with bluish background
        draw[opacity=0.2,fill=blue!50](M-1-2.north west) rectangle (M-1-2.south east);
        % bottom third of cell (2,2) with bluish background
        draw[opacity=0.2,fill=blue!50] ($ (M-2-2.north west)!0.67!(M-2-2.south west) $)
        rectangle(M-2-2.south east);
        % triangular shading of cell (4,2)
        draw[opacity=0.5, fill=green!50,draw=yellow, thick]
        (M-4-2.north west)--(M-4-2.south west)--(M-4-2.north east)--cycle;
        % crossing out cells in rows 5 and 6
        draw[thick, red](M-5-1.north west)--(M-6-2.south east);
        draw[thick, red](M-6-1.south west)--(M-5-2.north east);
        end{tikzpicture}

        end{document}





        share|improve this answer












        If you want to have a lot of control over shading of the cells then I recommend using a matrix of nodes from the tikz package --- see chapter 57.1 of the very comprehensive manual. For example, you can produce:



        enter image description here



        using the code:



        documentclass{article}
        usepackage{tikz}
        usetikzlibrary{matrix,calc}

        begin{document}

        begin{tikzpicture}
        matrix (M)[matrix of nodes]{
        Row 1 & 1/3 colored \
        Row 2 & uncolored \
        Row 3 & uncolored \
        Row 4 & uncolored \
        Row 5 & uncolored \
        Row 6 & uncolored \
        };
        % cell (1,2) with bluish background
        draw[opacity=0.2,fill=blue!50](M-1-2.north west) rectangle (M-1-2.south east);
        % bottom third of cell (2,2) with bluish background
        draw[opacity=0.2,fill=blue!50] ($ (M-2-2.north west)!0.67!(M-2-2.south west) $)
        rectangle(M-2-2.south east);
        % triangular shading of cell (4,2)
        draw[opacity=0.5, fill=green!50,draw=yellow, thick]
        (M-4-2.north west)--(M-4-2.south west)--(M-4-2.north east)--cycle;
        % crossing out cells in rows 5 and 6
        draw[thick, red](M-5-1.north west)--(M-6-2.south east);
        draw[thick, red](M-6-1.south west)--(M-5-2.north east);
        end{tikzpicture}

        end{document}






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 at 1:16









        Andrew

        29.2k34177




        29.2k34177






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f459690%2fcolor-fraction-of-table-cell%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

            mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

            How to change which sound is reproduced for terminal bell?

            Can I use Tabulator js library in my java Spring + Thymeleaf project?