Tikzpicture: How to color separate fields at the arrays and use resizebox?

Tikzpicture: How to color separate fields at the arrays and use resizebox?



I want to color only separated nodes? How could I do this? I want also resize the tikzfigure, but I got the error message Undefined control sequence. }


Undefined control sequence. }


documentclass[12pt]article
usepackageamsmath
usepackageamsfonts

usepackagetikz
usetikzlibraryintersections,matrix

begindocument
beginfigure
resizebox textwidth !
begintikzpicture [nodes in empty cells, nodes=minimum width=0.2cm, minimum height=0.2cm, row sep=-pgflinewidth, column sep=-pgflinewidth]

border/.style=draw

matrix(vector)[matrix of nodes, nodes=draw] at (3,10) & & & & & & & \
;
matrix(vector)[matrix of nodes, nodes=draw] at (10,10) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector)[matrix of nodes, nodes=draw] at (10,9) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector)[matrix of nodes, nodes=draw] at (10,8) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector)[matrix of nodes, nodes=draw] at (10,7) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;

matrix(vector)[matrix of nodes, nodes=draw] at (3,4) & & & & & & & \
;
matrix(vector)[matrix of nodes, nodes=draw] at (10,4) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector)[matrix of nodes, nodes=draw] at (10,3) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector)[matrix of nodes, nodes=draw] at (10,2) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector)[matrix of nodes, nodes=draw] at (10,1) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector)[matrix of nodes, nodes=draw] at (10,0) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;

draw [thick,->] (10.3,9.8) -- (10.3,9.2);
node at(10.7,9.5) $oplus$;
draw [thick,->] (10.3,8.8) -- (10.3,8.2);
node at(10.7,8.5) $oplus$;
draw [thick,->] (10.3,7.8) -- (10.3,7.2);
node at(10.7,7.5) $T$;

draw [thick,->] (10.3,3.8) -- (10.3,3.2);
node at(10.7,3.5) $oplus$;
draw [thick,->] (10.3,2.8) -- (10.3,2.2);
node at(10.7,2.5) $oplus$;
draw [thick,->] (10.3,1.8) -- (10.3,1.2);
node at(10.7,1.5) $oplus$;
draw [thick,->] (10.3,0.8) -- (10.3,0.2);
node at(10.7,0.5) $T$;

node at (0.5,10) $B_4^0leftarrowmathcalB_7,$$:;
draw[thick,->] (4.5,10) -- node[above] $R_0$ (5.5,10);

node at (3.5,9) $S_127,S_0,S_24,S_50,S_75,S_102$:;
node at (1.7,8) $S_127oplus S_0oplus S_24oplus S_50oplus S_75oplus S_102oplus R_0(B_0^0)$:;
node at (5.3,7) $S'_127$:;

node at (0.5,4) $B_5^0leftarrowmathcalB_3,b$:;
draw[thick,->] (4.5,4) -- node[above] $R_7$ (5.5,4);

node at (5.3,3) $S'_127$:;
node at (3.8,2) $S_0,S_24,S_50,S_75,S_102$:;
node at (1.7,1) $S'_127oplus S_0oplus S_24oplus S_50oplus S_75oplus S_102oplus R_0(B_0^0)$:;
node at (5.3,0) $S'_126$:;

endtikzpicture

endfigure
enddocument



Output






Your editid code doesn't compile for some reason... Please fix your preamble.

– koleygr
Sep 16 '18 at 14:01






I made it work and your problem was explained in this answer: tex.stackexchange.com/a/15096/120578. But if you use the way of my edited answer about the specific problem and the solution on the original question of @Zarco your result will be better. His answer deserves to be the accepted if you return to the original problem that I suggest you have to do. So, do it (return to the original different and more usefull for the forum question) and accept his answer. The new question is just a dupplicate of the link

– koleygr
Sep 16 '18 at 14:16







one problem per question, please!

– Zarko
Sep 16 '18 at 15:06




