TeX - LaTeX Asked on March 10, 2021
I am trying to draw a table like the one in the picture below. I’ve been working with tables and tikz but never combined both to draw a table with nodes in it.
What would be the best approach to draw such a table?
I created a minimum working example, which still has some issues.
Any help is appreciated. I can also use other packages if necessary. This was just my first idea.
Code:
documentclass{article}
usepackage{array,multirow,graphicx}
usepackage{tikz}
usetikzlibrary{tikzmark}
begin{document}
begin{table}[h]
centering
begin{tabular}{c|l|cccccc}
Kategorie& multicolumn{1}{c|}{Einflussgroesse} & multicolumn{6}{c}{Auspraegung in Fallstudie}
&&&1&2&3&4&
hline
multirow{4}{*}{rotatebox[origin=c]{90}{parbox[c]{1.5cm}{centering Markt-bezogene }}} & text &gering&&tikzmark{1}&&&hoch
& text &gering&&tikzmark{2}&&&hoch
& text &gering&&&tikzmark{3}&&hoch
& text &gering&&&tikzmark{4}&&hoch
end{tabular}
begin{tikzpicture}[overlay, remember picture]
draw [-] ({pic cs:1}) -- ({pic cs:2});
draw [-] ({pic cs:2}) -- ({pic cs:3});
draw [-] ({pic cs:3}) -- ({pic cs:4});
end{tikzpicture}
end{table}
end{document}
If you put the table inside a tikz matrix of nodes
(see chapter 20 of the tikz/pgf manual), then you will have the full power of tikz
at your disposal. To all intents and purposes a matrix of nodes
looks like a "normal" LaTeX matrix except:
tikzpicture
environment.Here the result of my experimenting with your MWE:
...and here is the code that produced this:
documentclass{article}
usepackage{tikz}
usetikzlibrary{calc,matrix}
newcommandhochscale[1]{%hochscale{a,b,c,d,...}
foreach r in {1,2,3,4} {% put numbers under heading
node at ($ (M-1-3.west)+(r,-0.4) $) {r};
}
% now draw scale in each row
foreach hoch [count=r from 2, remember=r as last] in {#1} {
node[anchor=west] at ($ (M-r-3.west)+(-0.8,0) $) {gering};
node[anchor=east] at ($ (M-r-3.west)+(5.5,0) $) {hoch};
draw (M-r-3.west)+(0.5,0) -- ++(4.5,0);
node[mypoint] (hochr) at ($ (M-r-3.west)+(hoch,0) $) {};
ifnumr>2% draw the lines between scales starting from row 3
draw[blue](hochlast)--(hochr);
fi
}
% add the dashed line
draw[dashed](M-2-3.west)+(2.5,0.5)--($ (M-last-3.west)+(2.5,-0.5) $);
}
begin{document}
begin{tikzpicture}[mypoint/.style={circle, radius=0.5mm, fill=blue}]
matrix (M)[matrix of nodes, nodes in empty cells,
row sep=8mm, column sep=6mm,
row 1/.style = {anchor=center, font=largebfseries, blue,
minimum height=12mm},% to allow for numbers
column 1/.style = {text width=15mm},
column 2/.style = {text width=60mm},
column 3/.style = {text width=60mm},
]{
Kategorie & Einflussgroesse & Auspraegung in Fallstudie
& text 1 &
& text 2 &
& text 3 &
& text 4 &
& text 5 &
};
draw[blue, thick](M-1-1.south west) -- (M-1-3.south east);
node[rotate=90, anchor=east] at (M-3-1) {Markt-bezogene};
hochscale{1,2,3,2,4}% add scales in column 3
end{tikzpicture}
end{document}
A few comments:
(M)
after the matrix
command says that the nodes of the matrix can be referred to as (M-1-1)
, (M-1-2)
, ... and more generally (M-row-col)
, where row
and col
are any row and column indices. You can replace M
with anything you like.hochscale
command prints the scales in column 3. It accepts a comma separated list of the "scale values" after which it does the rest. This command is basically a foreach
statement running over the values. It uses the (M-r-3)
syntax to refer to the node in row r
and column 3. The node positions of the form ($ .... $)
use the tikz calc
library.which is given by a few minor tweaks to the tikz style definitions:
documentclass{article}
usepackage[svgnames]{xcolor}
usepackage{tikz}
usetikzlibrary{calc,matrix}
newcommandhochscale[1]{%hochscale{a,b,c,d,...}
foreach r in {1,2,3,4} {
node at ($ (M-1-3.west)+(r,-0.4) $) {r};
}
foreach hoch [count=r from 2, remember=r as last] in {#1} {
node[anchor=west] at ($ (M-r-3.west)+(-0.8,0) $) {gering};
node[anchor=east] at ($ (M-r-3.west)+(5.5,0) $) {hoch};
draw (M-r-3.west)+(0.5,0) -- ++(4.5,0);
node[mypoint] (hochr) at ($ (M-r-3.west)+(hoch,0) $) {};
ifnumr>2%
draw[Peru](hochlast)--(hochr);
fi
}
draw[dashed](M-2-3.west)+(2.5,0.5)--($ (M-last-3.west)+(2.5,-0.5) $);
}
begin{document}
begin{tikzpicture}[mypoint/.style={circle, radius=0.5mm, draw=Peru, thick, fill=Tan}]
matrix (M)[matrix of nodes, nodes in empty cells,
row sep=2mm, column sep=8mm,
row 1/.style = {anchor=center, font=largebfseries, Peru,
minimum height=12mm},% to allow for numbers
column 1/.style = {text width=15mm},
row 1 column 2/.style = {nodes={fill=white,draw=white},text width=50mm},
column 2/.style = {nodes={rectangle,draw=Peru,fill=PapayaWhip},text width=50mm},
column 3/.style = {text width=60mm},
]{
Kategorie & Einflussgroesse & Auspraegung in Fallstudie
& text 1 &
& text 2 &
& text 3 &
& text 4 &
& text 5 &
};
draw[Sienna, thick](M-1-1.south west) -- (M-1-3.south east);
node[rotate=90, anchor=south] at (M-4-1) {Markt-bezogene};
hochscale{1,2,3,2,4}
end{tikzpicture}
end{document}
Correct answer by user30471 on March 10, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP