0

For example, in the following (contrived) MWE, I'd like to top align the blue square and the green square. (my ultimate goal is a document with text and pictures, and I would like all of that to look like pure text : top-aligned, left aligned)

More generally, I'd like to be able to control individually all the cells positions in their given "space" in the matrix. Some would be north-east, some south-center, etc.

I suspect the answer to be an "anchor" option with a "north" value, but I don't fully understand the examples I read (on tex.stackexchange.com, in some documents like VisualTikZ, ...).

Any hint (or link to an example) would be much appreciated.

If it is not possible only with TikZ, I will use another package.

Thanks !

MWE

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}

\matrix [line width=2pt] { \draw (0,0) rectangle (1,1) [draw=blue]; & \draw (0,0) rectangle (2,2) [draw=orange]; \

\draw (0,0) rectangle (2,2) [draw=red];
&
\draw (0,0) rectangle (1,1) [draw=green]; \ };

\end{tikzpicture} \end{document}

enter image description here

Michaël
  • 124
  • Maybe https://tex.stackexchange.com/questions/20535/non-vertically-centered-tikz-matrix-of-nodes-cell-content contains some pointers. – Marijn May 29 '21 at 15:49
  • @Michael was your problem solved – js bibra Jun 02 '21 at 05:22
  • Thanks to both of you! Yes, my problem is solved. For the more complex matrices I'm creating, with cells of different sizes, I am doing some basic computing in the program creating my TeX file, to do the north-shifting (like in the answer of @js bibra). – Michaël Jun 02 '21 at 12:17

1 Answers1

0

You are hard coding the start and end point of each rectangle by providing coordinates -- so all that is required is to vary these coordinates -- anchor would not help in such cases -- in my perception

enter image description here

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[]

\matrix [line width=2pt, ] { \draw (0,1) rectangle (1,2) [draw=blue]; & \draw (0,0) rectangle (2,2) [draw=orange]; \

\draw (0,0) rectangle (2,2) [draw=red];
&
\draw (1,1) rectangle (2,2) [draw=green]; \ };

\end{tikzpicture} \end{document}

js bibra
  • 21,280
  • Very simple and useful solution! Reading it and the other link (@Marijn) made me realize that a TkiZ matrix probably does not work the way I thought (nor the way I want), and that this part is not so easy and intuitive (for me) as other aspects of TkiZ. But seeing what beautiful and complex things TKiZ can do, I'm surprised to think that TKiZ can't do some simple north-shifting that can be done with just simple arithmetics and no experience of the tool (like I did). – Michaël Jun 02 '21 at 12:21