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}
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
add a comment |
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}
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
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 adocumentclass
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
add a comment |
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}
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
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}
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
tikz-pgf tables color tabularx
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 adocumentclass
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
add a comment |
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 adocumentclass
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
add a comment |
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:
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}
add a comment |
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:
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}
add a comment |
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:
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}
add a comment |
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:
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}
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:
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}
answered Nov 13 at 1:16
Andrew
29.2k34177
29.2k34177
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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