Tabelle in Treppen- bzw. Dreiecksform

Tabellen und Grafiken erstellen und anordnen


TeHaiX
Forum-Newbie
Forum-Newbie
Beiträge: 4
Registriert: Mo 7. Apr 2014, 02:01

Tabelle in Treppen- bzw. Dreiecksform

Beitrag von TeHaiX »

Hallo liebe Gemeinde,

ich habe bereits die Suchfunktion und Google genutzt, jedoch habe ich bis jetzt nichts Passendes gefunden. Ich würde gerne eine Tabelle erstellen, welche die Form eines Dreiecks bzw. eine Treppe besitzt. Ich hoffe ihr könnt mir helfen. Anbei ein Bild zum Verständnis.

Bild

esdd
Forum-Meister
Forum-Meister
Beiträge: 2561
Registriert: So 7. Feb 2010, 16:36

Beitrag von esdd »

Du könntest die Tabelle als Matrix mit TikZ darstellen:
\documentclass[margin=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}
\begin{document}
\begin{tikzpicture}
  \matrix(M)[
    matrix of nodes,
    row sep=-\pgflinewidth,column sep=-\pgflinewidth,
    nodes={draw,text width=1cm,minimum height=2em}
  ]
  {
    {}\\
    {}&{}\\
    {}&{}&{}\\
    {}&{}&{}&{}\\
  };
  \foreach[count=\j] \i in {2,...,5}\node[left=0pt of M-\j-1,font=\tiny]{\i};
  \foreach[count=\j] \i in {1,...,4}\node[below=0pt of M-4-\j,font=\tiny]{\i};
\end{tikzpicture}
\end{document}
Gruß
Elke

Felix
Forum-Century
Forum-Century
Beiträge: 210
Registriert: Sa 25. Jan 2014, 13:57

Beitrag von Felix »

Noch ein Beispiel, was mit TikZ möglich ist - mehr als nur Dreiecksform - Tabelle in Pfeilform.

Felix
Ein TikZ Süchtiger :-)

TeHaiX
Forum-Newbie
Forum-Newbie
Beiträge: 4
Registriert: Mo 7. Apr 2014, 02:01

Beitrag von TeHaiX »

Hi Leute,

die erste Variante war perfekt. Doch wenn ich das Dreieck umdrehen möchte, funktionieren die Abstände nicht mehr richtig. Es sieht bei mir jetzt wie folgt aus.
Bild
\begin{figure}[H]
\centering
\begin{tikzpicture}
\matrix(M)[matrix of nodes,row sep=-\pgflinewidth,column sep=-\pgflinewidth,
nodes={draw,minimum width=4em,minimum height=4em}] 
{
	$ A,B $ & $ A,B $ & $ B $ & $ B $ & $ B $ \\
	$ A,S $ & $ S $ & - & - \\
	$ A,S,C $ & $ C $ & - \\
	$ S,C $ & - \\
	$ C $ \\
};
\foreach[count=\j] \i in {$ a $,$ a $,$ b $, $ b $, $ b $}\node[above=0pt of M-1-\j]{\i}; 
\end{tikzpicture}
\caption{CYK-Algorithmus}
\end{figure}

esdd
Forum-Meister
Forum-Meister
Beiträge: 2561
Registriert: So 7. Feb 2010, 16:36

Beitrag von esdd »

Die Verschiebungen kommen von den unterschiedlichen Unterlängen in den einzelnen Zellen. Das kann man beseitigen, in dem man bei den Optionen für die nodes noch font=\strut ergänzt. (Was macht der Befehl \strut?)
\documentclass{scrartcl}
\usepackage{tikz} 
\usetikzlibrary{matrix,positioning} 
\begin{document}
 
\begin{center}
  \begin{minipage}{\linewidth}
    \centering
    \begin{tikzpicture} 
      \matrix(M)[matrix of math nodes,row sep=-\pgflinewidth,column sep=-\pgflinewidth, 
       nodes={draw,minimum width=4em,minimum height=4em,font=\strut}] 
      { 
          A,B & A,B & B & B & B \\ 
          A,S & S & - & - \\ 
          A,S,C & C & - \\ 
          S,C & - \\ 
          C \\ 
      }; 
      \foreach[count=\j] \i in {a,a,b,b,b}\node[above=0pt of M-1-\j]{$\i$}; 
    \end{tikzpicture} 
    \captionof{figure}{CYK-Algorithmus} 
  \end{minipage}
\end{center}
\end{document}
Gruß
Elke

Antworten