3 Answers
3



your question is not very clear to me, so i suspect, that you looking for something as you can see in the first two rows of your image:



enter image description here



tel me, if i'm wrong.



edit:



well, apparently i was misunderstood the question. coloring just one cell is simple. using the most of code from my previous answer (which is quite more concise and shorter from yours), you can rewrote your picture code as follows:


documentclass[tikz, margin=3mm]standalone
usetikzlibrarymatrix

begindocument
begintikzpicture
tikzset
mtrx/.style=
matrix of nodes,
nodes in empty cells,
nodes=draw, minimum size=2mm,
row sep=-pgflinewidth,
column sep=-pgflinewidth,

matrix (vector) [mtrx=red] at (3,10) & & & & & & & \
;
matrix (vector) [mtrx=blue!30] at (10,10) [fill=red];
matrix(vector)[mtrx=green] at (10,9) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector)[mtrx] at (10,8) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector)[mtrx] at (10,7) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;

matrix(vector)[mtrx] at (3,4) & & & & & & & \
;
matrix(vector)[mtrx] at (10,4) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector)[mtrx] at (10,3) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector)[mtrx] at (10,2) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector)[mtrx] at (10,1) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector)[mtrx] at (10,0) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;

draw [thick,->] (10.3,9.8) -- (10.3,9.2);
node at(10.7,9.5) $oplus$;
draw [thick,->] (10.3,8.8) -- (10.3,8.2);
node at(10.7,8.5) $oplus$;
draw [thick,->] (10.3,7.8) -- (10.3,7.2);
node at(10.7,7.5) $T$;

draw [thick,->] (10.3,3.8) -- (10.3,3.2);
node at(10.7,3.5) $oplus$;
draw [thick,->] (10.3,2.8) -- (10.3,2.2);
node at(10.7,2.5) $oplus$;
draw [thick,->] (10.3,1.8) -- (10.3,1.2);
node at(10.7,1.5) $oplus$;
draw [thick,->] (10.3,0.8) -- (10.3,0.2);
node at(10.7,0.5) $T$;

node at (0.5,10) $B_4^0leftarrowmathcalB_7,$$:;
draw[thick,->] (4.5,10) -- node[above] $R_0$ (5.5,10);

node at (3.5,9) $S_127,S_0,S_24,S_50,S_75,S_102$:;
node at (1.7,8) $S_127oplus S_0oplus S_24oplus S_50oplus S_75oplus S_102oplus R_0(B_0^0)$:;
node at (5.3,7) $S'_127$:;

node at (0.5,4) $B_5^0leftarrowmathcalB_3,b$:;
draw[thick,->] (4.5,4) -- node[above] $R_7$ (5.5,4);

node at (5.3,3) $S'_127$:;
node at (3.8,2) $S_0,S_24,S_50,S_75,S_102$:;
node at (1.7,1) $S'_127oplus S_0oplus S_24oplus S_50oplus S_75oplus S_102oplus R_0(B_0^0)$:;
node at (5.3,0) $S'_126$:;

endtikzpicture
enddocument



enter image description here






I think the question is not really clear too... But with "separate nodes" the OP possibly means what is in my answer's photo. May be it's my mistake... but let's wait for his reaction.

– koleygr
Sep 16 '18 at 13:25







Thanks for your answer. I want to color only one field and not the entire array. I will update my question. Sorry if the description was to bad.

– ikreb
Sep 16 '18 at 13:26






@koleygr, permanently you win in guessing! congratulation and +1!

– Zarko
Sep 16 '18 at 13:52






@ikreb, see edited answer!

– Zarko
Sep 16 '18 at 13:53






@Zarko.. You win (+1 enough time before).

– koleygr
Sep 16 '18 at 14:21



The only easy solution that I found is to use nested tikzpictures... But it is really simple. Also used svgnames for more colors:



Code:


documentclass[tikz,svgnames]standalone
usetikzlibrarymatrix
usepackagepgf

