So zeichnen Sie einen Pfeil nach links/rechts in eine Tabelle

So zeichnen Sie einen Pfeil nach links/rechts in eine Tabelle

Ich habe keine Ahnung, wie man einen Links-Rechts-Pfeil in eine Tabelle zeichnet, dieser Pfeil sollte so aussehen Pfeile nach links und rechts

Hier der Code für die Tabelle

\begin{table}[]
\caption{}
\label{tab:arrow}
\begin{tabular}{llllll}
                       &                                           & Text here                                    &                                                         &                                   &  \\
\multicolumn{4}{l}{\textless{}--------------------------------------------------------------------------------------------------\textgreater{}}                             &                                   &  \\
                       & Some other text here                      &                                              & \multicolumn{2}{c}{Some other text here}                                                    &  \\
                       & Some other text here                      &                                              & Some other text here                                    & Some other text here              &  \\
                       & Some other text here                      &                                              & Some other text here                                    & Some other text here              &  \\
                       &                                           & \multicolumn{3}{l}{\textless{}---------------------------------------------------------------------------------------------\textgreater{}} &  \\
                       &                                           &                                              & \multicolumn{2}{c}{Some other text here}                                                    &  \\
                       & \multicolumn{5}{l}{\textless{}------------------------------------------------------------------------------------------------------------------------------------------\textgreater{}}   \\
                       &                                           &                                              & Some other text here                                    &                                   & 
\end{tabular}
\end{table}

Antwort1

Mit {NiceTabular}von nicematrix.

\documentclass{article}
\usepackage{geometry}
\usepackage{caption}
\usepackage{nicematrix,tikz}
\usetikzlibrary{arrows.meta}

\begin{document}

\begin{table}[]
\caption{}
\label{tab:arrow}
\begin{NiceTabular}{llllll}
                 &                      & Text here \\
\\
                 & Some other text here &                  & \Block{1-2}{Some other text here} \\
                 & Some other text here &                  & Some other text here              & Some other text here  &  \\
                 & Some other text here &                  & Some other text here              & Some other text here  &  \\
\\
                 &                      &                  & \Block{1-2}{Some other text here} \\
\\
                 &                      &                  & Some other text here 
\CodeAfter
  \begin{tikzpicture} [-LaTeX]
  \draw [<->] (2.5-|1) -- (2.5-|5) ;
  \draw [<->] (6.5-|3) -- (6.5-|6) ;
  \draw [<->] (8.5-|2) -- (8.5-|7) ;
  \end{tikzpicture}
\end{NiceTabular}
\end{table}

\end{document}

Man braucht mehrere Zusammenstellungen.

Ausgabe des obigen Codes

Wenn Sie die Regeln visualisieren möchten, müssen Sie nur den Schlüssel hvlines(bereitgestellt von nicematrix) verwenden.

\documentclass{article}
\usepackage{geometry}
\usepackage{caption}
\usepackage{nicematrix,tikz}
\usetikzlibrary{arrows.meta}

\begin{document}

\begin{table}[]
\caption{}
\label{tab:arrow}
\begin{NiceTabular}{llllll}[hvlines,rules/width=0.1pt]
                 &                      & Text here \\
\\
                 & Some other text here &                  & \Block{1-2}{Some other text here} \\
                 & Some other text here &                  & Some other text here              & Some other text here  &  \\
                 & Some other text here &                  & Some other text here              & Some other text here  &  \\
\\
                 &                      &                  & \Block{1-2}{Some other text here} \\
\\
                 &                      &                  & Some other text here 
\CodeAfter
  \begin{tikzpicture} [-LaTeX]
  \draw [<->] (2.5-|1) -- (2.5-|5) ;
  \draw [<->] (6.5-|3) -- (6.5-|6) ;
  \draw [<->] (8.5-|2) -- (8.5-|7) ;
  \end{tikzpicture}
\end{NiceTabular}
\end{table}

Ausgabe des obigen Codes


Wenn Sie die Anzahl der Zeilen und Spalten nicht zählen möchten, können Sie auch Blöcke verwenden (Befehl \Block) und diesen Blöcken Namen geben.

\documentclass{article}
\usepackage{geometry}
\usepackage{caption}
\usepackage{nicematrix,tikz}
\usetikzlibrary{arrows.meta}

\begin{document}

\begin{table}[]
\caption{}
\label{tab:arrow}
\begin{NiceTabular}{llllll}
                 &                      & Text here \\
\Block[name=first-arrow]{1-4}{} \\
                 & Some other text here &                  & \Block{1-2}{Some other text here} \\
                 & Some other text here &                  & Some other text here              & Some other text here  &  \\
                 & Some other text here &                  & Some other text here              & Some other text here  &  \\
                 &                      & \Block[name=second-arrow]{1-3}{} \\
                 &                      &                  & \Block{1-2}{Some other text here} \\
                 & \Block[name=third-arrow]{1-5}{} \\
                 &                      &                  & Some other text here 
