Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

LaTeX table cell-to-cell connection line

1,006 views
Skip to first unread message

Speedbird80

unread,
Nov 11, 2010, 12:29:22 PM11/11/10
to
Hello

I would like to connect different LaTeX-table cells with dotted,
dashed lines according this example:

https://home.zhaw.ch/~grenasil/documents/PAX_Ansprueche.jpg

Could anyone give me a hint? Thanks a lot.

Best regards,
Tom

Lars Madsen

unread,
Nov 11, 2010, 1:07:42 PM11/11/10
to

seems doable using tikz

Alan Munn

unread,
Nov 12, 2010, 1:05:08 AM11/12/10
to
In article
<721353f0-4d73-4e2e...@i41g2000vbn.googlegroups.com>,
Speedbird80 <Top...@web.de> wrote:

> https://home.zhaw.ch/~grenasil/documents/PAX_Ansprueche.jpg

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix (A) [matrix of nodes, nodes in empty cells, row
sep={1cm,between origins}]
{ColumnA & ColumnB & ColumnC & ColumnD & ColumnF \\
RowA &&&&\\
RowB &&&&\\
RowC &&&&\\
RowD &&&&\\
};
\draw[thick,dotted] (A-2-2.center) -- (A-4-3.center) -- (A-3-4.center)
-- (A-3-5.center);
\draw[thick] (A-3-2.center) -- (A-2-3.center) -- (A-2-4.center) --
(A-4-5.center);
\end{tikzpicture}

\end{document}

etc.

Alan

Speedbird80

unread,
Nov 12, 2010, 10:20:02 AM11/12/10
to
On 12 Nov., 07:05, Alan Munn <am...@msu.edu> wrote:
> In article
> <721353f0-4d73-4e2e-b99b-445cdf63a...@i41g2000vbn.googlegroups.com>,

>
>  Speedbird80 <Top_...@web.de> wrote:
> >https://home.zhaw.ch/~grenasil/documents/PAX_Ansprueche.jpg
>
> \documentclass{article}
> \usepackage{tikz}
> \usetikzlibrary{matrix}
> \begin{document}
> \begin{tikzpicture}
>    \matrix (A) [matrix of nodes, nodes in empty cells, row
> sep={1cm,between origins}]
>    {ColumnA & ColumnB & ColumnC & ColumnD & ColumnF \\
> RowA &&&&\\
> RowB &&&&\\
> RowC &&&&\\
> RowD &&&&\\
>    };
> \draw[thick,dotted] (A-2-2.center) -- (A-4-3.center) -- (A-3-4.center)
> -- (A-3-5.center);
> \draw[thick] (A-3-2.center) -- (A-2-3.center) -- (A-2-4.center) --
> (A-4-5.center);
> \end{tikzpicture}
>
> \end{document}
>
> etc.
>
> Alan

Hi Alan

Thanks a lot for your help. That's a perfect template.
On the first view, I didn't find out, how to draw the vertical and
horizontal line between the colomns and rows.

Could you help me? Thanks a lot anyway.

Best regards
Tom

Alan Munn

unread,
Nov 12, 2010, 12:31:19 PM11/12/10
to
In article
<a3bf56e9-2b0c-44af...@w18g2000vbe.googlegroups.com>,
Speedbird80 <Top...@web.de> wrote:

After I sent this, I realized that drawing the table lines would be
difficult. So here's a different approach, using a regular table, and
then overlaying the lines with \tikz commands. (You'll need to typeset
twice to get the lines positioned correctly.) -Alan


\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\usepackage{array}

% create a new column type with some extra height in each cell
\newcolumntype{C}{@{}>{\centering\arraybackslash}p{2cm}<{\rule[-1.5ex]{0p
t}{5ex}}@{}}