newcommandmyfill[1]%This is the command manually adjusted to do the wholev job
begintikzpicture[overlay, remember picture]
draw[draw=none,fill=#1,shift=(-0.11,-0.115)](0,0)rectangle(0.22,0.225);
endtikzpicture

begindocument
begintikzpicture [nodes in empty cells, nodes=minimum width=0.2cm, minimum height=0.2cm, row sep=-pgflinewidth, column sep=-pgflinewidth]

border/.style=draw

matrix(vector)[matrix of nodes, nodes=draw] at (3,10) & & & & & & & \
;
matrix(vector)[matrix of nodes, nodes=draw] at (10,10) myfillRed & & &myfillGreen &myfillBrown & & & myfillBlue!30!Yellow& & & & & & & & & & & & & & & & & & & & & myfillBlue\
;
matrix(vector)[matrix of nodes, nodes=draw] at (10,9) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector)[matrix of nodes, nodes=draw] at (10,8) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector)[matrix of nodes, nodes=draw] at (10,7) &myfillGreen & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;

matrix(vector)[matrix of nodes, nodes=draw] at (3,4) & & & & & & & \
;
matrix(vector)[matrix of nodes, nodes=draw] at (10,4) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector)[matrix of nodes, nodes=draw] at (10,3) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector)[matrix of nodes, nodes=draw] at (10,2) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector)[matrix of nodes, nodes=draw] at (10,1) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector)[matrix of nodes, nodes=draw] at (10,0) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;

draw [thick,->] (10.3,9.8) -- (10.3,9.2);
node at(10.7,9.5) $oplus$;
draw [thick,->] (10.3,8.8) -- (10.3,8.2);
node at(10.7,8.5) $oplus$;
draw [thick,->] (10.3,7.8) -- (10.3,7.2);
node at(10.7,7.5) $T$;

draw [thick,->] (10.3,3.8) -- (10.3,3.2);
node at(10.7,3.5) $oplus$;
draw [thick,->] (10.3,2.8) -- (10.3,2.2);
node at(10.7,2.5) $oplus$;
draw [thick,->] (10.3,1.8) -- (10.3,1.2);
node at(10.7,1.5) $oplus$;
draw [thick,->] (10.3,0.8) -- (10.3,0.2);
node at(10.7,0.5) $T$;

node at (0.5,10) $B_4^0leftarrowmathcalB_7,$$:;
draw[thick,->] (4.5,10) -- node[above] $R_0$ (5.5,10);

node at (3.5,9) $S_127,S_0,S_24,S_50,S_75,S_102$:;
node at (1.7,8) $S_127oplus S_0oplus S_24oplus S_50oplus S_75oplus S_102oplus R_0(B_0^0)$:;
node at (5.3,7) $S'_127$:;

node at (0.5,4) $B_5^0leftarrowmathcalB_3,b$:;
draw[thick,->] (4.5,4) -- node[above] $R_7$ (5.5,4);

node at (5.3,3) $S'_127$:;
node at (3.8,2) $S_0,S_24,S_50,S_75,S_102$:;
node at (1.7,1) $S'_127oplus S_0oplus S_24oplus S_50oplus S_75oplus S_102oplus R_0(B_0^0)$:;
node at (5.3,0) $S'_126$:;

endtikzpicture
enddocument



Output:



enter image description here



Edit: After OPS Edit:


documentclass[12pt]article
usepackageamsmath
usepackageamsfonts

usepackagetikz
usetikzlibraryintersections,matrix

