TeX - LaTeX Asked by John Moser on July 7, 2021
Is there a way to make the top and bottom row come out the same, or is this offset always going to happen?
documentclass[twoside,titlepage,12pt,appendixprefix=true]{scrbook}
usepackage{tikz}
usepackage{pgfplots}
usepackage{pgfmath}
begin{document}
{
centering
begin{tikzpicture}
tikzset{byte/.append style={rectangle,
draw=black, fill=white,
minimum width=0.75cm,
minimum height=1cm,
anchor=north west,
align=center, font=scriptsize}}
tikzset{register/.append style={byte,
minimum height=0.5cm,
fill=blue!20}}
node [byte,minimum height=1cm] (Address Label) at (0,0) {Addr};
node [byte, minimum height=0.5cm, minimum width=6cm] (Register Array 0) at (Address Label.north east) {Register Array 0};
node [byte, minimum height=0.5cm, minimum width=6cm] (Register Array 1) at ($(Register Array 0.north east) + (0.25cm,0)$) {Register Array 1};
foreach r in {0,1}
{
node [byte, minimum height=0.5cm] (Heading Rr D7) at (Register Array r.south west) {D7};
foreach b in {6,...,0}
{
pgfmathtruncatemacro{bp}{b + 1}
node [byte, minimum height=0.5cm] (Heading Rr Db) at ($(Heading Rr Dbp.north west) + (0.75cm,0)$) {Db};
}
}
foreach r in {0,1}
{
node [byte, minimum height=0.5cm] (Heading Rr Da7) at (Heading Rr D7.south west) {D7};
foreach b in {6,...,0}
{
pgfmathtruncatemacro{bp}{b + 1}
node [byte, minimum height=0.5cm] (Heading Rr Dab) at (Heading Rr Dabp.north east) {Db};
}
}
end{tikzpicture}
}
end{document}
After some more searching, I found this answer about padding and borders. The solution was to set outer sep=0
on the node style.
Answered by John Moser on July 7, 2021
For this kind of structure I think it's easier to use matrix
nodes and add the Addr node once the register is done and not start with it.
documentclass[twoside,titlepage,12pt,appendixprefix=true]{scrbook}
usepackage{tikz}
usetikzlibrary{matrix, positioning, fit}
begin{document}
centering
begin{tikzpicture}[font=scriptsize,
register/.style={matrix of nodes, font=scriptsize, nodes in empty cells,
column sep=-pgflinewidth, row sep=-pgflinewidth,
nodes={anchor=center, draw, minimum height=.5cm, minimum width=8mm},
row 1/.style={nodes={draw=none}}},
byte/.style={rectangle, draw, minimum width=.75cm, minimum height=1cm, font=scriptsize},
]
matrix (RA0) [register]{
&&&&&&&D7&D6&D5&D4&D3&D2&D1&D0D7&D6&D5&D4&D3&D2&D1&D0};
matrix (RA1) [register, right= 3mm of RA0.east]{
&&&&&&&D7&D6&D5&D4&D3&D2&D1&D0D7&D6&D5&D4&D3&D2&D1&D0};
node[fit=(RA0-1-1) (RA0-1-8), draw, inner sep=-.5pgflinewidth, label=center:Register Array 0] {};
node[fit=(RA1-1-1) (RA1-1-8), draw, inner sep=-.5pgflinewidth, label=center:Register Array 1] {};
node [byte, left = -pgflinewidth of RA0-1-1.north west, anchor=north east] (Address Label) {Addr};
end{tikzpicture}
end{document}
Answered by Ignasi on July 7, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP