Seite 2 von 2

Re: Zentrierte Textausrichtung in Zellen einer Matrix

Verfasst: Mi 12. Mai 2021, 15:39
von kannstmasehn

Danke, das sieht sehr gut aus.

Ich habe noch einige Marker eingebaut, die nun verstellt sind. Wie kann ich neben dem Text ein einfaches Rechteck oder einen Kreis hinzufügen?

\documentclass[a4paper,12pt]{report}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{booktabs,etoolbox}

\tikzset{
  kastenzelle/.style={inner sep=3pt,text height=\ht\strutbox,text depth=\dp\strutbox},
  leer/.style={}
}

\tikzset{re/.style={rectangle,fill,inner sep=2pt}}
\newcommand\verbindungslinieDR[3]{
	\foreach [remember=\p as \lastp (initially #2)] \p in {#3}
	\draw[#1,dotted](\lastp.east)node[re]{}-.(\p.east)node[re]{};
}

\begin{document}
\begin{table}[!tbph]
  \centering
  \caption{Morphologischer Kasten}
  \begin{tikzpicture}[
    nodes={kastenzelle}
    ]
    \matrix[
    matrix of nodes,
    column 1/.style={anchor=base west},% 1.Spalte rechtsbündig
    column 2/.style={anchor=base},
    column 3/.style={anchor=base},
    column 4/.style={anchor=base},
    column 5/.style={anchor=base},
    column 6/.style={anchor=base},
    ](m){
    Test
    & Test
    & Test
    & Test
    & Test \\
            
    Testp
    & Test
    & Test
    & Test
    & Blub \\
    
    Test
    & Test
    & Test
    & PfPfPfp
    & Test \\
    
    Testfunktion
    & Test
    & Test
    & Test
    & Test \\
    };
    
    % Kopfzeile
    \node(ul)[anchor=south west] at (m.north-|m-1-1.west) {Teilfunktion};
    \foreach[count=\i from 2] \c in {1,2,3,4} \node[anchor=base] at (ul.base-|m-1-\i){\c};
    % Tabellenlinien
    \draw[line width=\lightrulewidth]
    ([yshift=0]ul.south-|m.west)
    --([yshift=0]ul.south-|m.east);
    \draw[line width=\heavyrulewidth]([yshift=0]ul.north-|m.west)
    --([yshift=0]ul.north-|m.east)
    ([yshift={0}]m.south west)
    --([yshift={0}]m.south east);
    
    % Verbindungslinien
    \verbindungslinieDR{black}{m-1-5}{m-2-4,m-3-4,m-4-4}
    
  \end{tikzpicture}
\end{table}
\end{document}

Danke im Voraus.


Re: Zentrierte Textausrichtung in Zellen einer Matrix

Verfasst: Mi 12. Mai 2021, 18:38
von esdd

Du musst dann eben schauen, dass der Stil kastenzelle nur auf die Nodes der Matrix bzw. der Spaltenüberschriften wirkt. Außerdem würde ich den Abstand zwischen den Spalten etwas vergrößern.

\documentclass[a4paper,12pt]{report}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{booktabs,etoolbox}

\tikzset{
  kastenzelle/.style={inner sep=3pt,text height=\ht\strutbox,text depth=\dp\strutbox},
  leer/.style={}
}

\tikzset{re/.style={rectangle,fill,inner sep=2pt}}
\newcommand\verbindungslinieDR[3]{
	\foreach [remember=\p as \lastp (initially #2)] \p in {#3}
	\draw[#1,dotted](\lastp.east)node[re]{}-.(\p.east)node[re]{};
}

\begin{document}
\begin{table}[!tbph]
  \centering
  \caption{Morphologischer Kasten}
  \begin{tikzpicture}
    \matrix[
    matrix of nodes,
    nodes={kastenzelle},% <- Einstellung nur für Nodes in Matrix
    column sep=2pt,% <- etwas mehr Abstand zwischen den Spalten
    column 1/.style={anchor=base west},% 1.Spalte rechtsbündig
    column 2/.style={anchor=base},
    column 3/.style={anchor=base},
    column 4/.style={anchor=base},
    column 5/.style={anchor=base},
    column 6/.style={anchor=base},
    ](m){
    Test
    & Test
    & Test
    & Test
    & Test \\
            
    Testp
    & Test
    & Test
    & Test
    & Blub \\
    
    Test
    & Test
    & Test
    & PfPfPfp
    & Test \\
    
    Testfunktion
    & Test
    & Test
    & Test
    & Test \\
    };
    
    % Kopfzeile
    % Stil kastenzelle für Nodes in Kopfzeile ergänzt:
    \node(ul)[anchor=south west,kastenzelle] at (m.north-|m-1-1.west) {Teilfunktion};
    \foreach[count=\i from 2] \c in {1,2,3,4} \node[anchor=base,kastenzelle] at (ul.base-|m-1-\i){\c};
    % Tabellenlinien
    \draw[line width=\lightrulewidth]
    ([yshift=0]ul.south-|m.west)
    --([yshift=0]ul.south-|m.east);
    \draw[line width=\heavyrulewidth]([yshift=0]ul.north-|m.west)
    --([yshift=0]ul.north-|m.east)
    ([yshift={0}]m.south west)
    --([yshift={0}]m.south east);
    
    % Verbindungslinien
    \verbindungslinieDR{black}{m-1-5}{m-2-4,m-3-4,m-4-4}
    
  \end{tikzpicture}
\end{table}
\end{document}

Re: Zentrierte Textausrichtung in Zellen einer Matrix

Verfasst: Do 13. Mai 2021, 08:43
von kannstmasehn

Danke, stimmt. Nun passt es perfekt. Vielen Dank.