newcommandmyfill[1]%This is the command manually adjusted to do the wholev job
begintikzpicture[overlay, remember picture]
draw[draw=none,fill=#1,shift=(-0.13,-0.13)](0,0)rectangle(0.255,0.26);
endtikzpicture

begindocument
beginfigure
resizebox textwidth !
begintikzpicture [nodes in empty cells, nodes=minimum width=0.2cm, minimum height=0.2cm, row sep=-pgflinewidth, column sep=-pgflinewidth]

border/.style=draw

matrix(vector)[matrix of nodes, nodes=draw,ampersand replacement=&,] at (3,10) myfillgreen& myfillred& & & & & & myfillbrown\
;
matrix(vector)[matrix of nodes, nodes=draw,ampersand replacement=&,] at (10,10) & & myfillyellow& & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector)[matrix of nodes, nodes=draw,ampersand replacement=&,] at (10,9) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector)[matrix of nodes, nodes=draw,ampersand replacement=&,] at (10,8) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector)[matrix of nodes, nodes=draw,ampersand replacement=&,] at (10,7) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;

matrix(vector)[matrix of nodes, nodes=draw,ampersand replacement=&,] at (3,4) &myfillgreen & & & & & & \
;
matrix(vector)[matrix of nodes, nodes=draw,ampersand replacement=&,] at (10,4) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector)[matrix of nodes, nodes=draw,ampersand replacement=&,] at (10,3) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector)[matrix of nodes, nodes=draw,ampersand replacement=&,] at (10,2) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector)[matrix of nodes, nodes=draw,ampersand replacement=&,] at (10,1) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector)[matrix of nodes, nodes=draw,ampersand replacement=&,] at (10,0) & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;

draw [thick,->] (10.3,9.8) -- (10.3,9.2);
node at(10.7,9.5) $oplus$;
draw [thick,->] (10.3,8.8) -- (10.3,8.2);
node at(10.7,8.5) $oplus$;
draw [thick,->] (10.3,7.8) -- (10.3,7.2);
node at(10.7,7.5) $T$;

draw [thick,->] (10.3,3.8) -- (10.3,3.2);
node at(10.7,3.5) $oplus$;
draw [thick,->] (10.3,2.8) -- (10.3,2.2);
node at(10.7,2.5) $oplus$;
draw [thick,->] (10.3,1.8) -- (10.3,1.2);
node at(10.7,1.5) $oplus$;
draw [thick,->] (10.3,0.8) -- (10.3,0.2);
node at(10.7,0.5) $T$;

node at (0.5,10) $B_4^0leftarrowmathcalB_7,$$:;
draw[thick,->] (4.5,10) -- node[above] $R_0$ (5.5,10);

node at (3.5,9) $S_127,S_0,S_24,S_50,S_75,S_102$:;
node at (1.7,8) $S_127oplus S_0oplus S_24oplus S_50oplus S_75oplus S_102oplus R_0(B_0^0)$:;
node at (5.3,7) $S'_127$:;

node at (0.5,4) $B_5^0leftarrowmathcalB_3,b$:;
draw[thick,->] (4.5,4) -- node[above] $R_7$ (5.5,4);

node at (5.3,3) $S'_127$:;
node at (3.8,2) $S_0,S_24,S_50,S_75,S_102$:;
node at (1.7,1) $S'_127oplus S_0oplus S_24oplus S_50oplus S_75oplus S_102oplus R_0(B_0^0)$:;
node at (5.3,0) $S'_126$:;

endtikzpicture

endfigure
enddocument






Also, please next time post a compilable MWE. (No documentclass and begindocument was there).

– koleygr
Sep 16 '18 at 13:22


begindocument






Updated answer colors with more accuracy.

– koleygr
Sep 16 '18 at 13:30






Sorry, I updated it. One question, whe does resizebox doesn't work with your solution? To ask a new question is not usefull or?

– ikreb
Sep 16 '18 at 13:33






@ikreb I think you can just edit your question with the change.. It's ok for me to select a better answer later that does both.

– koleygr
Sep 16 '18 at 13:39



Here is an answer that makes use of resizebox. All you need to do is to put the tikzpicture in a lrbox. As for your real question, you only need to put |[fill=red]| in a given cell to fill the cell. I add some examples to the code.


resizebox


|[fill=red]|


