Seite 1 von 1
[Tikz] Matrix of Math Nodes positionieren? Dringend
Verfasst: Mo 20. Jan 2014, 20:05
von BlackDevil
Aloah
Ich brauche am besten noch heute Abend eine Antwort ... ich möchte ein Tikz Bild zeichnen in dem eine kleine Matrix vorkommt. Kann ich die Matrix nun irgendwie im Bild verschieben?
Miniaturbeispiel:
\documentclass{scrbook}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix (m)[matrix of math nodes,left delimiter=[,right delimiter={]},ampersand replacement=\&] {
1 \& 2 \\
3 \& 4 \\
};
\end{tikzpicture}
\end{document}
Danke im voraus und Grüße

Verfasst: Mo 20. Jan 2014, 20:31
von Studi
Du kannst shift-Parameter zu den Matrix-Optionen hinzufügen:
\matrix (m)[matrix of math nodes,left delimiter=[,right delimiter={]},ampersand replacement=\&,
xshift=1cm, yshift=1cm] {
1 \& 2 \\
3 \& 4 \\
};
Studi
Verfasst: Mo 20. Jan 2014, 21:00
von BlackDevil
Nice
danke

Verfasst: Mo 20. Jan 2014, 21:54
von cgnieder
Da eine Matrix letztlich auch nur eine Node ist, kannst Du auch einfach die Koordinaten angeben, wo die Matrix platziert sein soll:
\documentclass{scrbook}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\draw[help lines] (0,0) grid (5,5) ;
\matrix (m) at (2,3) % <<< Platzierung
[
matrix of math nodes,
left delimiter=[,
right delimiter={]},
ampersand replacement=\&
]
{
1 \& 2 \\
3 \& 4 \\
} ;
\end{tikzpicture}
\end{document}
Grüße
Verfasst: Mo 20. Jan 2014, 22:00
von BlackDevil
@cgnieder: Das habe ich mir gedacht, kam aber irgendwie nicht auf das "at"
Tikz ist Zeitaufwändig - macht aber irgendwo Spaß und das Ergebnis überzeugt. Sieht nun so aus:
\documentclass{scrbook}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix (m)[matrix of math nodes,left delimiter=[,right delimiter={]},xshift=0cm, yshift=0] {
w_{11} & w_{12} & w_{13} \\
w_{21} & w_{22} & w_{23} \\
w_{31} & w_{32} & w_{33} \\
w_{41} & w_{42} & w_{43} \\
};
\node[left of=m, xshift=-0.9cm] (a) {=};
\node[left of=a,yshift=2cm] (b) {};
\node[left of=a,yshift=-2cm] (c) {};
\draw[thick,red,decorate,decoration={brace,amplitude=12pt}] (b) -- (c);
\foreach \name/\y/\text in {d/1.2cm/1,e/0/2,f/-1.2cm/3}
\node[thick,draw,circle, left of=a,xshift=-1cm,yshift=\y,scale=0.8] (\name) {$O_\text$};
\foreach \name/\y/\text in {g/1.7cm/1,h/0/2,i/-1.7cm/3}
\node[thick,draw,circle, left of=a,xshift=-2.5cm,yshift=\y,scale=0.9] (\name) {$I_\text$};
\foreach \namea in {d,e,f}
\foreach \nameb in {g,h,i}
\draw[->] (\nameb) -- (\namea);
\end{tikzpicture}
\end{document}
Wenn man das mal mit den relativen Koordinaten geschnallt hat ist das echt Gold wert ...
Verfasst: Di 21. Jan 2014, 11:30
von sudo
Noch besser ist es mit der postitions library. Damit kannst du left=of m verwenden und kannst dir in der Regel Nachjustierungen mit xshift sparen, weil der tatsächliche Abstand genommen wird statt dem Abstand der Mittelpunkte.
Verfasst: Di 21. Jan 2014, 11:36
von BlackDevil
Ich schau mir das mal. Ich vermute aber, das ich trotzdem mit xshift die Position korrigieren würde. Ansonsten weiß Latex bzw. Tikz ja nicht wo ich das Element haben möchte, außer eben Links von einem anderen Element.
Verfasst: Di 21. Jan 2014, 14:13
von sudo
Den allgemeinen Abstand kannst du mit node distance einstellen. Den kannst du auch bei einem node noch einmal ändern. Da musst du AFAIR ein bisschen auf die Reihenfolge der Optionen achten.
Verfasst: Di 21. Jan 2014, 18:09
von BlackDevil
Hmmm okay. Ich schau mir das mal an, danke

Verfasst: Mi 29. Jan 2014, 15:33
von Ludger
Hübsch gemacht, das kann ich als Codeschnipsel sogar gebrauchen

. Wobei ich inhaltlich die vierte Zeile der Matrix nicht ganz verstehe

Aber darum gehts hier ja auch nicht.
Gruß, Ludger