% create a command to place a tikz node (supply unique node name as the
argument)
\newcommand*{\tknode}[1]{\tikz[remember picture]\node (#1) {};}

\begin{document}
\begin{tabular}{|C|C|C|C|C|C|}
\hline
& ColumnA & ColumnB & ColumnC & ColumnD & ColumnF \\
\hline
RowA &\tknode{A} &\tknode{F}&\tknode{G}&&\\
\hline
RowB &\tknode{E}&&\tknode{C}&&\tknode{D}\\
\hline
RowC &&\tknode{B}&&&\\
\hline
RowD &&&&\tknode{H}&\\
\hline
\end{tabular}

% now connect up the nodes
\tikz[remember picture, overlay] \draw[thick,dotted] (A.center) --
(B.center) -- (C.center) -- (D.center);
\tikz[remember picture, overlay] \draw[thick] (E.center) -- (F.center)
-- (G.center) -- (H.center);

\end{document}

Speedbird80

unread,
Nov 14, 2010, 5:10:41 PM11/14/10
to
On 12 Nov., 18:31, Alan Munn <am...@msu.edu> wrote:
> In article
> <a3bf56e9-2b0c-44af-ac63-5cac84e89...@w18g2000vbe.googlegroups.com>,

Hi Alan

Wow, this solution is exactly that I looked for. As I copied the code
here, the linebrake followed first to 31 erros, but now I recognised
this was the line break.
Anyway thanks a lot for your great help! By the way, would you draw
the legend below the table also with an TikZ overlay?

Best regards
Tom

Alan Munn

unread,
Nov 14, 2010, 6:08:47 PM11/14/10
to
In article
<23382fdf-870a-4e66...@n30g2000vbb.googlegroups.com>,
Speedbird80 <Top...@web.de> wrote:

You don't need to do an overlay for this, just put the tikz code in the
table like this: (assuming my example above, put this after the last
\hline)

\multicolumn{2}{C}{\tikz\draw[thick] (0,0) -- (1,0) node[pos=2.75,text
width=3cm] {Legend is here it will wrap};}&
\multicolumn{2}{C}{\tikz\draw[thick,dotted] (0,0) -- (1,0)
node[pos=2.75,text width=3cm] {Second legend};}&
\multicolumn{2}{C}{\tikz\draw[thick,dashed] (0,0) -- (1,0)
node[pos=2.75,text width=3cm] {Third legend};}

Alan

Speedbird80

unread,
Nov 15, 2010, 6:41:59 PM11/15/10
to
On 15 Nov., 00:08, Alan Munn <am...@msu.edu> wrote:
> In article
> <23382fdf-870a-4e66-8d64-ab5f9ffb1...@n30g2000vbb.googlegroups.com>,

Wow, now can continue working with this example!
Thank you very much for your excellent help!

Speedbird80

unread,
Nov 16, 2010, 3:25:40 PM11/16/10
to
Hi Alan

I've done the table so far, but now I have following problems:
-Text in the first line has an unequal space between the first and
second \hilne and not sufficient space between the vertical lines
-The numbers are not centered between the lines
-In the legend there is a strange line brake: "dringende
Geschäftsreise" works but the others not, althought I used the spacing
\-

Can you help me again? Thank you very much!

Best regards
Tom

Here is the code:

\documentclass{article}
\usepackage[latin1]{inputenc}


\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{array}

% create a new column type with some extra height in each cell

\newcolumntype{C}{@{}>{\centering\arraybackslash}m{1.5cm}<{\rule[-2ex]
{0pt}{0ex}\hspace{1cm}}@{}}%
\newcolumntype{S}{@{}>{\centering\arraybackslash}m{1cm}<{\rule[-2ex]
{0pt}{0ex}}@{}}


% create a command to place a tikz node (supply unique node name as
the argument)
\newcommand*{\tknode}[1]{\tikz[remember picture]\node (#1) {};}

\begin{document}

%\setlength{\extrarowheight}{2.5pt}
%\setlength{\tabcolsep}{5pt}
\begin{tabular}{|CC|C|C|C|C|C|C|C|}
\hline
\multicolumn{2}{|S|}{Kunden\-einschätzung} & Sitz\-ver\-füg\-bar\-
keit & Hohe Frequenz & Um\-buch\-ungs\-mög\-lich\-keit & Zwischen\-
stops & Service und Komfort & Schneller Check-In/Check-Out & günstiger
Preis \\
\hline
sehr wichtig & 5 & \tknode{Do1} & & \tknode{Do2} & \tknode{T4} &
\tknode{Do4} & \tknode{Do5} & \tknode{Dl5}\\
\hline
\hfill & 4 & & \tknode{T2} & \tknode{T3} & & \tknode{T5} &
\tknode{T6} & \tknode{Da6}\\
\hline
\hfill & 3 & \tknode{T1} \tknode{Da1} & & \tknode{Da2} & \tknode{Do3}
& \tknode{Da4} & &\\
\hline
\hfill & 2 & & \tknode{Dl2} & & \tknode{Da3} & & \tknode{Da5} &
\tknode{T7} \\
\hline
nicht wichtig & 1 & \tknode{Dl1} & & \tknode{Dl3} & & & \tknode{Dl4}
& \tknode{Do6}\\
\hline


\multicolumn{2}{C}{\tikz\draw[thick,dotted] (0,0) -- (1,0)

node[pos=2.75,text width=3cm] {dringende Geschäfts\-reise};}&


\multicolumn{2}{C}{\tikz\draw[thick] (0,0) -- (1,0) node[pos=2.75,text

width=3cm] {Geschäfts\-reise};}&


\multicolumn{2}{C}{\tikz\draw[thick,dashed] (0,0) -- (1,0)

node[pos=2.75,text width=3cm] {Wochen\-end\-reise};}&
\multicolumn{2}{C}{\tikz\draw[thick,dash pattern=on 10pt off 5pt]
(0,0) -- (1,0) node[pos=2.75,text width=3cm] {Ur\-laubs\-reise};}
\end{tabular}

% now connect up the nodes

\tikz[remember picture, overlay] \draw[thick,dotted] (Do1.center) --
(Do2.center) -- (Do3.center) -- (Do4.center) -- (Do5.center) --
(Do6.center);
\tikz[remember picture, overlay] \draw[thick] (T1.center) --
(T2.center)-- (T3.center) -- (T4.center) -- (T5.center) -- (T6.center)
-- (T7.center);
\tikz[remember picture, overlay] \draw[thick,dashed] (Da1.center) --
(Da2.center)-- (Da3.center) -- (Da4.center) -- (Da5.center) --
(Da6.center);
\tikz[remember picture, overlay] \draw[thick,dash pattern=on 10pt off
5pt] (Dl1.center) -- (Dl2.center)-- (Dl3.center) -- (Dl4.center) --
(Dl5.center);

Speedbird80

unread,
Nov 16, 2010, 3:37:00 PM11/16/10
to
Sorry I forgot the command \end{document}

\documentclass{article}
\usepackage[latin1]{inputenc}

\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{array}

% create a new column type with some extra height in each cell

\newcolumntype{C}{@{}>{\centering\arraybackslash}m{1.5cm}<{\rule[-2ex]
{0pt}{0ex}\hspace{1cm}}@{}}%
\newcolumntype{S}{@{}>{\centering\arraybackslash}m{1cm}<{\rule[-2ex]

{0pt}{0ex}}@{}}


% create a command to place a tikz node (supply unique node name as
the argument)
\newcommand*{\tknode}[1]{\tikz[remember picture]\node (#1) {};}

\begin{document}

%\setlength{\extrarowheight}{2.5pt}


%\setlength{\tabcolsep}{5pt}
\begin{tabular}{|CC|C|C|C|C|C|C|C|}
\hline
\multicolumn{2}{|S|}{Kunden\-einschätzung} & Sitz\-ver\-füg\-bar\-
keit & Hohe Frequenz & Um\-buch\-ungs\-mög\-lich\-keit & Zwischen\-
stops & Service und Komfort & Schneller Check-In/Check-Out & günstiger
Preis \\
\hline
sehr wichtig & 5 & \tknode{Do1} & & \tknode{Do2} & \tknode{T4} &
\tknode{Do4} & \tknode{Do5} & \tknode{Dl5}\\
\hline
\hfill & 4 & & \tknode{T2} & \tknode{T3} & & \tknode{T5} &
\tknode{T6} & \tknode{Da6}\\
\hline
\hfill & 3 & \tknode{T1} \tknode{Da1} & & \tknode{Da2} & \tknode{Do3}
& \tknode{Da4} & &\\
\hline
\hfill & 2 & & \tknode{Dl2} & & \tknode{Da3} & & \tknode{Da5} &
\tknode{T7} \\
\hline
nicht wichtig & 1 & \tknode{Dl1} & & \tknode{Dl3} & & & \tknode{Dl4}
& \tknode{Do6}\\
\hline

\multicolumn{2}{C}{\tikz\draw[thick,dotted] (0,0) -- (1,0)

node[pos=2.75,text width=3cm] {dringende Geschäfts\-reise};}&


\multicolumn{2}{C}{\tikz\draw[thick] (0,0) -- (1,0) node[pos=2.75,text

width=3cm] {Geschäfts\-reise};}&


\multicolumn{2}{C}{\tikz\draw[thick,dashed] (0,0) -- (1,0)

node[pos=2.75,text width=3cm] {Wochen\-end\-reise};}&
\multicolumn{2}{C}{\tikz\draw[thick,dash pattern=on 10pt off 5pt]

(0,0) -- (1,0) node[pos=2.75,text width=3cm] {Ur\-laubs\-reise};}
\end{tabular}

% now connect up the nodes

\tikz[remember picture, overlay] \draw[thick,dotted] (Do1.center) --
(Do2.center) -- (Do3.center) -- (Do4.center) -- (Do5.center) --
(Do6.center);
\tikz[remember picture, overlay] \draw[thick] (T1.center) --
(T2.center)-- (T3.center) -- (T4.center) -- (T5.center) -- (T6.center)
-- (T7.center);
\tikz[remember picture, overlay] \draw[thick,dashed] (Da1.center) --
(Da2.center)-- (Da3.center) -- (Da4.center) -- (Da5.center) --
(Da6.center);
\tikz[remember picture, overlay] \draw[thick,dash pattern=on 10pt off
5pt] (Dl1.center) -- (Dl2.center)-- (Dl3.center) -- (Dl4.center) --
(Dl5.center);

\end{document}

Gonzalo Medina Arellano

unread,
Nov 17, 2010, 12:27:17 PM11/17/10
to
On Nov 12, 12:31 pm, Alan Munn <am...@msu.edu> wrote:
>
> After I sent this, I realized that drawing the table lines would be
> difficult.


Not necessarily; here's your example code with vertical and horizontal
lines:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}
\begin{tikzpicture}
\matrix (A) [%


matrix of nodes, nodes in empty cells,

row sep={1cm,between origins},
text width=2cm,text height=5mm
]


{ColumnA & ColumnB & ColumnC & ColumnD & ColumnF \\
RowA &&&&\\
RowB &&&&\\
RowC &&&&\\
RowD &&&&\\

RowE &&&&\\


};
\draw[thick,dotted] (A-2-2.center) -- (A-4-3.center) --
(A-3-4.center)
-- (A-3-5.center);
\draw[thick] (A-3-2.center) -- (A-2-3.center) -- (A-2-4.center) --
(A-4-5.center);

% horizontal lines of the table
\foreach \i in {1,2,3,4,5,6}
\draw[thin,black] (A-\i-1.north west) -- (A-\i-5.north east);
\draw[thin,black] (A-6-1.south west) -- (A-6-5.south east);
% vertical lines of the table
\foreach \j in {1,2,3,4,5}
\draw[thin,black] (A-1-\j.north west) -- (A-6-\j.south west);
\draw[thin,black] (A-1-5.north east) -- (A-6-5.south east);
\end{tikzpicture}
\end{document}

0 new messages