4

This question already has an answer here:

How can I make the box distribute evenly? code as below:

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}
\begin{document}
\begin{tikzpicture}
\def\lw{1pt} %define linewidth here
\tikzset{box/.style={draw,rotate=90,inner sep=0pt,line width=\lw,
    minimum width=2.2cm,minimum height=2.2cm,text width=1.6cm}}
\matrix (M1) [matrix of nodes,draw,inner sep=2pt,
        row 1/.style={align=right},
        row 5/.style={align=left},
        row sep=-\lw,column sep=-\lw,
        nodes={box},nodes in empty cells]{
 & PORCH 1st &  & DOOR & \\
 &  &  &  & \\
 &  &  &  & \\
 &  &  &  & \\
 & BSMT & GARAGE & PORCH 2nd & \\};
\end{tikzpicture}
\end{document}

Now the output seems ugly: enter image description here

marked as duplicate by Ignasi tikz-pgf Feb 11 '16 at 7:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Does inner sep=2pt do anything? – cfr Feb 11 '16 at 3:34
3

Add anchor=center to your box/.style:

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}
\begin{document}
\begin{tikzpicture}
\def\lw{1pt} %define linewidth here
\tikzset{box/.style={draw,rotate=90,inner sep=0pt,line width=\lw,
    minimum width=2.2cm,minimum height=2.2cm,text width=1.6cm,anchor=center}}
\matrix (M1) [matrix of nodes,draw,inner sep=2pt,
        row 1/.style={align=right},
        row 5/.style={align=left},
        row sep=-\lw,column sep=-\lw,
        nodes={box},nodes in empty cells]{
 & PORCH 1st &  & DOOR & \\
 &  &  &  & \\
 &  &  &  & \\
 &  &  &  & \\
 & BSMT & GARAGE & PORCH 2nd & \\};
\end{tikzpicture}
\end{document}

Output:

matrix

  • Great, it works now. but why the default anchor so "unstable", it should align the same style but my original output is so "random" distribute. – lucky1928 Feb 11 '16 at 4:10
  • The manual states on page 227: "When you place a node at some coordinate, the node is centered on this coordinate by default." So it could be a bug. – Benjamin Feb 11 '16 at 5:15
  • @Benjamin: It's not a bug, by design matrix of nodes sets anchor=base which is different in empty and non empty nodes. Take a look at tex.stackexchange.com/questions/78964/… – Ignasi Feb 11 '16 at 7:41
  • @Ignasi Thanks. I now also found it in the manual. I have missed that this is a duplicate. Should I just keep my answer here or delete it? I could not find a clear answer on Meta. – Benjamin Feb 11 '16 at 16:07
  • @Benjamin Your answer is correct and useful for people who arrives here. So, why to delete it? – Ignasi Feb 11 '16 at 16:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.