Tabelle / TikZ: Morphologischer Kasten:

Tabellen und Grafiken erstellen und anordnen


Neo
Forum-Fortgeschrittener
Forum-Fortgeschrittener
Beiträge: 61
Registriert: Mo 21. Dez 2020, 20:36

Tabelle / TikZ: Morphologischer Kasten:

Beitrag von Neo »

Guten Tag,

ich würde gerne einen Morphologischen Kasten inkl. Verbindungslinien mit TikZ erstellen. Eine passende Vorlage habe ich dazu bereits in einem anderen Forum gefunden. Da ich mit TikZ nicht wirklich gut klarkomme und ich bis zum Abgabedatum meiner Masterthesis auch zu wenig Zeit habe, um mich einzuarbeiten, hätte ein erfahrener Anwender eventuell eine schnelle Lösung?

Anliegen: Die mit TikZ erzeugte Tabelle aus dem Minibeispiel #1 soll das Tabellenlayout aus dem Minibeispiel #2 erhalten. Sprich: Senkrechte Linien mit allen passenden Abständen. Graue Einfärbung wäre auch schön - ist aber kein Muss.

Falls da jemand Lust zu hat, eine Lösung zu finden, ich wäre dankbar.
PS: Ich weiß, senkrechte Linien sollte man generell in Tabellen vermeiden. In der Matrix-Darstellung will mein Prof. es aber so haben.

Minibeispiel 1 mit TikZ:
\documentclass[captions=tableheading]{scrreprt}
\usepackage[top=25mm , bottom=25mm , left=25mm , right=25mm , bindingoffset=5mm]{geometry}

\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{tikz}
\usetikzlibrary{matrix}

\newlength\bildhoehe
\setlength\bildhoehe{2cm}
\newcommand\bildbreite{2cm}
\newcommand\schrift{\footnotesize}% Einstellung für Bildbeschriftungen
\newcommand\zeilenabstand{.75\tabcolsep}

