Drawing a memory layout diagram with TikzBetter way of designing memory layout in tikzDisplaying memory...

How to answer "write something on the board"?

Security Patch SUPEE-11155 - Possible issues?

Why won't the ground take my seed?

Handling a player (unintentionally) stealing the spotlight

Adjective for 'made of pus' or 'corrupted by pus' or something of something of pus

What are good ways to spray paint a QR code on a footpath?

Why were the first airplanes "backwards"?

Put my student loan in parents’ second mortgage - help?

Could a Weapon of Mass Destruction, targeting only humans, be developed?

Who voices the character "Finger" in The Fifth Element?

Could human civilization live 150 years in a nuclear-powered aircraft carrier colony without resorting to mass killing/ cannibalism?

Can Aziraphale and Crowley actually become native?

Why do I need two parameters in an HTTP parameter pollution attack?

What exactly did Ant-Man see that made him say that their plan worked?

Multiple computers 1 minecraft

Drawing a memory layout diagram with Tikz

How can my story take place on Earth without referring to our existing cities and countries?

Can White Castle? #3

Do the 26 richest billionaires own as much wealth as the poorest 3.8 billion people?

Why would anyone even use a Portkey?

My colleague is constantly blaming me for his errors

I hit a pipe with a mower and now it won't turn

How to organize members in a struct to waste least space on alignment?

Find first and last non-zero column in each row of a pandas dataframe



Drawing a memory layout diagram with Tikz


Better way of designing memory layout in tikzDisplaying memory variable valuesDrawing a packet layout with TikZDrawing flow diagram in LaTeX using TikZDrawing a block diagram with TiKzDrawing diagram in TikZDrawing a block diagram in Tikzexceeding memory with tikz (even after externalise)Drawing Color Diagram with TikzVariable/counter for each object/instance using a template with tikzset and /.style?Drawing a Decision Diagram with Tikz and layout manager






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







1















I'd like to draw a memory layout diagram in Tikz that looks a bit like the following:
enter image description here
Note that the original was an SVG file, and conversion to PNG causes the weird [Not supported by viewer] errors, not sure what that's about.



Anyway, how can I recreate that diagram in Tikz, but without the numbered stages, and with the sections starting at the very left?



I tried to modify this answer to near it to the posted image, but I don't know enough Tikz to get it quite there.










share|improve this question

























  • What have to tried so far?

    – Skillmon
    8 hours ago











  • @Skillmon I tried hacking around the answer to this question[1] but my Tikz knowledge wasn't enough to get it anywhere close. [1]: tex.stackexchange.com/questions/430577/…

    – Bernardo Meurer
    8 hours ago











  • You could include the code you tried so far in your question.

    – Skillmon
    8 hours ago











  • I'll add a reference to that question while I try to salvage my attempt from Vim's history

    – Bernardo Meurer
    8 hours ago











  • ctan.org/pkg/bytefield

    – Henri Menke
    8 hours ago


















1















I'd like to draw a memory layout diagram in Tikz that looks a bit like the following:
enter image description here
Note that the original was an SVG file, and conversion to PNG causes the weird [Not supported by viewer] errors, not sure what that's about.



Anyway, how can I recreate that diagram in Tikz, but without the numbered stages, and with the sections starting at the very left?



I tried to modify this answer to near it to the posted image, but I don't know enough Tikz to get it quite there.










share|improve this question

























  • What have to tried so far?

    – Skillmon
    8 hours ago











  • @Skillmon I tried hacking around the answer to this question[1] but my Tikz knowledge wasn't enough to get it anywhere close. [1]: tex.stackexchange.com/questions/430577/…

    – Bernardo Meurer
    8 hours ago











  • You could include the code you tried so far in your question.

    – Skillmon
    8 hours ago











  • I'll add a reference to that question while I try to salvage my attempt from Vim's history

    – Bernardo Meurer
    8 hours ago











  • ctan.org/pkg/bytefield

    – Henri Menke
    8 hours ago














1












1








1








I'd like to draw a memory layout diagram in Tikz that looks a bit like the following:
enter image description here
Note that the original was an SVG file, and conversion to PNG causes the weird [Not supported by viewer] errors, not sure what that's about.



Anyway, how can I recreate that diagram in Tikz, but without the numbered stages, and with the sections starting at the very left?



I tried to modify this answer to near it to the posted image, but I don't know enough Tikz to get it quite there.










share|improve this question
















I'd like to draw a memory layout diagram in Tikz that looks a bit like the following:
enter image description here
Note that the original was an SVG file, and conversion to PNG causes the weird [Not supported by viewer] errors, not sure what that's about.



