Graphics, Figures & Tables ⇒ multirow/multicolumn Cells in tikZ Matrices
multirow/multicolumn Cells in tikZ Matrices
Stefan said: "You could use the anchors of the matrix to place a multicolumn node over the matrix."
I don't understand, how to do it. Stefan, can you give and example and explain better?
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
multirow/multicolumn Cells in tikZ Matrices
A basic structure can be built with the »fit« library to create nodes that surround empty cells in the matrix.
Code: Select all
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit,matrix}
\begin{document}
\begin{tikzpicture}
\matrix (table) [%
matrix of nodes,
nodes in empty cells
] {%
A & B & C & D \\
E & & & G \\
H & I & J & \\
K & L & M & \\
};
\node[fit=(table-2-2)(table-2-3)]{F};
\node[fit=(table-3-4)(table-4-4)]{N};
\end{tikzpicture}
\end{document}
Thorsten
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
multirow/multicolumn Cells in tikZ Matrices
Or it is impossible to do with matrix?
Code: Select all
\documentclass{article}
\usepackage[a3paper]{geometry}
\usepackage[cm]{fullpage}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\usepackage{verbatim}
\usepackage{color}
\usepackage{graphicx}
\usepackage[english]{babel}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,backgrounds,calc, positioning, fit, matrix}
\begin{document}
\definecolor{delicate-color}{HTML}{5CB3FF}
\pagecolor{delicate-color}
\begin{tikzpicture}
%{{{ tikz styles
\tikzset{
header/.style={ellipse, draw=black, top color=white, bottom color=yellow!50,thick, inner sep=3mm, minimum width=10cm, minimum height=2cm, font=\Large\bfseries, text centered, double, anchor=west},
pointer/.style = {signal, signal to=east, anchor=west, text width = 40mm, fill=white, line width=0.4mm},
mnemonic-block/.style={rectangle, anchor=west, inner sep=2mm, text width = 9.6cm, fill=white, line width=0.4mm},
line/.style = {draw, line width=0.3mm},
comment/.style = {rectangle, rounded corners, draw, inner sep=3mm, anchor=west, text width = 8cm, node distance=1.5cm, fill=white, line width=0.4mm},
}
%}}}
\matrix (table) [
matrix of nodes,
nodes in empty cells,
nodes={draw}, row sep=5mm,
column sep = 15mm,minimum width=.875cm, minimum height=1cm,
]
{
& &\\
\node [pointer,yshift=-3cm] (3_1) {read-write / read only}; &
\node [mnemonic-block,yshift=-3cm] (3_2) {\begin{lstlisting}[language=Perl]
has 'attr' => {is => 'rw'}
has 'attr' => {is => 'ro'}
\end{lstlisting}};\\\node [pointer] (4_1) {Accessor methods}; &
\node [mnemonic-block] (4_2) {\begin{lstlisting}[language=Perl]
has 'attr' => {reader => 'get_attr',}
has 'attr' => {writer => 'set_attr',}
\end{lstlisting}};\\\node [pointer] (5_1) {Predicate method}; &
\node [mnemonic-block] (5_2) {\begin{lstlisting}[language=Perl]
has 'attr' => {predicate => 'has_attr'}
\end{lstlisting}
}; &
\node [comment] (5_3) {Tells you whether or not a given attribute is currently set};\\\node [pointer] (6_1) {Cleaner method}; &
\node [mnemonic-block] (6_2) {\begin{lstlisting}[language=Perl]
has 'attr' => {cleaner => 'clean_attr'}
\end{lstlisting}}; &
\node [comment] (6_3) {Unsets the attribute};\\\node [pointer] (7_1) {Required}; &
\node [mnemonic-block] (7_2) {\begin{lstlisting}[language=Perl]
has 'attr' => {required => 1}
\end{lstlisting}};\\\node [pointer] (8_1) {\pgftext[x=1cm] {Lazy}}; &
\node [mnemonic-block] (8_2) {\begin{lstlisting}[language=Perl]
has 'attr' => {lazy => 1}
\end{lstlisting}
}; &
\node [comment] (8_3) {When lazy is true, the default is not generated until the reader method is called};\\\node [pointer] (9_1) {Constructor parameters}; &
\node [mnemonic-block] (9_2) {\begin{lstlisting}[language=Perl]
has 'attr' => {init_arg => 'new_name'}
\end{lstlisting}
}; &
\node [comment] (9_3) {
Use a different name for the constructor parameter for this attribute.
};\\\node [pointer] (10_1) {Weak references}; &
\node [mnemonic-block] (10_2) {\begin{lstlisting}[language=Perl]
has 'attr' => {weak_ref => 1}
\end{lstlisting}
}; &
\node [comment] (10_3) {
If you set the weak\_ref option to a true value, then it will call Scalar::Util::weaken whenever the attribute is set
};\\\node [pointer] (11_1) {Trigger}; &
\node [mnemonic-block] (11_2) {\begin{lstlisting}[language=Perl]
has 'attr' => {trigger => \&attr_set}
\end{lstlisting}
}; &
\node [comment] (11_3) {subroutine that is called whenever the attribute is set};\\\node [pointer] (12_1) {Attribute type}; &
\node [mnemonic-block] (12_2) {\begin{lstlisting}[language=Perl]
has 'attr' => {isa => 'Str',}
has 'attr' => {isa => 'MyApp::Weapon',}
\end{lstlisting}
};\\\node [pointer] (13_1) {Documentation}; &
\node [mnemonic-block] (13_2) {\begin{lstlisting}[language=Perl]
has 'attr' => {documentation => q{Some text}}
\end{lstlisting}
};\\
};
\node [header, align=center, fit=(table-1-1)(table-1-2)(table-1-3)] (1_1) {Moose Attributes};
\draw[line] (3_1.west) --++ (-5mm, 0) |- (4_1.west) --++ (-5mm, 0) |- (5_1.west) --++ (-5mm, 0) |- (6_1.west) --++ (-5mm, 0) |- (7_1.west) --++ (-5mm, 0) |- (8_1.west) --++ (-5mm, 0) |- (9_1.west) --++ (-5mm, 0) |- (10_1.west) --++ (-5mm, 0) |- (11_1.west) --++ (-5mm, 0) |- (12_1.west) --++ (-5mm, 0) |- (13_1.west);\draw[line] (3_1.east) -- (3_2.west);\draw[line] (4_1.east) -- (4_2.west);\draw[line] (5_1.east) -- (5_2.west);\draw[line] (5_2.east) -- (5_3.west);\draw[line] (6_1.east) -- (6_2.west);\draw[line] (6_2.east) -- (6_3.west);\draw[line] (7_1.east) -- (7_2.west);\draw[line] (8_1.east) -- (8_2.west);\draw[line] (8_2.east) -- (8_3.west);\draw[line] (9_1.east) -- (9_2.west);\draw[line] (9_2.east) -- (9_3.west);\draw[line] (10_1.east) -- (10_2.west);\draw[line] (10_2.east) -- (10_3.west);\draw[line] (11_1.east) -- (11_2.west);\draw[line] (11_2.east) -- (11_3.west);\draw[line] (12_1.east) -- (12_2.west);\draw[line] (13_1.east) -- (13_2.west);
\draw[line] (3_1.west) --++ (-5mm, 0) |- (1_1.west);
\end{tikzpicture}
\end{document}
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
multirow/multicolumn Cells in tikZ Matrices
[1] View topic: Centering a node in tikz
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
multirow/multicolumn Cells in tikZ Matrices

But then it will stretch the center column, that I don't want.
And when I tried your solution with fit lib, it gave this:

- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
multirow/multicolumn Cells in tikZ Matrices
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10