\newcommand\grafik[2]{%
  \begin{minipage}{\bildbreite}
    \centering\raisebox{.5\tabcolsep}{%
      \parbox{\linewidth}{\hspace*{0pt}\raggedright\schrift#1}}\newline%
    \includegraphics[width=\linewidth,height=\bildhoehe]{#2}%
  \end{minipage}%
}

\newcommand\LV{\rule{0pt}{0.5\bildhoehe}}% Stütze, liefert nötige Höhe für Endpunkte

\tikzset{vp/.style={circle,fill,inner sep=3pt}}
\newcommand\verbindungslinie[3]{
  \foreach [remember=\p as \lastp (initially #2)] \p in {#3}
    \draw[#1]([yshift=.5\bildhoehe]\lastp.south)node[vp]{}--([yshift=.5\bildhoehe]\p.south)node[vp]{};
}

\usepackage{mwe}% für example-image
\begin{document}
\begin{center}
  \begin{minipage}{\linewidth}
    \captionof{table}{Morphologischer Kasten}\label{morphKasten} 
    \begin{tikzpicture}[
        very thick,
        nodes={inner sep=\tabcolsep}
      ]
      \matrix[
          matrix of nodes,
          inner sep=0pt,
          nodes={anchor=south},
          row sep=\zeilenabstand,
          column 1/.style={text width={2\tabcolsep+1em},align=right,yshift=0.5\bildhoehe},
          column 2/.style={minimum width=4.5cm,yshift=0.5\bildhoehe}
        ](m){
          1&Teilfunktion 1
            &\grafik{Text}{example-image}
            &\grafik{Text}{example-image}
            &\grafik{Text}{example-image}
            &\grafik{Text}{example-image}\\
          2&Teilfunktion 2
            &\grafik{längerer Text}{example-image}
            &\grafik{Beispielbild}{example-image}
            &\grafik{Text}{example-image}
            &\grafik{Text}{example-image}\\[\tabcolsep]% wegen der Linie
          \ldots&{}
            &\grafik{Text}{example-image}
            &\grafik{Bild mit sehr langem Text}{example-image}
            &\grafik{Text}{example-image}
            &\grafik{Text}{example-image}\\
          n&Teilfunktion n
            &\grafik{Text}{example-image}
            &\grafik{Text}{example-image}
            &\grafik{Text}{example-image}
            &\grafik{Text}{example-image}\\
          &&\LV&\LV&\LV&\LV\\
        };
% Kopfzeile
      \node(ul)[anchor=south west] 
        at ([yshift={\zeilenabstand+\aboverulesep+\belowrulesep}]m.north west)
        {Teilfunktion};
      \node(or)[anchor=south east] at (ul.north-|m-1-2.east){Lösungsvarianten};
      \foreach[count=\i from 3] \c in {1,2,\ldots,m}
        \node[anchor=base] at (or.base-|m-1-\i){\c};
% Tabellenlinien
      \draw[line width=\lightrulewidth](or.north-|ul.west)--(or.east|-ul.south)
        ([yshift=-\aboverulesep]ul.south-|m.west)
          --([yshift=-\aboverulesep]ul.south-|m.east);
      \draw[line width=\heavyrulewidth]([yshift=\belowrulesep]or.north-|m.west)
          --([yshift=\belowrulesep]or.north-|m.east)
        ([yshift={-\aboverulesep-\zeilenabstand}]m.south west)
          --([yshift={-\aboverulesep-\zeilenabstand}]m.south east);
% Verbindungslinien
      \verbindungslinie{red}{m-1-3}{m-2-4,m-3-3,m-4-5,m-5-5}
      \verbindungslinie{blue}{m-1-5}{m-2-3,m-3-3,m-4-3,m-5-3}
      \verbindungslinie{green}{m-1-6}{m-2-6,m-3-4,m-4-6,m-5-6}
      \foreach \f/\p/\t in {red/m-5-5/LV1,blue/m-5-3/LV2,green/m-5-6/LV3}
        \node[\f,below,font=\bfseries]at(\p){\t};
% vertikale Beschriftung und Tabellenzwischenlinie
      \path(m-1-1.north west)--
         node[xshift=\zeilenabstand,rotate=90]{}
        (m-2-1.south west);
      \draw[line width=\lightrulewidth]([yshift=-\tabcolsep]m.west|-m-2-3.south)--([yshift=-\tabcolsep]m.east|-m-2-3.south);
    \end{tikzpicture}
  \end{minipage}
\end{center}
\end{document}


Minibeispiel 2 ohne TikZ, aber mit gewünschtem Layout:

\documentclass[headsepline]{scrreprt}
\usepackage{lmodern}					% verbesserte Fonts
\usepackage[T1]{fontenc}				
\usepackage[utf8]{inputenc}				% Codierung
\usepackage[english, ngerman]{babel}	% Sprache DE
\usepackage[svgnames,table,x11names]{xcolor}			% Farbe
\usepackage{tabularx}					% Tabellen in Textbreite
\usepackage{makecell, cellspace, bigstrut}
\usepackage[bindingoffset = 5mm,left = 25mm,right = 25mm,bottom = 25mm,top = 25mm]{geometry}
\usepackage[automark]{scrlayer-scrpage} % Kopf- Fußzeilenpaket
\usepackage{graphicx}					% Abbildungen
%
\clearpairofpagestyles		% individuelle Kopf- und Fußzeilen
\pagestyle{scrheadings}		% pagestyle für Dokument aktivieren
\ihead{\headmark}						% Kopfzeile links
\ohead*{\pagemark}					% Kopfzeile rechts	
%
\newcolumntype{C}{>{\centering\arraybackslash}X}
%
\begin{document}
%
\begin{table}[h]
\begin{tabularx}{\textwidth}{|p{5mm}|C|C|C|C|C|}\hline
\rowcolor{Gainsboro} & & \multicolumn{4}{c|}{Lösungsvariante}  \\
\rowcolor{Gainsboro} \textbf{Nr.} & Teilfunktion & 1 & 2 & 3 & 4   \\ \hline
\cellcolor{Gainsboro} \makecell{1} & \cellcolor{Gainsboro} \parbox[c]{22mm}{Ölstrom \\ verjüngen \& \\ bündeln} & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}}  & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}} &  \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}} & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}} \\ \hline
\cellcolor{Gainsboro} \makecell{2} & \cellcolor{Gainsboro} \parbox[c]{22mm}{Licht \\ einleiten} & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}} & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}} & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}} & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}} \\ \hline
\cellcolor{Gainsboro} \makecell{3} & \cellcolor{Gainsboro} \parbox[c]{22mm}{Licht  \\ ausleiten} & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}} & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}} & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}}  & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}}\\\hline
\cellcolor{Gainsboro} \makecell{4} & \cellcolor{Gainsboro} \parbox[c]{25mm}{test \\ realisieren} & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}}  & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}} & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}} & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}}\\\hline
\cellcolor{Gainsboro} \makecell{5} & \cellcolor{Gainsboro} \parbox[c]{22mm}{test \\ kompensieren} & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}} & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}} & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}}   & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}}\\ \hline
\cellcolor{Gainsboro} \makecell{6} & \cellcolor{Gainsboro} \parbox[c]{22mm}{Verjüngung \\ abdichten} & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}} & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}} & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}}  &\makecell{BILD  \\ \includegraphics[width=2cm]{example-image}} \\\hline
\cellcolor{Gainsboro} \makecell{7} & \cellcolor{Gainsboro} \parbox[c]{22mm}{test \\ abdichten} & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}} &   \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}} & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}} & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}}\\\hline
\cellcolor{Gainsboro} \makecell{8} & \cellcolor{Gainsboro} \parbox[c]{22mm}{test \\ test} & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}} & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}} & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}} & \makecell{BILD  \\ \includegraphics[width=2cm]{example-image}}\\\hline
\end{tabularx}
\end{table}
%
\end{document}