documentclass[12pt]article
usepackageamsmath
usepackageamsfonts

usepackagetikz
usetikzlibraryintersections,matrix,positioning
newsaveboxpicbox
begindocument
beginfigure
beginlrboxpicbox
begintikzpicture [nodes in empty cells, nodes=minimum width=0.2cm, minimum height=0.2cm, row sep=-pgflinewidth, column sep=-pgflinewidth]
border/.style=draw
matrix(vector-1)[matrix of nodes, nodes=draw] [fill=red];
matrix(vector-2)[right=2cm of vector-1,matrix of nodes, nodes=draw] & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector-3)[below=1cm of vector-2,matrix of nodes, nodes=draw] & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector-4)[below=1cm of vector-3,matrix of nodes, nodes=draw] & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector-5)[below=1cm of vector-4,matrix of nodes, nodes=draw] & & & & & & & & & & & & & & & & & & & & & & & & & & \
;

matrix(vector-6)[below=6.5cm of vector-1,matrix of nodes, nodes=draw] & & & & & & & \
;
matrix(vector-7)[right=2cm of vector-6,matrix of nodes, nodes=draw] & & &
;
matrix(vector-8)[below=1cm of vector-7,matrix of nodes, nodes=draw] & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector-9)[below=1cm of vector-8,matrix of nodes, nodes=draw] & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector-10)[below=1cm of vector-9,matrix of nodes, nodes=draw] & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
matrix(vector-11)[below=1cm of vector-10,matrix of nodes, nodes=draw] & & & & & & & & & & & & & & & & & & & & & & & & & & & & \
;
%
foreach X [evaluate=X as Y using int(X-1)] in 3,4,8,9,10
draw[thick,-latex] (vector-Y) -- (vector-X) node[midway,right]$oplus$;
%
foreach X [evaluate=X as Y using int(X-1)] in 5,11
draw[thick,-latex] (vector-Y) -- (vector-X) node[midway,right]$T$;
%
draw[thick,-latex] (vector-1) -- (vector-2) node[midway,above]$R_0$;
draw[thick,-latex] (vector-6) -- (vector-7) node[midway,above]$R_7$;
%
node[left=2mm of vector-1,anchor=east] $B_4^0leftarrowmathcalB_7,$$:;
%
node[left=2mm of vector-3,anchor=east] $S_127,S_0,S_24,S_50,S_75,S_102$:;
node[left=2mm of vector-4,anchor=east] $S_127oplus S_0oplus S_24oplus S_50oplus S_75oplus S_102oplus R_0(B_0^0)$:;
node[left=2mm of vector-5,anchor=east] $S'_127$:;
%
node[left=2mm of vector-6,anchor=east]$B_5^0leftarrowmathcalB_3,b$:;
%
node[left=2mm of vector-8,anchor=east] $S'_127$:;
node[left=2mm of vector-9,anchor=east] $S_0,S_24,S_50,S_75,S_102$:;
node[left=2mm of vector-10,anchor=east] $S'_127oplus S_0oplus S_24oplus S_50oplus S_75oplus S_102oplus R_0(B_0^0)$:;
node[left=2mm of vector-11,anchor=east] $S'_126$:;
%
endtikzpicture
endlrbox
resizeboxtextwidth!useboxpicbox
endfigure
enddocument



enter image description here



A word of caution: it is quite possible that someone may copy my code, add some feature like chains, and claim that this code then becomes much more "concise". I'd kindly ask you to check if this really the case. Your code is already very well structured and thus easy to understand and adjustable. I used used positioning because I think it is advantageous here, and also use foreach loops to repeat things. Personally I would refrain from using chains here for several reasons, one of them being that you lose some flexibility of adjusting positions. Likewise, you could define styles for repeating things, but your code is so well structured that I don't think that makes a big difference. So this is just to say that if someone claims to be more "concise" you should critically ask yourself if that's really true.


chains


foreach



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



But avoid



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



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)