\CodeAfter
  \begin{tikzpicture} [-LaTeX]
  \draw [<->] (first-arrow.west) -- (first-arrow.east) ;
  \draw [<->] (second-arrow.west) -- (second-arrow.east) ;
  \draw [<->] (third-arrow.west) -- (third-arrow.east) ;
  \end{tikzpicture}
\end{NiceTabular}
\end{table}

\end{document}

Die Ausgabe ist die gleiche.


Es ist auch möglich, einen Befehl zu erstellen, \LeftRightArrowder in die Haupttabelle eingefügt wird und die gesamte Arbeit erledigt (es müssen keine Anweisungen eingegeben werden \CodeAfter).

\documentclass{article}
\usepackage{geometry}
\usepackage{caption}
\usepackage{nicematrix,tikz}
\usetikzlibrary{arrows.meta}


\makeatletter
\ExplSyntaxOn
\NewDocumentCommand { \LeftRightArrow } { m }
  {
    \tl_gput_right:Nx \g_nicematrix_code_after_tl
      { \niru__LeftRightArrow:nnn { \arabic { iRow } } { \arabic { jCol } } { #1 } }
  }

\cs_new_protected:Nn \niru__LeftRightArrow:nnn 
  { \tikz \draw [-LaTeX,<->] (#1.5-|#2) -- (#1.5-|\int_eval:n{#2+#3}) ; }
\ExplSyntaxOff
\makeatother


\begin{document}

\begin{table}[]
\caption{}
\label{tab:arrow}
\begin{NiceTabular}{llllll}
                 &                      & Text here \\
\LeftRightArrow{4} \\
                 & Some other text here &                  & \Block{1-2}{Some other text here} \\
                 & Some other text here &                  & Some other text here              & Some other text here  &  \\
                 & Some other text here &                  & Some other text here              & Some other text here  &  \\
                 &                      & \LeftRightArrow{3} \\
                 &                      &                  & \Block{1-2}{Some other text here} \\
                 & \LeftRightArrow{5} \\
                 &                      &                  & Some other text here 
\end{NiceTabular}
\end{table}

\end{document}

Die Ausgabe ist die gleiche.

Antwort2

Mit einer TikZ-Matrix:

\documentclass{article}
\usepackage{geometry}

\usepackage{tikz}
\usetikzlibrary{matrix, fit}
\usetikzlibrary{arrows.meta}
\tikzset{
    mynode/.style={text height=3ex, text depth=1ex,inner ysep=0pt},
    mymulti/.style={mynode, inner xsep=0pt},
    }

\usepackage{caption}

\begin{document}
\begin{table}\centering 
  \caption{My table}\label{tab:arrow}
  \begin{tikzpicture} 
    \matrix[
      matrix of nodes, nodes in empty cells, nodes={mynode},
      column 1/.style={text width=.3cm},
      column 2/.style={text width=width("Some other text here")},% put the longest text of the column here
      column 3/.style={text width=width("Text here")},% put the longest text of the column here
      column 4/.style={text width=width("Some other text here")},% put the longest text of the column here
      column 5/.style={text width=width("Some other text here")},% put the longest text of the column here
      column 6/.style={text width=.3cm},
      ] (mymatr) {  
      & & Text here & & &  \\
      & & & & & \\
      & Some other text here & & & & \\
      & Some other text here & & Some other text here & Some other text here & \\
      & Some other text here & & Some other text here & Some other text here & \\
      & & & & & \\
      & & & & & \\
      & & & & & \\
      & & & Some other text here & & \\
      };
      % Multicolumn texts
      \node[fit=(mymatr-3-4)(mymatr-3-5), mymulti] {Some other text here};
      \node[fit=(mymatr-7-4)(mymatr-7-5), mymulti] {Some other text here};
      % Arrows
      \draw[{Latex}-{Latex}] (mymatr-2-1.west) -- (mymatr-2-4.east);
      \draw[{Latex}-{Latex}] (mymatr-6-3.west) -- (mymatr-6-5.east);
      \draw[{Latex}-{Latex}] (mymatr-8-2.west) -- (mymatr-8-6.east);
    \end{tikzpicture}   
  \end{table}
\end{document}

Bildbeschreibung hier eingeben

Und falls ihr die Rahmenlinien und den grauen Hintergrund braucht:

\documentclass{article}
\usepackage{geometry}

\usepackage{tikz}
\usetikzlibrary{matrix, fit}
\usetikzlibrary{arrows.meta}
\tikzset{
    mynode/.style={text height=3ex, text depth=1ex,inner ysep=0pt, fill=gray!5},
    mymulti/.style={mynode, inner xsep=0pt},
    myarrow/.style={{Latex}-{Latex},shorten <=1pt,shorten >=1pt},
    }

\usepackage{caption}

\begin{document}
\begin{table}\centering 
  \caption{My table}\label{tab:arrow}
  \begin{tikzpicture} 
    \matrix[
      matrix of nodes, nodes in empty cells, nodes={mynode},
      column 1/.style={text width=.3cm},
      column 2/.style={text width=width("Some other text here")},% put the longest text of the column here
      column 3/.style={text width=width("Text here")},% put the longest text of the column here
      column 4/.style={text width=width("Some other text here")},% put the longest text of the column here
      column 5/.style={text width=width("Some other text here")},% put the longest text of the column here
      column 6/.style={text width=.3cm},
      ] (mymatr) {  
      & & Text here & & &  \\
      & & & & & \\
      & Some other text here & & & & \\
      & Some other text here & & Some other text here & Some other text here & \\
      & Some other text here & & Some other text here & Some other text here & \\
      & & & & & \\
      & & & & & \\
      & & & & & \\
      & & & Some other text here & & \\
      };
      % Multicolumn texts
      \node[fit=(mymatr-3-4)(mymatr-3-5), mymulti] {Some other text here};
      \node[fit=(mymatr-7-4)(mymatr-7-5), mymulti] {Some other text here};
      % Border lines
      \foreach \myrow in {1,2,...,9} 
        {\draw[gray!40] (mymatr-\myrow-1.north west) -- (mymatr-\myrow-6.north east);}
      \draw[gray!40] (mymatr-9-1.south west) -- (mymatr-9-6.south east);
      \draw[gray!40] (mymatr-1-1.north west) -- (mymatr-9-1.south west);
      \foreach \mycol in {2,3,4} 
        {\draw[gray!40] (mymatr-1-\mycol.north west) -- (mymatr-1-\mycol.south west);}
      \draw[gray!40] (mymatr-3-2.north west) -- (mymatr-9-2.south west);
      \draw[gray!40] (mymatr-3-3.north west) -- (mymatr-7-3.south west);
      \foreach \mycol in {3,4,5,6} 
        {\draw[gray!40] (mymatr-9-\mycol.north west) -- (mymatr-9-\mycol.south west);}
      \draw[gray!40] (mymatr-3-4.north west) -- (mymatr-5-4.south west);
      \draw[gray!40] (mymatr-7-4.north west) -- (mymatr-7-4.south west);
      \draw[gray!40] (mymatr-1-5.north west) -- (mymatr-2-5.south west);
      \draw[gray!40] (mymatr-4-5.north west) -- (mymatr-5-5.south west);
      \draw[gray!40] (mymatr-1-6.north west) -- (mymatr-7-6.south west);
      \draw[gray!40] (mymatr-1-6.north east) -- (mymatr-9-6.south east);
      % Arrows
      \draw[myarrow] (mymatr-2-1.west) -- (mymatr-2-4.east);
      \draw[myarrow] (mymatr-6-3.west) -- (mymatr-6-5.east);
      \draw[myarrow] (mymatr-8-2.west) -- (mymatr-8-6.east);
    \end{tikzpicture}   
  \end{table}
\end{document}

Bildbeschreibung hier eingeben

Antwort3

Das Folgende MWEist einigermaßen in Ordnung, aber ich gehe davon aus, dass andere Experten bessere Vorschläge machen werden als ich :-)

\documentclass{book}

\makeatletter
\def\leftrightarrowfill{$\m@th\mathord\leftarrow-\mkern-21mu
\cleaders\hbox{$\!\mathord-\!$}\hfill
\mkern-25mu\mathord-\rightarrow$}
\makeatother

\begin{document}

\begin{table}[]
\caption{}
\label{tab:arrow}
\begin{tabular}{llllll}
                       &                                           & Text here                                    &                                                         &                                   &  \\
\multicolumn{4}{l}{\hbox to 250pt{\leftrightarrowfill}}                             &                                   &  \\
                       & Some other text here                      &                                              & \multicolumn{2}{c}{Some other text here}                                                    &  \\
                       & Some other text here                      &                                              & Some other text here                                    & Some other text here              &  \\
                       & Some other text here                      &                                              & Some other text here                                    & Some other text here              &  \\
                       &                                           &
                       \multicolumn{3}{l}{\hbox to 150pt{\leftrightarrowfill}} &  \\
                       &                                           &                                              & \multicolumn{2}{c}{Some other text here}                                                    &  \\
                        \multicolumn{6}{l}{\hbox to 350pt{\leftrightarrowfill}}   \\
                       &                                           &                                              & Some other text here                                    &                                   & 
\end{tabular}
\end{table}

\end{document}

Bildbeschreibung hier eingeben

verwandte Informationen