Anyway, how can I recreate that diagram in Tikz, but without the numbered stages, and with the sections starting at the very left?



I tried to modify this answer to near it to the posted image, but I don't know enough Tikz to get it quite there.







tikz-pgf diagrams memory






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 8 hours ago







Bernardo Meurer

















asked 8 hours ago









Bernardo MeurerBernardo Meurer

2711 silver badge9 bronze badges




2711 silver badge9 bronze badges













  • What have to tried so far?

    – Skillmon
    8 hours ago











  • @Skillmon I tried hacking around the answer to this question[1] but my Tikz knowledge wasn't enough to get it anywhere close. [1]: tex.stackexchange.com/questions/430577/…

    – Bernardo Meurer
    8 hours ago











  • You could include the code you tried so far in your question.

    – Skillmon
    8 hours ago











  • I'll add a reference to that question while I try to salvage my attempt from Vim's history

    – Bernardo Meurer
    8 hours ago











  • ctan.org/pkg/bytefield

    – Henri Menke
    8 hours ago



















  • What have to tried so far?

    – Skillmon
    8 hours ago











  • @Skillmon I tried hacking around the answer to this question[1] but my Tikz knowledge wasn't enough to get it anywhere close. [1]: tex.stackexchange.com/questions/430577/…

    – Bernardo Meurer
    8 hours ago











  • You could include the code you tried so far in your question.

    – Skillmon
    8 hours ago











  • I'll add a reference to that question while I try to salvage my attempt from Vim's history

    – Bernardo Meurer
    8 hours ago











  • ctan.org/pkg/bytefield

    – Henri Menke
    8 hours ago

















What have to tried so far?

– Skillmon
8 hours ago





What have to tried so far?

– Skillmon
8 hours ago













@Skillmon I tried hacking around the answer to this question[1] but my Tikz knowledge wasn't enough to get it anywhere close. [1]: tex.stackexchange.com/questions/430577/…

– Bernardo Meurer
8 hours ago





@Skillmon I tried hacking around the answer to this question[1] but my Tikz knowledge wasn't enough to get it anywhere close. [1]: tex.stackexchange.com/questions/430577/…

– Bernardo Meurer
8 hours ago













You could include the code you tried so far in your question.

– Skillmon
8 hours ago





You could include the code you tried so far in your question.

– Skillmon
8 hours ago













I'll add a reference to that question while I try to salvage my attempt from Vim's history

– Bernardo Meurer
8 hours ago





I'll add a reference to that question while I try to salvage my attempt from Vim's history

– Bernardo Meurer
8 hours ago













ctan.org/pkg/bytefield

– Henri Menke
8 hours ago





ctan.org/pkg/bytefield

– Henri Menke
8 hours ago










2 Answers
2






active

oldest

votes


















3














Something like this:



enter image description here
This is done using tikz but to hide the technicalities I have defined a macro MemoryLayout that accepts a coma separated list of x-coordinates/colours/labels so that the image above was produced by:



MemoryLayout{
12/blue!10/A,
21/orange!20/B,
30/red!30/C,
39/yellow!30/D,
48/green!30/E,
62/white/relax
}


Use a label of relax when you do not want a label.



All that this macro does is loop over the input data to draw the picture using standard tikz commands. Here is the full code:



documentclass[tikz, border=5mm]{standalone}
usetikzlibrary{decorations.pathreplacing}

newcommandMemoryLayout[1]{
begin{tikzpicture}[scale=0.3]
draw[thick](0,0)--++(0,3)node[above]{$0$};
foreach pt/col/lab [remember=pt as tp (initially 0)] in {#1} {
foreach a in {tp,...,pt-1} {
draw[fill=col](-a,0) rectangle ++(-1,2);
}
draw[thick](-pt,0)--++(0,3)node[above]{$pt$};
iflabrelaxrelaxelse
draw[thick,decorate, decoration={brace,amplitude=4mm}]
(-tp,-0.2)--node[below=4mm]{lab} (-pt,-0.2);
fi
}
end{tikzpicture}
}

begin{document}

MemoryLayout{
12/blue!10/A,
21/orange!20/B,
30/red!30/C,
39/yellow!30/D,
48/green!30/E,
62/white/relax
}

end{document}


To remove the numbers just comment out the two draw[thick]...; commands.






share|improve this answer


























  • I love it! Thank you!

    – Bernardo Meurer
    6 hours ago



















3














Just for fun an implementation using only xcolor (and amstext for text in the labels below the brace). The memory command takes the following arguments:



memory[<width>]{<num>}[<height>]{<color>}[<label>]


<width>
: is the width of a single cell



<height>
: is the height of the cells



<color>
: is the colour used by the cells, it can contain an optional argument and a mandatory one, or just the mandatory one forwarded to textcolor, so both {[gray]{.85}} and {white!85!black} are valid.



<label>
: the text which is printed below the brace, if it is left out no brace will be drawn.



The borders' thickness is the current value of fboxrule, the rules don't add to the size of the cells. To draw more than a single block of memory, just put multiple memory instances after each other, make sure to not put a space in between. The size of the <label> might create white space, you'd have to take care for that.



documentclass[]{article}

usepackage{amstext}
usepackage{xcolor}

makeatletter
begingroup
lccode`A=`-
lccode`N=`N
lccode`V=`V
lowercase{endgroupdefmemory@noval{ANoValue-}}
longdefmemory@fiBgbfi#1#2{fi}
longdefmemory@fiTBbfi#1#2#3{fi#2}
newcommandmemory@ifnovalF[1]%>>=
{%
ifxmemory@noval#1%
memory@fiBgb
fi
@firstofone
}%=<<
newcommandmemory@ifnovalTF[1]%>>=
{%
ifxmemory@noval#1%
memory@fiTBb
fi
@secondoftwo
}%=<<
newcommandmemory@Oarg[2]%>>=
{%
@ifnextchar[{memory@Oarg@{#2}}{#2{#1}}%
}%=<<
longdefmemory@Oarg@#1[#2]%>>=
{%
#1{#2}%
}%=<<
newcommand*memory@oarg%>>=
{%
memory@Oargmemory@noval
}%=<<
newcommand*memory@ifcoloropt%>>=
{%
@ifnextchar[memory@ifcoloropt@truememory@ifcoloropt@false
}%=<<
longdefmemory@ifcoloropt@true#1memory@noval#2#3%>>=
{%
#2%
}%=<<
longdefmemory@ifcoloropt@false#1memory@noval#2#3%>>=
{%
#3%
}%=<<
newlengthmemory@width
newlengthmemory@height
setlengthmemory@width{7pt}
setlengthmemory@height{10pt}
newcountmemory@num
newcommand*memory@blocks[2]%>>=
{%
memory@num#1relax
fboxsep-fboxrule
memory@ifcoloropt#2memory@noval
{defmemory@color{textcolor#2}}
{defmemory@color{textcolor{#2}}}%
loop
ifnummemory@num>0
fbox{memory@color{rule{memory@width}{memory@height}}}%
kern-fboxrule
advancememory@numm@ne
repeat
}%=<<
% memory:
% [#1]: width
% #2 : count
% [#3]: height
% #4 : colour
% [#5]: label
newcommand*memory%>>=
{%
begingroup
memory@oargmemory@a
}%=<<
newcommand*memory@a[2]%>>=
{%
% #1 width
% #2 count
memory@ifnovalF{#1}{memory@width#1relax}%
memory@Oargmemory@height{memory@b{#2}}%
}%=<<
newcommand*memory@b[3]%>>=
{%
% #1 count
% #2 height
% #3 colour
memory@ifnovalF{#2}{memory@height#2relax}%
memory@oarg{memory@c{#1}{#3}}%
}%=<<
newcommand*memory@c[3]%>>=
{%
% #1 count
% #2 colour
% #3 label
memory@ifnovalTF{#3}
{ensuremath{memory@blocks{#1}{#2}}}
{ensuremath{underbrace{memory@blocks{#1}{#2}}_{text{#3}}}}%
endgroup
}%=<<
makeatother

begin{document}
memory{8}{orange}%
memory{8}{green}[{makebox[0pt]{[Not supported by viewer]}}]%
memory{8}{yellow}%
end{document}

% vim: fdm=marker fmr=>>=,=<<


enter image description here






share|improve this answer


























  • This is absolutely amazing, right down to the [Not supported by viewer]!

    – Bernardo Meurer
    6 hours ago














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%2f497431%2fdrawing-a-memory-layout-diagram-with-tikz%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









3














Something like this:



enter image description here
This is done using tikz but to hide the technicalities I have defined a macro MemoryLayout that accepts a coma separated list of x-coordinates/colours/labels so that the image above was produced by:



MemoryLayout{
12/blue!10/A,
21/orange!20/B,
30/red!30/C,
39/yellow!30/D,
48/green!30/E,
62/white/relax
}


Use a label of relax when you do not want a label.



All that this macro does is loop over the input data to draw the picture using standard tikz commands. Here is the full code:



documentclass[tikz, border=5mm]{standalone}
usetikzlibrary{decorations.pathreplacing}

newcommandMemoryLayout[1]{
begin{tikzpicture}[scale=0.3]
draw[thick](0,0)--++(0,3)node[above]{$0$};
foreach pt/col/lab [remember=pt as tp (initially 0)] in {#1} {
foreach a in {tp,...,pt-1} {
draw[fill=col](-a,0) rectangle ++(-1,2);
}
draw[thick](-pt,0)--++(0,3)node[above]{$pt$};
iflabrelaxrelaxelse
draw[thick,decorate, decoration={brace,amplitude=4mm}]
(-tp,-0.2)--node[below=4mm]{lab} (-pt,-0.2);
fi
}
end{tikzpicture}
}

begin{document}

MemoryLayout{
12/blue!10/A,
21/orange!20/B,
30/red!30/C,
39/yellow!30/D,
48/green!30/E,
62/white/relax
}

end{document}


To remove the numbers just comment out the two draw[thick]...; commands.






share|improve this answer


























  • I love it! Thank you!

    – Bernardo Meurer
    6 hours ago
















3














Something like this:



enter image description here
This is done using tikz but to hide the technicalities I have defined a macro MemoryLayout that accepts a coma separated list of x-coordinates/colours/labels so that the image above was produced by:



MemoryLayout{
12/blue!10/A,
21/orange!20/B,
30/red!30/C,
39/yellow!30/D,
48/green!30/E,
62/white/relax
}


Use a label of relax when you do not want a label.



All that this macro does is loop over the input data to draw the picture using standard tikz commands. Here is the full code:



documentclass[tikz, border=5mm]{standalone}
usetikzlibrary{decorations.pathreplacing}

newcommandMemoryLayout[1]{
begin{tikzpicture}[scale=0.3]
draw[thick](0,0)--++(0,3)node[above]{$0$};
foreach pt/col/lab [remember=pt as tp (initially 0)] in {#1} {
foreach a in {tp,...,pt-1} {
draw[fill=col](-a,0) rectangle ++(-1,2);
}
draw[thick](-pt,0)--++(0,3)node[above]{$pt$};
iflabrelaxrelaxelse
draw[thick,decorate, decoration={brace,amplitude=4mm}]
(-tp,-0.2)--node[below=4mm]{lab} (-pt,-0.2);
fi
}
end{tikzpicture}
}

begin{document}

MemoryLayout{
12/blue!10/A,
21/orange!20/B,
30/red!30/C,
39/yellow!30/D,
48/green!30/E,
62/white/relax
}

end{document}


To remove the numbers just comment out the two draw[thick]...; commands.






share|improve this answer


























  • I love it! Thank you!

    – Bernardo Meurer
    6 hours ago














3












3








3







Something like this:



enter image description here
This is done using tikz but to hide the technicalities I have defined a macro MemoryLayout that accepts a coma separated list of x-coordinates/colours/labels so that the image above was produced by:



MemoryLayout{
12/blue!10/A,
21/orange!20/B,
30/red!30/C,
39/yellow!30/D,
48/green!30/E,
62/white/relax
}


Use a label of relax when you do not want a label.



All that this macro does is loop over the input data to draw the picture using standard tikz commands. Here is the full code:



documentclass[tikz, border=5mm]{standalone}
usetikzlibrary{decorations.pathreplacing}

newcommandMemoryLayout[1]{
begin{tikzpicture}[scale=0.3]
draw[thick](0,0)--++(0,3)node[above]{$0$};
foreach pt/col/lab [remember=pt as tp (initially 0)] in {#1} {
foreach a in {tp,...,pt-1} {
draw[fill=col](-a,0) rectangle ++(-1,2);
}
draw[thick](-pt,0)--++(0,3)node[above]{$pt$};
iflabrelaxrelaxelse
draw[thick,decorate, decoration={brace,amplitude=4mm}]
(-tp,-0.2)--node[below=4mm]{lab} (-pt,-0.2);
fi
}
end{tikzpicture}
}

begin{document}

MemoryLayout{
12/blue!10/A,
21/orange!20/B,
30/red!30/C,
39/yellow!30/D,
48/green!30/E,
62/white/relax
}

end{document}


To remove the numbers just comment out the two draw[thick]...; commands.






share|improve this answer















Something like this:



enter image description here
This is done using tikz but to hide the technicalities I have defined a macro MemoryLayout that accepts a coma separated list of x-coordinates/colours/labels so that the image above was produced by:



MemoryLayout{
12/blue!10/A,
21/orange!20/B,
30/red!30/C,
39/yellow!30/D,
48/green!30/E,
62/white/relax
}


Use a label of relax when you do not want a label.



All that this macro does is loop over the input data to draw the picture using standard tikz commands. Here is the full code:



documentclass[tikz, border=5mm]{standalone}
usetikzlibrary{decorations.pathreplacing}

newcommandMemoryLayout[1]{
begin{tikzpicture}[scale=0.3]
draw[thick](0,0)--++(0,3)node[above]{$0$};
foreach pt/col/lab [remember=pt as tp (initially 0)] in {#1} {
foreach a in {tp,...,pt-1} {
draw[fill=col](-a,0) rectangle ++(-1,2);
}
draw[thick](-pt,0)--++(0,3)node[above]{$pt$};
iflabrelaxrelaxelse
draw[thick,decorate, decoration={brace,amplitude=4mm}]
(-tp,-0.2)--node[below=4mm]{lab} (-pt,-0.2);
fi
}
end{tikzpicture}
}

begin{document}

MemoryLayout{
12/blue!10/A,
21/orange!20/B,
30/red!30/C,
39/yellow!30/D,
48/green!30/E,
62/white/relax
}

end{document}


To remove the numbers just comment out the two draw[thick]...; commands.







share|improve this answer














share|improve this answer



share|improve this answer








edited 6 hours ago

























answered 6 hours ago









AndrewAndrew

34k3 gold badges50 silver badges88 bronze badges




34k3 gold badges50 silver badges88 bronze badges













  • I love it! Thank you!

    – Bernardo Meurer
    6 hours ago



















  • I love it! Thank you!

    – Bernardo Meurer
    6 hours ago

















I love it! Thank you!

– Bernardo Meurer
6 hours ago





I love it! Thank you!

– Bernardo Meurer
6 hours ago













3














Just for fun an implementation using only xcolor (and amstext for text in the labels below the brace). The memory command takes the following arguments:



memory[<width>]{<num>}[<height>]{<color>}[<label>]


<width>
: is the width of a single cell



<height>
: is the height of the cells



<color>
: is the colour used by the cells, it can contain an optional argument and a mandatory one, or just the mandatory one forwarded to textcolor, so both {[gray]{.85}} and {white!85!black} are valid.



<label>
: the text which is printed below the brace, if it is left out no brace will be drawn.



The borders' thickness is the current value of fboxrule, the rules don't add to the size of the cells. To draw more than a single block of memory, just put multiple memory instances after each other, make sure to not put a space in between. The size of the <label> might create white space, you'd have to take care for that.



documentclass[]{article}

usepackage{amstext}
usepackage{xcolor}

makeatletter
begingroup
lccode`A=`-
lccode`N=`N
lccode`V=`V
lowercase{endgroupdefmemory@noval{ANoValue-}}
longdefmemory@fiBgbfi#1#2{fi}
longdefmemory@fiTBbfi#1#2#3{fi#2}
newcommandmemory@ifnovalF[1]%>>=
{%
ifxmemory@noval#1%
memory@fiBgb
fi
@firstofone
}%=<<
newcommandmemory@ifnovalTF[1]%>>=
{%
ifxmemory@noval#1%
memory@fiTBb
fi
@secondoftwo
}%=<<
newcommandmemory@Oarg[2]%>>=
{%
@ifnextchar[{memory@Oarg@{#2}}{#2{#1}}%
}%=<<
longdefmemory@Oarg@#1[#2]%>>=
{%
#1{#2}%
}%=<<
newcommand*memory@oarg%>>=
{%
memory@Oargmemory@noval
}%=<<
newcommand*memory@ifcoloropt%>>=
{%
@ifnextchar[memory@ifcoloropt@truememory@ifcoloropt@false
}%=<<
longdefmemory@ifcoloropt@true#1memory@noval#2#3%>>=
{%
#2%
}%=<<
longdefmemory@ifcoloropt@false#1memory@noval#2#3%>>=
{%
#3%
}%=<<
newlengthmemory@width
newlengthmemory@height
setlengthmemory@width{7pt}
setlengthmemory@height{10pt}
newcountmemory@num
newcommand*memory@blocks[2]%>>=
{%
memory@num#1relax
fboxsep-fboxrule
memory@ifcoloropt#2memory@noval
{defmemory@color{textcolor#2}}
{defmemory@color{textcolor{#2}}}%
loop
ifnummemory@num>0
fbox{memory@color{rule{memory@width}{memory@height}}}%
kern-fboxrule
advancememory@numm@ne
repeat
}%=<<
% memory:
% [#1]: width
% #2 : count
% [#3]: height
% #4 : colour
% [#5]: label
newcommand*memory%>>=
{%
begingroup
memory@oargmemory@a
}%=<<
newcommand*memory@a[2]%>>=
{%
% #1 width
% #2 count
memory@ifnovalF{#1}{memory@width#1relax}%
memory@Oargmemory@height{memory@b{#2}}%
}%=<<
newcommand*memory@b[3]%>>=
{%
% #1 count
% #2 height
% #3 colour
memory@ifnovalF{#2}{memory@height#2relax}%
memory@oarg{memory@c{#1}{#3}}%
}%=<<
newcommand*memory@c[3]%>>=
{%
% #1 count
% #2 colour
% #3 label
memory@ifnovalTF{#3}
{ensuremath{memory@blocks{#1}{#2}}}
{ensuremath{underbrace{memory@blocks{#1}{#2}}_{text{#3}}}}%
endgroup
}%=<<
makeatother

begin{document}
memory{8}{orange}%
memory{8}{green}[{makebox[0pt]{[Not supported by viewer]}}]%
memory{8}{yellow}%
end{document}

% vim: fdm=marker fmr=>>=,=<<


enter image description here






share|improve this answer


























  • This is absolutely amazing, right down to the [Not supported by viewer]!

    – Bernardo Meurer
    6 hours ago
















3














Just for fun an implementation using only xcolor (and amstext for text in the labels below the brace). The memory command takes the following arguments:



memory[<width>]{<num>}[<height>]{<color>}[<label>]


<width>
: is the width of a single cell



<height>
: is the height of the cells



<color>
: is the colour used by the cells, it can contain an optional argument and a mandatory one, or just the mandatory one forwarded to textcolor, so both {[gray]{.85}} and {white!85!black} are valid.



<label>
: the text which is printed below the brace, if it is left out no brace will be drawn.



The borders' thickness is the current value of fboxrule, the rules don't add to the size of the cells. To draw more than a single block of memory, just put multiple memory instances after each other, make sure to not put a space in between. The size of the <label> might create white space, you'd have to take care for that.



documentclass[]{article}

usepackage{amstext}
usepackage{xcolor}

makeatletter
begingroup
lccode`A=`-
lccode`N=`N
lccode`V=`V
lowercase{endgroupdefmemory@noval{ANoValue-}}
longdefmemory@fiBgbfi#1#2{fi}
longdefmemory@fiTBbfi#1#2#3{fi#2}
newcommandmemory@ifnovalF[1]%>>=
{%
ifxmemory@noval#1%
memory@fiBgb
fi
@firstofone
}%=<<
newcommandmemory@ifnovalTF[1]%>>=
{%
ifxmemory@noval#1%
memory@fiTBb
fi
@secondoftwo
}%=<<
newcommandmemory@Oarg[2]%>>=
{%
@ifnextchar[{memory@Oarg@{#2}}{#2{#1}}%
}%=<<
longdefmemory@Oarg@#1[#2]%>>=
{%
#1{#2}%
}%=<<
newcommand*memory@oarg%>>=
{%
memory@Oargmemory@noval
}%=<<
newcommand*memory@ifcoloropt%>>=
{%
@ifnextchar[memory@ifcoloropt@truememory@ifcoloropt@false
}%=<<
longdefmemory@ifcoloropt@true#1memory@noval#2#3%>>=
{%
#2%
}%=<<
longdefmemory@ifcoloropt@false#1memory@noval#2#3%>>=
{%
#3%
}%=<<
newlengthmemory@width
newlengthmemory@height
setlengthmemory@width{7pt}
setlengthmemory@height{10pt}
newcountmemory@num
newcommand*memory@blocks[2]%>>=
{%
memory@num#1relax
fboxsep-fboxrule
memory@ifcoloropt#2memory@noval
{defmemory@color{textcolor#2}}
{defmemory@color{textcolor{#2}}}%
loop
ifnummemory@num>0
fbox{memory@color{rule{memory@width}{memory@height}}}%
kern-fboxrule
advancememory@numm@ne
repeat
}%=<<
% memory:
% [#1]: width
% #2 : count
% [#3]: height
% #4 : colour
% [#5]: label
newcommand*memory%>>=
{%
begingroup
memory@oargmemory@a
}%=<<
newcommand*memory@a[2]%>>=
{%
% #1 width
% #2 count
memory@ifnovalF{#1}{memory@width#1relax}%
memory@Oargmemory@height{memory@b{#2}}%
}%=<<
newcommand*memory@b[3]%>>=
{%
% #1 count
% #2 height
% #3 colour
memory@ifnovalF{#2}{memory@height#2relax}%
memory@oarg{memory@c{#1}{#3}}%
}%=<<
newcommand*memory@c[3]%>>=
{%
% #1 count
% #2 colour
% #3 label
memory@ifnovalTF{#3}
{ensuremath{memory@blocks{#1}{#2}}}
{ensuremath{underbrace{memory@blocks{#1}{#2}}_{text{#3}}}}%
endgroup
}%=<<
makeatother

begin{document}
memory{8}{orange}%
memory{8}{green}[{makebox[0pt]{[Not supported by viewer]}}]%
memory{8}{yellow}%
end{document}

% vim: fdm=marker fmr=>>=,=<<


enter image description here






share|improve this answer


























  • This is absolutely amazing, right down to the [Not supported by viewer]!

    – Bernardo Meurer
    6 hours ago














3












3








3







Just for fun an implementation using only xcolor (and amstext for text in the labels below the brace). The memory command takes the following arguments:



memory[<width>]{<num>}[<height>]{<color>}[<label>]


<width>
: is the width of a single cell



<height>
: is the height of the cells



<color>
: is the colour used by the cells, it can contain an optional argument and a mandatory one, or just the mandatory one forwarded to textcolor, so both {[gray]{.85}} and {white!85!black} are valid.



<label>
: the text which is printed below the brace, if it is left out no brace will be drawn.



The borders' thickness is the current value of fboxrule, the rules don't add to the size of the cells. To draw more than a single block of memory, just put multiple memory instances after each other, make sure to not put a space in between. The size of the <label> might create white space, you'd have to take care for that.



documentclass[]{article}

usepackage{amstext}
usepackage{xcolor}

makeatletter
begingroup
lccode`A=`-
lccode`N=`N
lccode`V=`V
lowercase{endgroupdefmemory@noval{ANoValue-}}
longdefmemory@fiBgbfi#1#2{fi}
longdefmemory@fiTBbfi#1#2#3{fi#2}
newcommandmemory@ifnovalF[1]%>>=
{%
ifxmemory@noval#1%
memory@fiBgb
fi
@firstofone
}%=<<
newcommandmemory@ifnovalTF[1]%>>=
{%
ifxmemory@noval#1%
memory@fiTBb
fi
@secondoftwo
}%=<<
newcommandmemory@Oarg[2]%>>=
{%
@ifnextchar[{memory@Oarg@{#2}}{#2{#1}}%
}%=<<
longdefmemory@Oarg@#1[#2]%>>=
{%
#1{#2}%
}%=<<
newcommand*memory@oarg%>>=
{%
memory@Oargmemory@noval
}%=<<
newcommand*memory@ifcoloropt%>>=
{%
@ifnextchar[memory@ifcoloropt@truememory@ifcoloropt@false
}%=<<
longdefmemory@ifcoloropt@true#1memory@noval#2#3%>>=
{%
#2%
}%=<<
longdefmemory@ifcoloropt@false#1memory@noval#2#3%>>=
{%
#3%
}%=<<
newlengthmemory@width
newlengthmemory@height
setlengthmemory@width{7pt}
setlengthmemory@height{10pt}
newcountmemory@num
newcommand*memory@blocks[2]%>>=
{%
memory@num#1relax
fboxsep-fboxrule
memory@ifcoloropt#2memory@noval
{defmemory@color{textcolor#2}}
{defmemory@color{textcolor{#2}}}%
loop
ifnummemory@num>0
fbox{memory@color{rule{memory@width}{memory@height}}}%
kern-fboxrule
advancememory@numm@ne
repeat
}%=<<
% memory:
% [#1]: width
% #2 : count
% [#3]: height
% #4 : colour
% [#5]: label
newcommand*memory%>>=
{%
begingroup
memory@oargmemory@a
}%=<<
newcommand*memory@a[2]%>>=
{%
% #1 width
% #2 count
memory@ifnovalF{#1}{memory@width#1relax}%
memory@Oargmemory@height{memory@b{#2}}%
}%=<<
newcommand*memory@b[3]%>>=
{%
% #1 count
% #2 height
% #3 colour
memory@ifnovalF{#2}{memory@height#2relax}%
memory@oarg{memory@c{#1}{#3}}%
}%=<<
newcommand*memory@c[3]%>>=
{%
% #1 count
% #2 colour
% #3 label
memory@ifnovalTF{#3}
{ensuremath{memory@blocks{#1}{#2}}}
{ensuremath{underbrace{memory@blocks{#1}{#2}}_{text{#3}}}}%
endgroup
}%=<<
makeatother

begin{document}
memory{8}{orange}%
memory{8}{green}[{makebox[0pt]{[Not supported by viewer]}}]%
memory{8}{yellow}%
end{document}

% vim: fdm=marker fmr=>>=,=<<


enter image description here






share|improve this answer















Just for fun an implementation using only xcolor (and amstext for text in the labels below the brace). The memory command takes the following arguments:



memory[<width>]{<num>}[<height>]{<color>}[<label>]


<width>
: is the width of a single cell



<height>
: is the height of the cells



<color>
: is the colour used by the cells, it can contain an optional argument and a mandatory one, or just the mandatory one forwarded to textcolor, so both {[gray]{.85}} and {white!85!black} are valid.



<label>
: the text which is printed below the brace, if it is left out no brace will be drawn.



The borders' thickness is the current value of fboxrule, the rules don't add to the size of the cells. To draw more than a single block of memory, just put multiple memory instances after each other, make sure to not put a space in between. The size of the <label> might create white space, you'd have to take care for that.



documentclass[]{article}

usepackage{amstext}
usepackage{xcolor}

makeatletter
begingroup
lccode`A=`-
lccode`N=`N
lccode`V=`V
lowercase{endgroupdefmemory@noval{ANoValue-}}
longdefmemory@fiBgbfi#1#2{fi}
longdefmemory@fiTBbfi#1#2#3{fi#2}
newcommandmemory@ifnovalF[1]%>>=
{%
ifxmemory@noval#1%
memory@fiBgb
fi
@firstofone
}%=<<
newcommandmemory@ifnovalTF[1]%>>=
{%
ifxmemory@noval#1%
memory@fiTBb
fi
@secondoftwo
}%=<<
newcommandmemory@Oarg[2]%>>=
{%
@ifnextchar[{memory@Oarg@{#2}}{#2{#1}}%
}%=<<
longdefmemory@Oarg@#1[#2]%>>=
{%
#1{#2}%
}%=<<
newcommand*memory@oarg%>>=
{%
memory@Oargmemory@noval
}%=<<
newcommand*memory@ifcoloropt%>>=
{%
@ifnextchar[memory@ifcoloropt@truememory@ifcoloropt@false
}%=<<
longdefmemory@ifcoloropt@true#1memory@noval#2#3%>>=
{%
#2%
}%=<<
longdefmemory@ifcoloropt@false#1memory@noval#2#3%>>=
{%
#3%
}%=<<
newlengthmemory@width
newlengthmemory@height
setlengthmemory@width{7pt}
setlengthmemory@height{10pt}
newcountmemory@num
newcommand*memory@blocks[2]%>>=
{%
memory@num#1relax
fboxsep-fboxrule
memory@ifcoloropt#2memory@noval
{defmemory@color{textcolor#2}}
{defmemory@color{textcolor{#2}}}%
loop
ifnummemory@num>0
fbox{memory@color{rule{memory@width}{memory@height}}}%
kern-fboxrule
advancememory@numm@ne
repeat
}%=<<
% memory:
% [#1]: width
% #2 : count
% [#3]: height
% #4 : colour
% [#5]: label
newcommand*memory%>>=
{%
begingroup
memory@oargmemory@a
}%=<<
newcommand*memory@a[2]%>>=
{%
% #1 width
% #2 count
memory@ifnovalF{#1}{memory@width#1relax}%
memory@Oargmemory@height{memory@b{#2}}%
}%=<<
newcommand*memory@b[3]%>>=
{%
% #1 count
% #2 height
% #3 colour
memory@ifnovalF{#2}{memory@height#2relax}%
memory@oarg{memory@c{#1}{#3}}%
}%=<<
newcommand*memory@c[3]%>>=
{%
% #1 count
% #2 colour
% #3 label
memory@ifnovalTF{#3}
{ensuremath{memory@blocks{#1}{#2}}}
{ensuremath{underbrace{memory@blocks{#1}{#2}}_{text{#3}}}}%
endgroup
}%=<<
makeatother

begin{document}
memory{8}{orange}%
memory{8}{green}[{makebox[0pt]{[Not supported by viewer]}}]%
memory{8}{yellow}%
end{document}

% vim: fdm=marker fmr=>>=,=<<


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited 7 hours ago

























answered 7 hours ago









SkillmonSkillmon

26.6k1 gold badge25 silver badges54 bronze badges




26.6k1 gold badge25 silver badges54 bronze badges













  • This is absolutely amazing, right down to the [Not supported by viewer]!

    – Bernardo Meurer
    6 hours ago



















  • This is absolutely amazing, right down to the [Not supported by viewer]!

    – Bernardo Meurer
    6 hours ago

















This is absolutely amazing, right down to the [Not supported by viewer]!

– Bernardo Meurer
6 hours ago





This is absolutely amazing, right down to the [Not supported by viewer]!

– Bernardo Meurer
6 hours ago


















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%2f497431%2fdrawing-a-memory-layout-diagram-with-tikz%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

Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...