1

I am trying to overlay a TikZpicture over my table and would like it to look like this:enter image description here

My code is the following

\documentclass{scrreprt}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[pdftex]{graphicx}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{shapes}
\usetikzlibrary{tikzmark}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{booktabs}
\usepackage {tabularx}
\usepackage{multirow}

\begin{document}

\newcommand{\newfig}[3]{\begin{subfigure}[t]{\linewidth}\centering\includegraphics[width=#1]{#2}\vspace{-4pt}\caption*{\footnotesize\centering #3}\end{subfigure}}
\newcommand{\newfigg}[3]{\begin{subfigure}[t]{\linewidth}\centering \includegraphics[height=#1]{#2}\vspace{-4pt}\caption*{\footnotesize\centering #3}\end{subfigure}}
\newcommand{\myCoord}[1]{
  \tikzmark{#1}
    \tikz\draw[fill=red,color=red] (pic cs:#1) circle[radius=3pt];
}

\begin{table}%
\centering
\begin{tabularx}{\textwidth}{m{0.2\linewidth}|X}
  \toprule
  Teilaufgabe&Lösungsvarianten\\
    \midrule
  Heizelement&{\begin{tabularx}{\linewidth}{X|X|X|X}
        \myCoord{a}\newfig{2.2cm}{example-image.png}{elektrischer Widerstand}&
    \newfig{2.2cm}{example-image.png}{Heizkartusche}&
    \newfig{2.2cm}{example-image.png}{Nickelchrom-draht}&
    \newfig{2.2cm}{example-image.png}{Verbrennung}
    \end{tabularx}}\\
  \midrule
  Temperatur- messung&{\begin{tabularx}{\linewidth}{*{2}{X|}X}
        \newfigg{1.3cm}{example-image.png}{Widerstands-thermometer}&
        \myCoord{b}\newfigg{1.3cm}{example-image.png}{Thermistor}&
        \newfigg{1.3cm}{example-image.png}{Thermoelement}
    \end{tabularx}}\\
    \midrule
    Mischverfahren&{\begin{tabularx}{\linewidth}{*{4}{X|}X}
        \centering aktiv&\multicolumn{4}{c}{passiv}\\ \midrule
        \newfig{1.8cm}{example-image.png}{Mischstab}&
        \newfig{1.8cm}{example-image.png}{gestufte Labyrinthmischdüse}&
        \myCoord{c}\newfig{1.8cm}{example-image.png}{Linear Edge Melt Filter}&
        \newfig{1.8cm}{example-image.png}{Statische Mischdüse}&
        \newfig{1.8cm}{example-image.png}{Statische Mischdüse}
    \end{tabularx}}\\
\bottomrule
\end{tabularx}

\begin{tikzpicture}[remember picture]
  \draw[overlay,color=red] (pic cs:a) -- (pic cs:b) -- (pic cs:c);
\end{tikzpicture}

\end{table}

\end{document}

And I'm getting the following result: enter image description here

I'm thankful for any help!

0

Drawing on top of pictures generally requires some manual adjustments. But don't mix between overlaying and direct drawing. Because direct drawing can destroy your original figure alignment. I removed the \myCoord command and did all drawings in an overlay style.

\documentclass{scrreprt}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[pdftex]{graphicx}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{shapes}
\usetikzlibrary{tikzmark}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{booktabs}
\usepackage {tabularx}
\usepackage{multirow}

\begin{document}

\newcommand{\newfig}[3]{\begin{subfigure}[t]{\linewidth}\centering\includegraphics[width=#1]{#2}\vspace{-4pt}\caption*{\footnotesize\centering #3}\end{subfigure}}
\newcommand{\newfigg}[3]{\begin{subfigure}[t]{\linewidth}\centering \includegraphics[height=#1]{#2}\vspace{-4pt}\caption*{\footnotesize\centering #3}\end{subfigure}}

\begin{table}%
\centering
\begin{tabularx}{\textwidth}{m{0.2\linewidth}|X}
  \toprule
  Teilaufgabe&Lösungsvarianten\\
    \midrule
  Heizelement&{\begin{tabularx}{\linewidth}{X|X|X|X}
        \newfig{2.2cm}{example-image.png}{elektrischer Widerstand}\tikzmark{a}&
    \newfig{2.2cm}{example-image.png}{Heizkartusche}&
    \newfig{2.2cm}{example-image.png}{Nickelchrom-draht}&
    \newfig{2.2cm}{example-image.png}{Verbrennung}
    \end{tabularx}}\\
  \midrule
  Temperatur- messung&{\begin{tabularx}{\linewidth}{*{2}{X|}X}
        \newfigg{1.3cm}{example-image.png}{Widerstands-thermometer}&
        \newfigg{1.3cm}{example-image.png}{Thermistor}\tikzmark{b}&
        \newfigg{1.3cm}{example-image.png}{Thermoelement}
    \end{tabularx}}\\
    \midrule
    Mischverfahren&{\begin{tabularx}{\linewidth}{*{4}{X|}X}
        \centering aktiv&\multicolumn{4}{c}{passiv}\\ \midrule
        \newfig{1.8cm}{example-image.png}{Mischstab}&
        \newfig{1.8cm}{example-image.png}{gestufte Labyrinthmischdüse}&
        \newfig{1.8cm}{example-image.png}{Linear Edge Melt Filter}\tikzmark{c}&
        \newfig{1.8cm}{example-image.png}{Statische Mischdüse}&
        \newfig{1.8cm}{example-image.png}{Statische Mischdüse}
    \end{tabularx}}\\
\bottomrule
\end{tabularx}

\begin{tikzpicture}[remember picture]
  \draw[overlay,color=red] ([shift={(-1.1cm,.9cm)}]pic cs:a)node[circle,fill=red,color=red]{} -- ([shift={(-1.6cm,.6cm)}]pic cs:b)node[circle,fill=red,color=red]{} -- ([shift={(-.9cm,.7cm)}]pic cs:c)node[circle,fill=red,color=red]{};
\end{tikzpicture}

\end{table}

\end{document}

enter image description here

|improve this answer|||||
0

Although your original mycoord command introduced misalignments, it can be modified to do what you wanted. In following code, mycoord command is similar to newfig or newfigg but it declares a TiKZ node surrounding includegraphics. This nodes can be later used to draw links between them.

\documentclass{scrreprt}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[pdftex]{graphicx}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{shapes}
\usetikzlibrary{tikzmark}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{booktabs}
\usepackage {tabularx}
\usepackage{multirow}

\begin{document}

\newcommand{\newfig}[3]{\begin{subfigure}[t]{\linewidth}\centering\includegraphics[width=#1]{#2}\vspace{-4pt}\caption*{\footnotesize\centering #3}\end{subfigure}}
\newcommand{\newfigg}[3]{\begin{subfigure}[t]{\linewidth}\centering \includegraphics[height=#1]{#2}\vspace{-4pt}\caption*{\footnotesize\centering #3}\end{subfigure}}

\newcommand{\myCoord}[4]{%
\begin{subfigure}[t]{\linewidth}%
\centering%
  \begin{tikzpicture}[remember picture] 
   \node[inner sep=0pt, outer sep=0pt] (#1) {\includegraphics[#2]{#3}};
   \fill[red] (#1) circle (3pt); 
  \end{tikzpicture}%
\vspace{-4pt}\caption*{\footnotesize\centering #4}\end{subfigure}}

\begin{table}%
\centering
\begin{tabularx}{\textwidth}{m{0.2\linewidth}|X}
  \toprule
  Teilaufgabe&Lösungsvarianten\\
    \midrule
  Heizelement&{\begin{tabularx}{\linewidth}{X|X|X|X}
        \myCoord{a}{width=2.2cm}{example-image.png}{elektrischer Widerstand}&
    \newfig{2.2cm}{example-image.png}{Heizkartusche}&
    \newfig{2.2cm}{example-image.png}{Nickelchrom-draht}&
    \newfig{2.2cm}{example-image.png}{Verbrennung}
    \end{tabularx}}\\
  \midrule
  Temperatur- messung&{\begin{tabularx}{\linewidth}{*{2}{X|}X}
        \newfigg{1.3cm}{example-image.png}{Widerstands-thermometer}&
        \myCoord{b}{height=1.3cm}{example-image.png}{Thermistor}&
        \newfigg{1.3cm}{example-image.png}{Thermoelement}
    \end{tabularx}}\\
    \midrule
    Mischverfahren&{\begin{tabularx}{\linewidth}{*{4}{X|}X}
        \centering aktiv&\multicolumn{4}{c}{passiv}\\ \midrule
        \newfig{1.8cm}{example-image.png}{Mischstab}&
        \newfig{1.8cm}{example-image.png}{gestufte Labyrinthmischdüse}&
        \myCoord{c}{width=1.8cm}{example-image.png}{Linear Edge Melt Filter}&
        \newfig{1.8cm}{example-image.png}{Statische Mischdüse}&
        \newfig{1.8cm}{example-image.png}{Statische Mischdüse}
    \end{tabularx}}\\
\bottomrule
\end{tabularx}

\begin{tikzpicture}[remember picture]
  \draw[overlay,color=red] (a.center) -- (b.center) -- (c.center);
\end{tikzpicture}

\end{table}

\end{document}

enter image description here

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.