Tikz Matrix: Nodes are not 'in-a-row'?
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
I am using a matrix for node-positioning with a fixed node witdh.
However, as some nodes contaning more than one line of text some nodes are shifted in y-axis and I don't know why or how to fix this. There seems to be enough space inside the node in y-axis. I also connected some nodes which result in an ugly picture.
MWE which shows this behaviour:
documentclass[tikz]standalone
usetikzlibrarymatrix,fit
begindocument
begintikzpicture
matrix (m) [%
matrix of nodes,%
nodes in empty cells,%
nodes=rectangle, draw ,align=center,minimum height=1.5cm, text width=3.5cm,font=scriptsize, inner sep= 0cm, outer sep= 0cm, fill=white,%
column sep=.5cm,%
row sep=.5cm,%
anchor=center
]%
&Two\line\breaks&One line&& \
One\linebreak&&&& \
&&&Two\line\break& \
&&One&& \
;
foreach row/rownext in 1/2,2/3,3/4,4/4
foreach col/colnext in 1/2,2/3,3/4,4/5,5/5
draw(m-row-col) to (m-row-colnext);
draw(m-row-col) to (m-rownext-col);
endtikzpicture
enddocument
Picture or result:
tikz-pgf horizontal-alignment vertical-alignment matrices nodes
add a comment |Â
up vote
4
down vote
favorite
I am using a matrix for node-positioning with a fixed node witdh.
However, as some nodes contaning more than one line of text some nodes are shifted in y-axis and I don't know why or how to fix this. There seems to be enough space inside the node in y-axis. I also connected some nodes which result in an ugly picture.
MWE which shows this behaviour:
documentclass[tikz]standalone
usetikzlibrarymatrix,fit
begindocument
begintikzpicture
matrix (m) [%
matrix of nodes,%
nodes in empty cells,%
nodes=rectangle, draw ,align=center,minimum height=1.5cm, text width=3.5cm,font=scriptsize, inner sep= 0cm, outer sep= 0cm, fill=white,%
column sep=.5cm,%
row sep=.5cm,%
anchor=center
]%
&Two\line\breaks&One line&& \
One\linebreak&&&& \
&&&Two\line\break& \
&&One&& \
;
foreach row/rownext in 1/2,2/3,3/4,4/4
foreach col/colnext in 1/2,2/3,3/4,4/5,5/5
draw(m-row-col) to (m-row-colnext);
draw(m-row-col) to (m-rownext-col);
endtikzpicture
enddocument
Picture or result:
tikz-pgf horizontal-alignment vertical-alignment matrices nodes
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I am using a matrix for node-positioning with a fixed node witdh.
However, as some nodes contaning more than one line of text some nodes are shifted in y-axis and I don't know why or how to fix this. There seems to be enough space inside the node in y-axis. I also connected some nodes which result in an ugly picture.
MWE which shows this behaviour:
documentclass[tikz]standalone
usetikzlibrarymatrix,fit
begindocument
begintikzpicture
matrix (m) [%
matrix of nodes,%
nodes in empty cells,%
nodes=rectangle, draw ,align=center,minimum height=1.5cm, text width=3.5cm,font=scriptsize, inner sep= 0cm, outer sep= 0cm, fill=white,%
column sep=.5cm,%
row sep=.5cm,%
anchor=center
]%
&Two\line\breaks&One line&& \
One\linebreak&&&& \
&&&Two\line\break& \
&&One&& \
;
foreach row/rownext in 1/2,2/3,3/4,4/4
foreach col/colnext in 1/2,2/3,3/4,4/5,5/5
draw(m-row-col) to (m-row-colnext);
draw(m-row-col) to (m-rownext-col);
endtikzpicture
enddocument
Picture or result:
tikz-pgf horizontal-alignment vertical-alignment matrices nodes
I am using a matrix for node-positioning with a fixed node witdh.
However, as some nodes contaning more than one line of text some nodes are shifted in y-axis and I don't know why or how to fix this. There seems to be enough space inside the node in y-axis. I also connected some nodes which result in an ugly picture.
MWE which shows this behaviour:
documentclass[tikz]standalone
usetikzlibrarymatrix,fit
begindocument
begintikzpicture
matrix (m) [%
matrix of nodes,%
nodes in empty cells,%
nodes=rectangle, draw ,align=center,minimum height=1.5cm, text width=3.5cm,font=scriptsize, inner sep= 0cm, outer sep= 0cm, fill=white,%
column sep=.5cm,%
row sep=.5cm,%
anchor=center
]%
&Two\line\breaks&One line&& \
One\linebreak&&&& \
&&&Two\line\break& \
&&One&& \
;
foreach row/rownext in 1/2,2/3,3/4,4/4
foreach col/colnext in 1/2,2/3,3/4,4/5,5/5
draw(m-row-col) to (m-row-colnext);
draw(m-row-col) to (m-rownext-col);
endtikzpicture
enddocument
Picture or result:
tikz-pgf horizontal-alignment vertical-alignment matrices nodes
tikz-pgf horizontal-alignment vertical-alignment matrices nodes
asked 3 hours ago
SRel
43911
43911
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
4
down vote
accepted
You only need to add anchor=center
to the nodes. You only added this option to the matrix (node), not to the nodes within the matrix.
documentclass[tikz]standalone
usetikzlibrarymatrix,fit
begindocument
begintikzpicture
matrix (m) [%
matrix of nodes,%
nodes in empty cells,%
nodes=rectangle, draw ,align=center,minimum height=1.5cm, text
width=3.5cm,font=scriptsize, inner sep= 0cm, outer sep= 0cm,
fill=white,anchor=center,%
column sep=.5cm,%
row sep=.5cm,%
anchor=center
]%
& Two\ line \breaks & One line && \
One\linebreak&&&& \
&&&Two\line\breaks& \
&&One&& \
;
foreach row/rownext in 1/2,2/3,3/4,4/4
foreach col/colnext in 1/2,2/3,3/4,4/5,5/5
draw(m-row-col) to (m-row-colnext);
draw(m-row-col) to (m-rownext-col);
endtikzpicture
enddocument
I think this has been first pointed out in tex.stackexchange.com/a/18761/121799.
â marmot
3 hours ago
The problem here is different from the one you pointed. The use ofmatrix of nodes
changes node's anchor tobase
which means thanempty cells
and nodes with text will align on theirbase
anchor, not through thecenter
. Loop Space explained to me also long time ago ;-).
â Ignasi
6 mins ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
You only need to add anchor=center
to the nodes. You only added this option to the matrix (node), not to the nodes within the matrix.
documentclass[tikz]standalone
usetikzlibrarymatrix,fit
begindocument
begintikzpicture
matrix (m) [%
matrix of nodes,%
nodes in empty cells,%
nodes=rectangle, draw ,align=center,minimum height=1.5cm, text
width=3.5cm,font=scriptsize, inner sep= 0cm, outer sep= 0cm,
fill=white,anchor=center,%
column sep=.5cm,%
row sep=.5cm,%
anchor=center
]%
& Two\ line \breaks & One line && \
One\linebreak&&&& \
&&&Two\line\breaks& \
&&One&& \
;
foreach row/rownext in 1/2,2/3,3/4,4/4
foreach col/colnext in 1/2,2/3,3/4,4/5,5/5
draw(m-row-col) to (m-row-colnext);
draw(m-row-col) to (m-rownext-col);
endtikzpicture
enddocument
I think this has been first pointed out in tex.stackexchange.com/a/18761/121799.
â marmot
3 hours ago
The problem here is different from the one you pointed. The use ofmatrix of nodes
changes node's anchor tobase
which means thanempty cells
and nodes with text will align on theirbase
anchor, not through thecenter
. Loop Space explained to me also long time ago ;-).
â Ignasi
6 mins ago
add a comment |Â
up vote
4
down vote
accepted
You only need to add anchor=center
to the nodes. You only added this option to the matrix (node), not to the nodes within the matrix.
documentclass[tikz]standalone
usetikzlibrarymatrix,fit
begindocument
begintikzpicture
matrix (m) [%
matrix of nodes,%
nodes in empty cells,%
nodes=rectangle, draw ,align=center,minimum height=1.5cm, text
width=3.5cm,font=scriptsize, inner sep= 0cm, outer sep= 0cm,
fill=white,anchor=center,%
column sep=.5cm,%
row sep=.5cm,%
anchor=center
]%
& Two\ line \breaks & One line && \
One\linebreak&&&& \
&&&Two\line\breaks& \
&&One&& \
;
foreach row/rownext in 1/2,2/3,3/4,4/4
foreach col/colnext in 1/2,2/3,3/4,4/5,5/5
draw(m-row-col) to (m-row-colnext);
draw(m-row-col) to (m-rownext-col);
endtikzpicture
enddocument
I think this has been first pointed out in tex.stackexchange.com/a/18761/121799.
â marmot
3 hours ago
The problem here is different from the one you pointed. The use ofmatrix of nodes
changes node's anchor tobase
which means thanempty cells
and nodes with text will align on theirbase
anchor, not through thecenter
. Loop Space explained to me also long time ago ;-).
â Ignasi
6 mins ago
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
You only need to add anchor=center
to the nodes. You only added this option to the matrix (node), not to the nodes within the matrix.
documentclass[tikz]standalone
usetikzlibrarymatrix,fit
begindocument
begintikzpicture
matrix (m) [%
matrix of nodes,%
nodes in empty cells,%
nodes=rectangle, draw ,align=center,minimum height=1.5cm, text
width=3.5cm,font=scriptsize, inner sep= 0cm, outer sep= 0cm,
fill=white,anchor=center,%
column sep=.5cm,%
row sep=.5cm,%
anchor=center
]%
& Two\ line \breaks & One line && \
One\linebreak&&&& \
&&&Two\line\breaks& \
&&One&& \
;
foreach row/rownext in 1/2,2/3,3/4,4/4
foreach col/colnext in 1/2,2/3,3/4,4/5,5/5
draw(m-row-col) to (m-row-colnext);
draw(m-row-col) to (m-rownext-col);
endtikzpicture
enddocument
You only need to add anchor=center
to the nodes. You only added this option to the matrix (node), not to the nodes within the matrix.
documentclass[tikz]standalone
usetikzlibrarymatrix,fit
begindocument
begintikzpicture
matrix (m) [%
matrix of nodes,%
nodes in empty cells,%
nodes=rectangle, draw ,align=center,minimum height=1.5cm, text
width=3.5cm,font=scriptsize, inner sep= 0cm, outer sep= 0cm,
fill=white,anchor=center,%
column sep=.5cm,%
row sep=.5cm,%
anchor=center
]%
& Two\ line \breaks & One line && \
One\linebreak&&&& \
&&&Two\line\breaks& \
&&One&& \
;
foreach row/rownext in 1/2,2/3,3/4,4/4
foreach col/colnext in 1/2,2/3,3/4,4/5,5/5
draw(m-row-col) to (m-row-colnext);
draw(m-row-col) to (m-rownext-col);
endtikzpicture
enddocument
answered 3 hours ago
marmot
58.5k463126
58.5k463126
I think this has been first pointed out in tex.stackexchange.com/a/18761/121799.
â marmot
3 hours ago
The problem here is different from the one you pointed. The use ofmatrix of nodes
changes node's anchor tobase
which means thanempty cells
and nodes with text will align on theirbase
anchor, not through thecenter
. Loop Space explained to me also long time ago ;-).
â Ignasi
6 mins ago
add a comment |Â
I think this has been first pointed out in tex.stackexchange.com/a/18761/121799.
â marmot
3 hours ago
The problem here is different from the one you pointed. The use ofmatrix of nodes
changes node's anchor tobase
which means thanempty cells
and nodes with text will align on theirbase
anchor, not through thecenter
. Loop Space explained to me also long time ago ;-).
â Ignasi
6 mins ago
I think this has been first pointed out in tex.stackexchange.com/a/18761/121799.
â marmot
3 hours ago
I think this has been first pointed out in tex.stackexchange.com/a/18761/121799.
â marmot
3 hours ago
The problem here is different from the one you pointed. The use of
matrix of nodes
changes node's anchor to base
which means than empty cells
and nodes with text will align on their base
anchor, not through the center
. Loop Space explained to me also long time ago ;-).â Ignasi
6 mins ago
The problem here is different from the one you pointed. The use of
matrix of nodes
changes node's anchor to base
which means than empty cells
and nodes with text will align on their base
anchor, not through the center
. Loop Space explained to me also long time ago ;-).â Ignasi
6 mins ago
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f451528%2ftikz-matrix-nodes-are-not-in-a-row%23new-answer', 'question_page');
);
Post as a guest
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
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
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