Drawing a memory layout diagram with TikzBetter 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
Security Patch SUPEE-11155 - Possible issues?
How hard is it to sell a home which is currently mortgaged?
Put my student loan in parents’ second mortgage - help?
Is there a legal way for US presidents to extend their terms beyond four years?
What is the purpose of putting a capacitor on the primary side of a step-down transformer?
In native German words, is Q always followed by U, as in English?
How to organize members in a struct to waste least space on alignment?
Drawing a memory layout diagram with Tikz
Could a Weapon of Mass Destruction, targeting only humans, be developed?
Was it really unprofessional of me to leave without asking for a raise first?
Why were the first airplanes "backwards"?
Graph problems as integer programs
For decoupling an IC's power supply pins, is there any reason to use multiple capacitances when all the MLCCs have the same package size?
What are good ways to spray paint a QR code on a footpath?
What exactly did Ant-Man see that made him say that their plan worked?
Why do changes to /etc/hosts take effect immediately?
Apex Class Deployment: duplicate value found: <unknown> duplicates value on record with id: <unknown>
What could a reptilian race tell by candling their eggs?
Step into the Octagram
Is there a canon reason why Klingon and Romulan vessels are so similar in shape?
Why won't the ground take my seed?
What game is this character in the Pixels movie from?
How did researchers find articles before the Internet and the computer era?
Which is better for keeping data primary partition or logical partition?
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;
I'd like to draw a memory layout diagram in Tikz that looks a bit like the following:
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
add a comment |
I'd like to draw a memory layout diagram in Tikz that looks a bit like the following:
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
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
add a comment |
I'd like to draw a memory layout diagram in Tikz that looks a bit like the following:
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
I'd like to draw a memory layout diagram in Tikz that looks a bit like the following:
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
tikz-pgf diagrams memory
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
Something like this:
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
usetikzlibrarydecorations.pathreplacing
newcommandMemoryLayout[1]
begintikzpicture[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
endtikzpicture
begindocument
MemoryLayout
12/blue!10/A,
21/orange!20/B,
30/red!30/C,
39/yellow!30/D,
48/green!30/E,
62/white/relax
enddocument
To remove the numbers just comment out the two draw[thick]...;
commands.
I love it! Thank you!
– Bernardo Meurer
6 hours ago
add a comment |
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
usepackageamstext
usepackagexcolor
makeatletter
begingroup
lccode`A=`-
lccode`N=`N
lccode`V=`V
lowercaseendgroupdefmemory@novalANoValue-
longdefmemory@fiBgbfi#1#2fi
longdefmemory@fiTBbfi#1#2#3fi#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@width7pt
setlengthmemory@height10pt
newcountmemory@num
newcommand*memory@blocks[2]%>>=
%
memory@num#1relax
fboxsep-fboxrule
memory@ifcoloropt#2memory@noval
defmemory@colortextcolor#2
defmemory@colortextcolor#2%
loop
ifnummemory@num>0
fboxmemory@colorrulememory@widthmemory@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#1memory@width#1relax%
memory@Oargmemory@heightmemory@b#2%
%=<<
newcommand*memory@b[3]%>>=
%
% #1 count
% #2 height
% #3 colour
memory@ifnovalF#2memory@height#2relax%
memory@oargmemory@c#1#3%
%=<<
newcommand*memory@c[3]%>>=
%
% #1 count
% #2 colour
% #3 label
memory@ifnovalTF#3
ensuremathmemory@blocks#1#2
ensuremathunderbracememory@blocks#1#2_text#3%
endgroup
%=<<
makeatother
begindocument
memory8orange%
memory8green[makebox[0pt][Not supported by viewer]]%
memory8yellow%
enddocument
% vim: fdm=marker fmr=>>=,=<<
This is absolutely amazing, right down to the[Not supported by viewer]
!
– Bernardo Meurer
6 hours ago
add a comment |
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
);
);
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%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
Something like this:
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
usetikzlibrarydecorations.pathreplacing
newcommandMemoryLayout[1]
begintikzpicture[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
endtikzpicture
begindocument
MemoryLayout
12/blue!10/A,
21/orange!20/B,
30/red!30/C,
39/yellow!30/D,
48/green!30/E,
62/white/relax
enddocument
To remove the numbers just comment out the two draw[thick]...;
commands.
I love it! Thank you!
– Bernardo Meurer
6 hours ago
add a comment |
Something like this:
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
usetikzlibrarydecorations.pathreplacing
newcommandMemoryLayout[1]
begintikzpicture[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
endtikzpicture
begindocument
MemoryLayout
12/blue!10/A,
21/orange!20/B,
30/red!30/C,
39/yellow!30/D,
48/green!30/E,
62/white/relax
enddocument
To remove the numbers just comment out the two draw[thick]...;
commands.
I love it! Thank you!
– Bernardo Meurer
6 hours ago
add a comment |
Something like this:
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
usetikzlibrarydecorations.pathreplacing
newcommandMemoryLayout[1]
begintikzpicture[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
endtikzpicture
begindocument
MemoryLayout
12/blue!10/A,
21/orange!20/B,
30/red!30/C,
39/yellow!30/D,
48/green!30/E,
62/white/relax
enddocument
To remove the numbers just comment out the two draw[thick]...;
commands.
Something like this:
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
usetikzlibrarydecorations.pathreplacing
newcommandMemoryLayout[1]
begintikzpicture[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
endtikzpicture
begindocument
MemoryLayout
12/blue!10/A,
21/orange!20/B,
30/red!30/C,
39/yellow!30/D,
48/green!30/E,
62/white/relax
enddocument
To remove the numbers just comment out the two draw[thick]...;
commands.
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
add a comment |
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
add a comment |
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
usepackageamstext
usepackagexcolor
makeatletter
begingroup
lccode`A=`-
lccode`N=`N
lccode`V=`V
lowercaseendgroupdefmemory@novalANoValue-
longdefmemory@fiBgbfi#1#2fi
longdefmemory@fiTBbfi#1#2#3fi#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@width7pt
setlengthmemory@height10pt
newcountmemory@num
newcommand*memory@blocks[2]%>>=
%
memory@num#1relax
fboxsep-fboxrule
memory@ifcoloropt#2memory@noval
defmemory@colortextcolor#2
defmemory@colortextcolor#2%
loop
ifnummemory@num>0
fboxmemory@colorrulememory@widthmemory@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#1memory@width#1relax%
memory@Oargmemory@heightmemory@b#2%
%=<<
newcommand*memory@b[3]%>>=
%
% #1 count
% #2 height
% #3 colour
memory@ifnovalF#2memory@height#2relax%
memory@oargmemory@c#1#3%
%=<<
newcommand*memory@c[3]%>>=
%
% #1 count
% #2 colour
% #3 label
memory@ifnovalTF#3
ensuremathmemory@blocks#1#2
ensuremathunderbracememory@blocks#1#2_text#3%
endgroup
%=<<
makeatother
begindocument
memory8orange%
memory8green[makebox[0pt][Not supported by viewer]]%
memory8yellow%
enddocument
% vim: fdm=marker fmr=>>=,=<<
This is absolutely amazing, right down to the[Not supported by viewer]
!
– Bernardo Meurer
6 hours ago
add a comment |
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
usepackageamstext
usepackagexcolor
makeatletter
begingroup
lccode`A=`-
lccode`N=`N
lccode`V=`V
lowercaseendgroupdefmemory@novalANoValue-
longdefmemory@fiBgbfi#1#2fi
longdefmemory@fiTBbfi#1#2#3fi#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@width7pt
setlengthmemory@height10pt
newcountmemory@num
newcommand*memory@blocks[2]%>>=
%
memory@num#1relax
fboxsep-fboxrule
memory@ifcoloropt#2memory@noval
defmemory@colortextcolor#2
defmemory@colortextcolor#2%
loop
ifnummemory@num>0
fboxmemory@colorrulememory@widthmemory@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#1memory@width#1relax%
memory@Oargmemory@heightmemory@b#2%
%=<<
newcommand*memory@b[3]%>>=
%
% #1 count
% #2 height
% #3 colour
memory@ifnovalF#2memory@height#2relax%
memory@oargmemory@c#1#3%
%=<<
newcommand*memory@c[3]%>>=
%
% #1 count
% #2 colour
% #3 label
memory@ifnovalTF#3
ensuremathmemory@blocks#1#2
ensuremathunderbracememory@blocks#1#2_text#3%
endgroup
%=<<
makeatother
begindocument
memory8orange%
memory8green[makebox[0pt][Not supported by viewer]]%
memory8yellow%
enddocument
% vim: fdm=marker fmr=>>=,=<<
This is absolutely amazing, right down to the[Not supported by viewer]
!
– Bernardo Meurer
6 hours ago
add a comment |
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
usepackageamstext
usepackagexcolor
makeatletter
begingroup
lccode`A=`-
lccode`N=`N
lccode`V=`V
lowercaseendgroupdefmemory@novalANoValue-
longdefmemory@fiBgbfi#1#2fi
longdefmemory@fiTBbfi#1#2#3fi#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@width7pt
setlengthmemory@height10pt
newcountmemory@num
newcommand*memory@blocks[2]%>>=
%
memory@num#1relax
fboxsep-fboxrule
memory@ifcoloropt#2memory@noval
defmemory@colortextcolor#2
defmemory@colortextcolor#2%
loop
ifnummemory@num>0
fboxmemory@colorrulememory@widthmemory@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#1memory@width#1relax%
memory@Oargmemory@heightmemory@b#2%
%=<<
newcommand*memory@b[3]%>>=
%
% #1 count
% #2 height
% #3 colour
memory@ifnovalF#2memory@height#2relax%
memory@oargmemory@c#1#3%
%=<<
newcommand*memory@c[3]%>>=
%
% #1 count
% #2 colour
% #3 label
memory@ifnovalTF#3
ensuremathmemory@blocks#1#2
ensuremathunderbracememory@blocks#1#2_text#3%
endgroup
%=<<
makeatother
begindocument
memory8orange%
memory8green[makebox[0pt][Not supported by viewer]]%
memory8yellow%
enddocument
% vim: fdm=marker fmr=>>=,=<<
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
usepackageamstext
usepackagexcolor
makeatletter
begingroup
lccode`A=`-
lccode`N=`N
lccode`V=`V
lowercaseendgroupdefmemory@novalANoValue-
longdefmemory@fiBgbfi#1#2fi
longdefmemory@fiTBbfi#1#2#3fi#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@width7pt
setlengthmemory@height10pt
newcountmemory@num
newcommand*memory@blocks[2]%>>=
%
memory@num#1relax
fboxsep-fboxrule
memory@ifcoloropt#2memory@noval
defmemory@colortextcolor#2
defmemory@colortextcolor#2%
loop
ifnummemory@num>0
fboxmemory@colorrulememory@widthmemory@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#1memory@width#1relax%
memory@Oargmemory@heightmemory@b#2%
%=<<
newcommand*memory@b[3]%>>=
%
% #1 count
% #2 height
% #3 colour
memory@ifnovalF#2memory@height#2relax%
memory@oargmemory@c#1#3%
%=<<
newcommand*memory@c[3]%>>=
%
% #1 count
% #2 colour
% #3 label
memory@ifnovalTF#3
ensuremathmemory@blocks#1#2
ensuremathunderbracememory@blocks#1#2_text#3%
endgroup
%=<<
makeatother
begindocument
memory8orange%
memory8green[makebox[0pt][Not supported by viewer]]%
memory8yellow%
enddocument
% vim: fdm=marker fmr=>>=,=<<
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
add a comment |
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
add a comment |
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.
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%2f497431%2fdrawing-a-memory-layout-diagram-with-tikz%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
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