From 5e7ed3f53bdf940ec6dc2327ccf586cd540aa9b9 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Tue, 15 Nov 2022 03:01:17 +0000 Subject: CTAN sync 202211150301 --- graphics/pgf/contrib/matrix-skeleton/LICENSE | 2 +- graphics/pgf/contrib/matrix-skeleton/README.md | 1 + graphics/pgf/contrib/matrix-skeleton/example.pdf | Bin 33635 -> 36920 bytes graphics/pgf/contrib/matrix-skeleton/manual.pdf | Bin 114680 -> 0 bytes graphics/pgf/contrib/matrix-skeleton/manual.tex | 397 -------------------- .../contrib/matrix-skeleton/matrix.skeleton.pdf | Bin 0 -> 123712 bytes .../contrib/matrix-skeleton/matrix.skeleton.tex | 402 +++++++++++++++++++++ .../pgflibrarymatrix.skeleton.code.tex | 10 +- .../tikzlibrarymatrix.skeleton.code.tex | 4 + 9 files changed, 416 insertions(+), 400 deletions(-) delete mode 100644 graphics/pgf/contrib/matrix-skeleton/manual.pdf delete mode 100644 graphics/pgf/contrib/matrix-skeleton/manual.tex create mode 100644 graphics/pgf/contrib/matrix-skeleton/matrix.skeleton.pdf create mode 100644 graphics/pgf/contrib/matrix-skeleton/matrix.skeleton.tex (limited to 'graphics') diff --git a/graphics/pgf/contrib/matrix-skeleton/LICENSE b/graphics/pgf/contrib/matrix-skeleton/LICENSE index cf5d56f156..723ab98b28 100644 --- a/graphics/pgf/contrib/matrix-skeleton/LICENSE +++ b/graphics/pgf/contrib/matrix-skeleton/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2013-2019, Nicolas Dudebout +Copyright (c) 2013-2022, Nicolas Dudebout Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. diff --git a/graphics/pgf/contrib/matrix-skeleton/README.md b/graphics/pgf/contrib/matrix-skeleton/README.md index a084f16689..c47acb6d10 100644 --- a/graphics/pgf/contrib/matrix-skeleton/README.md +++ b/graphics/pgf/contrib/matrix-skeleton/README.md @@ -32,3 +32,4 @@ More information and examples are available in [the manual](manual.pdf). Author: Nicolas Dudebout License: ISC +Version: 1.1 diff --git a/graphics/pgf/contrib/matrix-skeleton/example.pdf b/graphics/pgf/contrib/matrix-skeleton/example.pdf index 1bf57b0b62..c1fe53e664 100644 Binary files a/graphics/pgf/contrib/matrix-skeleton/example.pdf and b/graphics/pgf/contrib/matrix-skeleton/example.pdf differ diff --git a/graphics/pgf/contrib/matrix-skeleton/manual.pdf b/graphics/pgf/contrib/matrix-skeleton/manual.pdf deleted file mode 100644 index 878e7af24a..0000000000 Binary files a/graphics/pgf/contrib/matrix-skeleton/manual.pdf and /dev/null differ diff --git a/graphics/pgf/contrib/matrix-skeleton/manual.tex b/graphics/pgf/contrib/matrix-skeleton/manual.tex deleted file mode 100644 index 14ee41c69a..0000000000 --- a/graphics/pgf/contrib/matrix-skeleton/manual.tex +++ /dev/null @@ -1,397 +0,0 @@ -\documentclass{scrartcl} - -\usepackage{tikz} -\usetikzlibrary{matrix.skeleton} - -\usepackage[justification=centering,labelfont={sf,bf,up},labelsep=period,font=small]{caption} -\captionsetup[figure]{position=bottom,singlelinecheck=false} -\usepackage[font=small,justification=centering]{subcaption} -\usepackage{float} -\floatstyle{komabelow} -\restylefloat{figure} - -\usepackage{xspace} - -\usepackage{hyperref} -\hypersetup{ colorlinks=true - , linkcolor=blue!75 - , citecolor=black - , urlcolor=blue!75 - } - -\usepackage[noabbrev, capitalize]{cleveref} - -\tikzset{highlight/.style={draw=#1!75, fill=#1!25, rounded corners=1pt}} -\newcommand\code\texttt -\newcommand{\TikZ}{Ti\textit{k}Z\xspace} - -\title{\texttt{matrix.skeleton}'s Manual} -\author{Nicolas Dudebout} -\date{} - -\begin{document} - -\maketitle - -\section{Introduction} - -The \TikZ \code{matrix} library places nodes on a grid. -However, this grid is discarded after the nodes have been placed. -As a result, certain constructions involving multiple nodes become cumbersome. -The following two examples highlight some of the difficulties. - -\subsection{Alignment Issues with \code{fit}} - -The \code{fit} library is used to highlight a subset of nodes in a matrix. -If all the nodes in the matrix have the same dimension, as in~\cref{fig:highlighting_identical_dimensions}, \code{fit} produces the desired output. - -\begin{figure}[h] -\centering - -\begin{subfigure}{0.45\textwidth} -\centering -\begin{tikzpicture} -\matrix (m) [matrix of math nodes, column sep = 3pt, row sep = 3pt] { -1 & 2 \\ -3 & 4 \\ -5 & 6 \\ -}; -\end{tikzpicture} -\caption{Input matrix} -\end{subfigure} -% -\begin{subfigure}{0.45\textwidth} -\centering -\begin{tikzpicture} -\matrix (m) [matrix of math nodes, column sep = 3pt, row sep = 3pt] { -1 & 2 \\ -3 & 4 \\ -5 & 6 \\ -}; - -\fitandstyle[background]{(m-1-1) (m-2-1)}{highlight = yellow} -\fitandstyle[background]{(m-1-2) (m-2-2)}{highlight = red} -\fitandstyle[background]{(m-3-1) (m-3-2)}{highlight = green} -\end{tikzpicture} -\caption{Desired output and result with \code{fit}} -\end{subfigure} - -\caption{Highlighting in a matrix with nodes of identical dimensions} -\label{fig:highlighting_identical_dimensions} -\end{figure} - -However, if the nodes have different heights and widths, as illustrated in~\cref{fig:highlighting_different_dimensions}, some alignment issues arise. - -\begin{figure}[h] -\centering -\begin{subfigure}{0.3\textwidth} -\centering - -\begin{tikzpicture} -\matrix (m) [matrix of math nodes, column sep = 3pt, row sep = 3pt] { -1 & \frac{\frac{16}{4}}{1 + \frac{2}{2}} \\ -2.999999 & 4 \\ -5 & 6.000001 \\ -}; -\end{tikzpicture} -\caption{Input matrix} -\end{subfigure} -% -\begin{subfigure}{0.3\textwidth} -\centering - -\begin{tikzpicture} -\matrix (m) [matrix of math nodes, column sep = 3pt, row sep = 3pt, label skeleton] { -1 & \frac{\frac{16}{4}}{1 + \frac{2}{2}} \\ -2.999999 & 4 \\ -5 & 6.000001 \\ -}; - -\fitandstyle[background]{(m-cell-1-1) (m-cell-2-1)}{highlight = yellow} -\fitandstyle[background]{(m-cell-1-2) (m-cell-2-2)}{highlight = red} -\fitandstyle[background]{(m-cell-3-1) (m-cell-3-2)}{highlight = green} -\end{tikzpicture} -\caption{Desired output} -\end{subfigure} -% -\begin{subfigure}{0.3\textwidth} -\centering - -\begin{tikzpicture} -\matrix (m) [matrix of math nodes, column sep = 3pt, row sep = 3pt] { -1 & \frac{\frac{16}{4}}{1 + \frac{2}{2}} \\ -2.999999 & 4 \\ -5 & 6.000001 \\ -}; - -\fitandstyle[background]{(m-1-1) (m-2-1)}{highlight = yellow} -\fitandstyle[background]{(m-1-2) (m-2-2)}{highlight = red} -\fitandstyle[background]{(m-3-1) (m-3-2)}{highlight = green} -\end{tikzpicture} -\caption{Result with \code{fit}} -\end{subfigure} - -\caption{Highlighting in a matrix with nodes of different dimensions} -\label{fig:highlighting_different_dimensions} -\end{figure} - -These problems can be addressed using \code{minimum width} and \code{minimum height}. -However, adjusting manually these parameters in every matrix is a waste of time. - -The \code{matrix.skeleton} library provides a clean solution through the use of nodes called~\code{cells}. -These \code{cells} and other skeleton nodes are described in~\cref{sec:skeleton}. - -\subsection{Working with Rows and Columns} - -The readability of a matrix can sometimes be improved by adding a background on every other row. -This simple task is not easily achievable with \code{matrix} alone. -The style \code{every odd column} only affects the nodes of the said columns. -There is no real column object to work with. - -The \code{matrix.skeleton} library provides \TikZ styles to achieve this goal easily. -These styles are described in~\cref{sec:styling} - -\section{Skeleton} -\label{sec:skeleton} - -\subsection{Nodes} - -\code{matrix.skeleton} works by positioning a set of nodes to recreate the \code{matrix} grid. -The eight types of such nodes are illustrated in~\cref{fig:skeleton_nodes}. - -\begin{figure}[h] -\centering -\begin{subfigure}{0.3\textwidth} -\centering -\begin{tikzpicture} -\matrix (m) [draw, matrix of nodes, column sep=10pt, row sep=10pt, label skeleton] { -1 & 2 & 3 \\ -4 & 5 & 6 \\ -7 & 8 & 9 \\ -}; - -\fitandstyle[background]{(m-cell-1-1)}{fill=yellow!30} -\fitandstyle[background]{(m-row-2)}{fill=red!25} -\fitandstyle[background]{(m-column-3)}{fill=green!25, opacity=.75} -\end{tikzpicture} -\caption{\textcolor{yellow!80!orange}{Cell}, \textcolor{red!50}{row}, and \textcolor{green!60}{column}} -\end{subfigure} -% -\begin{subfigure}{0.3\textwidth} -\centering -\begin{tikzpicture} -\matrix (m) [draw, matrix of nodes, column sep=10pt, row sep=10pt, label skeleton] { -1 & 2 & 3 \\ -4 & 5 & 6 \\ -7 & 8 & 9 \\ -}; - -\fitandstyle[background]{(m-inter-row-1)}{fill=red!25} -\fitandstyle[background]{(m-inter-column-2)}{fill=green!25, opacity=.75} -\end{tikzpicture} -\caption{\textcolor{red!50}{Inter-row} and \textcolor{green!60}{inter-column}} -\end{subfigure} -% -\begin{subfigure}{0.3\textwidth} -\centering -\begin{tikzpicture} -\matrix (m) [draw, matrix of nodes, column sep=10pt, row sep=10pt, label skeleton] { -1 & 2 & 3 \\ -4 & 5 & 6 \\ -7 & 8 & 9 \\ -}; -\fitandstyle[background]{(m-tiling-cell-1-1)}{fill=yellow!30} -\fitandstyle[background]{(m-tiling-row-2)}{fill=red!25} -\fitandstyle[background]{(m-tiling-column-3)}{fill=green!25, opacity=.75} -\end{tikzpicture} -\caption{\textcolor{yellow!80!orange}{Tiling cell}, \textcolor{red!50}{tiling row}, and \textcolor{green!60}{tiling column}} -\end{subfigure} -\caption{Skeleton nodes} -\label{fig:skeleton_nodes} -\end{figure} - -\subsection{Using \code{matrix.skeleton}} - -The recommended way of using \code{matrix.skeleton} is through \TikZ. -First, load the library with: -\begin{verbatim} - \usetikzlibrary{matrix.skeleton} -\end{verbatim} -Then add an option to your matrix: -\begin{verbatim} - \matrix (m) [label skeleton] {...}; -\end{verbatim} -This creates a set of nodes that can be used for styling. -For example, the nodes illustrated in~\cref{fig:skeleton_nodes} are named: \code{m-cell-1-1}, \code{m-row-2}, \code{m-column-3}, \code{m-inter-row-1}, \code{m-inter-column-2}, \code{m-tiling-cell-1}, \code{m-tiling-row-2}, and \code{m-tiling-column-3}. - -\section{Styling} -\label{sec:styling} - -The skeleton nodes are PGF nodes not meant to be styled. -Styles should be applied to nodes whose shapes depend on the skeleton ones. - -\subsection{Macros} - -Styling in \code{matrix.skeleton} is done with the~\code{fit} library. -The following macro creates a \code{fit} node with the specified style: -\begin{verbatim} - \fitandstyle{(m-cell-1-1) (m-cell-2-2)}{draw=red}; -\end{verbatim} - -It takes an optional argument to place the node in a \code{pgfonlayer} environment: -\begin{verbatim} - \fitandstyle[background]{(m-cell-1-1) (m-cell-2-2)}{fill=red}; -\end{verbatim} - -\subsection{\TikZ \code{matrix} Options} - -Common styling options are also provided as \TikZ options. -These options call~\code{label skeleton} before styling the appropriate nodes. -They take the following form: -\begin{verbatim} - \matrix (m) [style odd rows = {draw=red}] {...}; -\end{verbatim} - -\begin{verbatim} - \matrix (m) [style odd tiling rows = {draw=red}] {...}; -\end{verbatim} - -\begin{verbatim} - \matrix (m) [style grid = {draw}] {...}; -\end{verbatim} - -\begin{verbatim} - \matrix (m) [style tiling grid = {draw}] {...}; -\end{verbatim} - -All of these options have an \code{on layer} variant taking the following form: -\begin{verbatim} - \matrix (m) [style odd rows on layer = {background}{fill=red}] {...}; -\end{verbatim} - -\section{Examples} - -The following examples illustrate the styling capabilities offered by \code{matrix.skeleton}. - -\subsection{Grid} - -\begin{figure}[h] -\centering -\begin{tikzpicture} -\matrix (m) [matrix of math nodes, style contour = {draw, very thick}, style grid = {draw, thin}] { -1 & \frac{\frac{16}{4}}{1 + \frac{2}{2}} & 3 \\ -3.999999 & 5 & 6 \\ -7 & 8.000001 & 3 + 3 + 3 \\ -}; -\end{tikzpicture} -\end{figure} - -\begin{verbatim} -\begin{tikzpicture} -\matrix (m) [matrix of math nodes, style contour = {draw, very thick}, - style grid = {draw, thin}] { -1 & \frac{\frac{16}{4}}{1 + \frac{2}{2}} & 3 \\ -3.999999 & 5 & 6 \\ -7 & 8.000001 & 3 + 3 + 3 \\ -}; -\end{tikzpicture} -\end{verbatim} - -\subsection{Rows} - -\begin{figure}[h] -\centering -\begin{tikzpicture} -\matrix (m) [matrix of math nodes, row sep = 10pt, style odd rows on layer={background}{fill=green!25}, style even rows on layer={background}{fill=yellow!30}] { -1 & \frac{\frac{16}{4}}{1 + \frac{2}{2}} & 3 \\ -3.999999 & 5 & 6 \\ -7 & 8.000001 & 3 + 3 + 3 \\ -}; - -\fitandstyle{(m-inter-row-1)}{fill=red!25} -\fitandstyle{(m-inter-row-2)}{fill=red!25} -\end{tikzpicture} -\end{figure} - -\begin{verbatim} -\begin{tikzpicture} -\matrix (m) [matrix of math nodes, row sep = 10pt, - style odd rows on layer={background}{fill=green!25}, - style even rows on layer={background}{fill=yellow!30}] { -1 & \frac{\frac{16}{4}}{1 + \frac{2}{2}} & 3 \\ -3.999999 & 5 & 6 \\ -7 & 8.000001 & 3 + 3 + 3 \\ -}; - -\fitandstyle{(m-inter-row-1)}{fill=red!25} -\fitandstyle{(m-inter-row-2)}{fill=red!25} -\end{tikzpicture} -\end{verbatim} - -\subsection{Checker Board} - -This example is inspired by the following \href{http://tex.stackexchange.com}{\TeX{} - \LaTeX{} Stack Exchange} question: \href{http://tex.stackexchange.com/questions/14061/how-can-i-set-the-background-color-of-the-rows-and-columns-of-a-matrix-node-in-t}{How can I set the background color of the rows and columns of a matrix node in Tikz?} - -\begin{figure}[h] -\centering -\begin{tikzpicture} -\matrix (m) [draw, matrix of nodes, row sep=2mm, column sep=1mm, nodes={draw, thick, circle, inner sep=1pt}, label skeleton] { - & 1 & &[2mm]|[gray]|1\\ - & & 2 &|[gray]|2\\ - |[gray]|2 & & &|[gray]|2\\[4mm] - 3 & & & 3\\ -}; -\foreach \row in {1, ..., 4} { - \foreach \col in {1, ..., 4} { - \pgfmathparse{Mod(\row + \col, 2) ? "red!25" : "yellow!30"} - \colorlet{squarebg}{\pgfmathresult} - \fitandstyle[background]{(m-tiling-cell-\row-\col)}{fill = squarebg} - } -} -\end{tikzpicture} -\end{figure} - -\newpage - -\begin{verbatim} -\begin{tikzpicture} -\matrix (m) [draw, matrix of nodes, row sep=2mm, column sep=1mm, - nodes={draw, thick, circle, inner sep=1pt}, label skeleton] { - & 1 & &[2mm]|[gray]|1\\ - & & 2 &|[gray]|2\\ - |[gray]|2 & & &|[gray]|2\\[4mm] - 3 & & & 3\\ -}; -\foreach \row in {1, ..., 4} { - \foreach \col in {1, ..., 4} { - \pgfmathparse{Mod(\row + \col, 2) ? "red!25" : "yellow!30"} - \colorlet{squarebg}{\pgfmathresult} - \fitandstyle[background]{(m-tiling-cell-\row-\col)}{fill = squarebg} - } -} -\end{tikzpicture} -\end{verbatim} - -\section{Internals} - -\code{matrix.skeleton} was heavily inspired by \href{http://tex.stackexchange.com/users/86/andrew-stacey}{Andrew Stacey}'s \code{matrixcells} \LaTeX{} package. -It has three distinctive features. -First, it works with any \code{anchor}. -Second, it provides finer control with respect to \code{row sep}, \code{column sep}, and \code{inner sep}. -Third, the skeleton node positioning relies only on \TeX{} and PGF, not on \LaTeX{} or \TikZ. - -\code{matrixcells} properly aligns its \code{cells} when the node \code{anchor} is \code{base}. -However, when the alignment is different it runs into problems, as exposed in the following \href{http://tex.stackexchange.com}{\TeX{} - \LaTeX{} Stack Exchange} question: \href{http://tex.stackexchange.com/questions/128045/matrixcells-problem-with-the-y-axis-only}{Matrixcells problem with the y-axis only}. -This shortcoming is the result of some loss of information in \code{pgfmodulematrix.code.tex}. -A dimension used during the placement of nodes is overwritten. -Therefore, this information is not available to build the grid. -In \code{matrixcells}, this lost dimension is reconstructed as the average of two other dimensions. -This method only gives the right dimension when the nodes are anchored at \code{base}. -To always get proper alignment, the~\code{pgfmodulematrix.code.tex} macro erasing the dimension was rewritten. -Following \href{http://tex.stackexchange.com/users/3235/percusse}{\code{@percusse}}'s recommendation this change is transparent to the user and does not require updating PGF/\TikZ. - -\code{matrixcells} only provides \code{cells} corresponding the \code{tiling-cells} in \code{matrix.skeleton}. -This tiling behavior is sometimes desired. -However, it can result in unexpected behaviors when: using a non-base \code{anchor}, using \code{row sep} or \code{column sep}, or when working on boundary nodes. - -\end{document} diff --git a/graphics/pgf/contrib/matrix-skeleton/matrix.skeleton.pdf b/graphics/pgf/contrib/matrix-skeleton/matrix.skeleton.pdf new file mode 100644 index 0000000000..66aca09bc7 Binary files /dev/null and b/graphics/pgf/contrib/matrix-skeleton/matrix.skeleton.pdf differ diff --git a/graphics/pgf/contrib/matrix-skeleton/matrix.skeleton.tex b/graphics/pgf/contrib/matrix-skeleton/matrix.skeleton.tex new file mode 100644 index 0000000000..52748e7583 --- /dev/null +++ b/graphics/pgf/contrib/matrix-skeleton/matrix.skeleton.tex @@ -0,0 +1,402 @@ +\documentclass{scrartcl} + +\usepackage{tikz} +\usetikzlibrary{matrix.skeleton} +\usetikzlibrary{positioning} + +\usepackage[justification=centering,labelfont={sf,bf,up},labelsep=period,font=small]{caption} +\captionsetup[figure]{position=bottom,singlelinecheck=false} +\usepackage[font=small,justification=centering]{subcaption} +\usepackage{float} +\floatstyle{komabelow} +\restylefloat{figure} + +\usepackage{xspace} + +\usepackage{hyperref} +\hypersetup{ colorlinks=true + , linkcolor=blue!75 + , citecolor=black + , urlcolor=blue!75 + } + +\usepackage[noabbrev, capitalize]{cleveref} + +\tikzset{highlight/.style={draw=#1!75, fill=#1!25, rounded corners=1pt}} +\newcommand\code\texttt +\newcommand{\TikZ}{Ti\textit{k}Z\xspace} + +\title{\texttt{matrix.skeleton}'s Manual} +\author{Nicolas Dudebout} +\date{Version \versionnumber} + +\begin{document} + +\maketitle + +\section{Introduction} + +The \TikZ \code{matrix} library places nodes on a grid. +However, this grid is discarded after the nodes have been placed. +As a result, certain constructions involving multiple nodes become cumbersome. +The following two examples highlight some of the difficulties. + +\subsection{Alignment Issues with \code{fit}} + +The \code{fit} library is used to highlight a subset of nodes in a matrix. +If all the nodes in the matrix have the same dimension, as in~\cref{fig:highlighting_identical_dimensions}, \code{fit} produces the desired output. + +\begin{figure}[h] +\centering + +\begin{subfigure}{0.45\textwidth} +\centering +\begin{tikzpicture} +\matrix (m) [matrix of math nodes, column sep = 3pt, row sep = 3pt] { +1 & 2 \\ +3 & 4 \\ +5 & 6 \\ +}; +\end{tikzpicture} +\caption{Input matrix} +\end{subfigure} +% +\begin{subfigure}{0.45\textwidth} +\centering +\begin{tikzpicture} +\matrix (m) [matrix of math nodes, column sep = 3pt, row sep = 3pt] { +1 & 2 \\ +3 & 4 \\ +5 & 6 \\ +}; + +\fitandstyle[background]{(m-1-1) (m-2-1)}{highlight = yellow} +\fitandstyle[background]{(m-1-2) (m-2-2)}{highlight = red} +\fitandstyle[background]{(m-3-1) (m-3-2)}{highlight = green} +\end{tikzpicture} +\caption{Desired output and result with \code{fit}} +\end{subfigure} + +\caption{Highlighting in a matrix with nodes of identical dimensions} +\label{fig:highlighting_identical_dimensions} +\end{figure} + +However, if the nodes have different heights and widths, as illustrated in~\cref{fig:highlighting_different_dimensions}, some alignment issues arise. + +\begin{figure}[h] +\centering +\begin{subfigure}{0.3\textwidth} +\centering + +\begin{tikzpicture} +\matrix (m) [matrix of math nodes, column sep = 3pt, row sep = 3pt] { +1 & \frac{\frac{16}{4}}{1 + \frac{2}{2}} \\ +2.999999 & 4 \\ +5 & 6.000001 \\ +}; +\end{tikzpicture} +\caption{Input matrix} +\end{subfigure} +% +\begin{subfigure}{0.3\textwidth} +\centering + +\begin{tikzpicture} +\matrix (m) [matrix of math nodes, column sep = 3pt, row sep = 3pt, label skeleton] { +1 & \frac{\frac{16}{4}}{1 + \frac{2}{2}} \\ +2.999999 & 4 \\ +5 & 6.000001 \\ +}; + +\fitandstyle[background]{(m-cell-1-1) (m-cell-2-1)}{highlight = yellow} +\fitandstyle[background]{(m-cell-1-2) (m-cell-2-2)}{highlight = red} +\fitandstyle[background]{(m-cell-3-1) (m-cell-3-2)}{highlight = green} +\end{tikzpicture} +\caption{Desired output} +\end{subfigure} +% +\begin{subfigure}{0.3\textwidth} +\centering + +\begin{tikzpicture} +\matrix (m) [matrix of math nodes, column sep = 3pt, row sep = 3pt] { +1 & \frac{\frac{16}{4}}{1 + \frac{2}{2}} \\ +2.999999 & 4 \\ +5 & 6.000001 \\ +}; + +\fitandstyle[background]{(m-1-1) (m-2-1)}{highlight = yellow} +\fitandstyle[background]{(m-1-2) (m-2-2)}{highlight = red} +\fitandstyle[background]{(m-3-1) (m-3-2)}{highlight = green} +\end{tikzpicture} +\caption{Result with \code{fit}} +\end{subfigure} + +\caption{Highlighting in a matrix with nodes of different dimensions} +\label{fig:highlighting_different_dimensions} +\end{figure} + +These problems can be addressed using \code{minimum width} and \code{minimum height}. +However, adjusting manually these parameters in every matrix is a waste of time. + +The \code{matrix.skeleton} library provides a clean solution through the use of nodes called~\code{cells}. +These \code{cells} and other skeleton nodes are described in~\cref{sec:skeleton}. + +\subsection{Working with Rows and Columns} + +The readability of a matrix can sometimes be improved by adding a background on every other row. +This simple task is not easily achievable with \code{matrix} alone. +The style \code{every odd column} only affects the nodes of the said columns. +There is no real column object to work with. + +The \code{matrix.skeleton} library provides \TikZ styles to achieve this goal easily. +These styles are described in~\cref{sec:styling} + +\section{Skeleton} +\label{sec:skeleton} + +\subsection{Nodes} + +\code{matrix.skeleton} works by positioning a set of nodes to recreate the \code{matrix} grid. +The eight types of such nodes are illustrated in~\cref{fig:skeleton_nodes}. + +\begin{figure}[h] +\centering +\begin{subfigure}{0.3\textwidth} +\centering +\begin{tikzpicture} +\matrix (m) [draw, matrix of nodes, column sep=10pt, row sep=10pt, label skeleton] { +1 & 2 & 3 \\ +4 & 5 & 6 \\ +7 & 8 & 9 \\ +}; + +\fitandstyle[background]{(m-cell-1-1)}{fill=yellow!30} +\fitandstyle[background]{(m-row-2)}{fill=red!25} +\fitandstyle[background]{(m-column-3)}{fill=green!25, opacity=.75} +\end{tikzpicture} +\caption{\textcolor{yellow!80!orange}{Cell}, \textcolor{red!50}{row}, and \textcolor{green!60}{column}} +\end{subfigure} +% +\begin{subfigure}{0.3\textwidth} +\centering +\begin{tikzpicture} +\matrix (m) [draw, matrix of nodes, column sep=10pt, row sep=10pt, label skeleton] { +1 & 2 & 3 \\ +4 & 5 & 6 \\ +7 & 8 & 9 \\ +}; + +\fitandstyle[background]{(m-inter-row-1)}{fill=red!25} +\fitandstyle[background]{(m-inter-column-2)}{fill=green!25, opacity=.75} +\end{tikzpicture} +\caption{\textcolor{red!50}{Inter-row} and \textcolor{green!60}{inter-column}} +\end{subfigure} +% +\begin{subfigure}{0.3\textwidth} +\centering +\begin{tikzpicture} +\matrix (m) [draw, matrix of nodes, column sep=10pt, row sep=10pt, label skeleton] { +1 & 2 & 3 \\ +4 & 5 & 6 \\ +7 & 8 & 9 \\ +}; +\fitandstyle[background]{(m-tiling-cell-1-1)}{fill=yellow!30} +\fitandstyle[background]{(m-tiling-row-2)}{fill=red!25} +\fitandstyle[background]{(m-tiling-column-3)}{fill=green!25, opacity=.75} +\end{tikzpicture} +\caption{\textcolor{yellow!80!orange}{Tiling cell}, \textcolor{red!50}{tiling row}, and \textcolor{green!60}{tiling column}} +\end{subfigure} +\caption{Skeleton nodes} +\label{fig:skeleton_nodes} +\end{figure} + +\subsection{Using \code{matrix.skeleton}} + +The recommended way of using \code{matrix.skeleton} is through \TikZ. +First, load the library with: +\begin{verbatim} + \usetikzlibrary{matrix.skeleton} +\end{verbatim} +Then add an option to your matrix: +\begin{verbatim} + \matrix (m) [label skeleton] {...}; +\end{verbatim} +This creates a set of nodes that can be used for styling. +For example, the nodes illustrated in~\cref{fig:skeleton_nodes} are named: \code{m-cell-1-1}, \code{m-row-2}, \code{m-column-3}, \code{m-inter-row-1}, \code{m-inter-column-2}, \code{m-tiling-cell-1}, \code{m-tiling-row-2}, and \code{m-tiling-column-3}. + +\section{Styling} +\label{sec:styling} + +The skeleton nodes are PGF nodes not meant to be styled. +Styles should be applied to nodes whose shapes depend on the skeleton ones. + +\subsection{Macros} + +Styling in \code{matrix.skeleton} is done with the~\code{fit} library. +The following macro creates a \code{fit} node with the specified style: +\begin{verbatim} + \fitandstyle{(m-cell-1-1) (m-cell-2-2)}{draw=red}; +\end{verbatim} + +It takes an optional argument to place the node in a \code{pgfonlayer} environment: +\begin{verbatim} + \fitandstyle[background]{(m-cell-1-1) (m-cell-2-2)}{fill=red}; +\end{verbatim} + +\subsection{\TikZ \code{matrix} Options} + +Common styling options are also provided as \TikZ options. +These options call~\code{label skeleton} before styling the appropriate nodes. +They take the following form: +\begin{verbatim} + \matrix (m) [style odd rows = {draw=red}] {...}; +\end{verbatim} + +\begin{verbatim} + \matrix (m) [style odd tiling rows = {draw=red}] {...}; +\end{verbatim} + +\begin{verbatim} + \matrix (m) [style grid = {draw}] {...}; +\end{verbatim} + +\begin{verbatim} + \matrix (m) [style tiling grid = {draw}] {...}; +\end{verbatim} + +All of these options have an \code{on layer} variant taking the following form: +\begin{verbatim} + \matrix (m) [style odd rows on layer = {background}{fill=red}] {...}; +\end{verbatim} + +\section{Examples} + +The following examples illustrate the styling capabilities offered by \code{matrix.skeleton}. + +\subsection{Grid} + +\begin{figure}[h] +\centering +\begin{tikzpicture} +\matrix (m) [matrix of math nodes, style contour = {draw, very thick}, style grid = {draw, thin}] { +1 & \frac{\frac{16}{4}}{1 + \frac{2}{2}} & 3 \\ +3.999999 & 5 & 6 \\ +7 & 8.000001 & 3 + 3 + 3 \\ +}; +\end{tikzpicture} +\end{figure} + +\begin{verbatim} +\begin{tikzpicture} +\matrix (m) [matrix of math nodes, style contour = {draw, very thick}, + style grid = {draw, thin}] { +1 & \frac{\frac{16}{4}}{1 + \frac{2}{2}} & 3 \\ +3.999999 & 5 & 6 \\ +7 & 8.000001 & 3 + 3 + 3 \\ +}; +\end{tikzpicture} +\end{verbatim} + +\subsection{Rows} + +\begin{figure}[h] +\centering +\begin{tikzpicture} +\matrix (m) [matrix of math nodes, row sep = 10pt, style odd rows on layer={background}{fill=green!25}, style even rows on layer={background}{fill=yellow!30}] { +1 & \frac{\frac{16}{4}}{1 + \frac{2}{2}} & 3 \\ +3.999999 & 5 & 6 \\ +7 & 8.000001 & 3 + 3 + 3 \\ +}; + +\fitandstyle{(m-inter-row-1)}{fill=red!25} +\fitandstyle{(m-inter-row-2)}{fill=red!25} +\end{tikzpicture} +\end{figure} + +\begin{verbatim} +\begin{tikzpicture} +\matrix (m) [matrix of math nodes, row sep = 10pt, + style odd rows on layer={background}{fill=green!25}, + style even rows on layer={background}{fill=yellow!30}] { +1 & \frac{\frac{16}{4}}{1 + \frac{2}{2}} & 3 \\ +3.999999 & 5 & 6 \\ +7 & 8.000001 & 3 + 3 + 3 \\ +}; + +\fitandstyle{(m-inter-row-1)}{fill=red!25} +\fitandstyle{(m-inter-row-2)}{fill=red!25} +\end{tikzpicture} +\end{verbatim} + +\subsection{Checker Board} + +This example is inspired by the following \href{http://tex.stackexchange.com}{\TeX{} - \LaTeX{} Stack Exchange} question: \href{http://tex.stackexchange.com/questions/14061/how-can-i-set-the-background-color-of-the-rows-and-columns-of-a-matrix-node-in-t}{How can I set the background color of the rows and columns of a matrix node in Tikz?} + +\begin{figure}[h] +\centering +\begin{tikzpicture} +\matrix (m) [draw, matrix of nodes, row sep=2mm, column sep=1mm, nodes={draw, thick, circle, inner sep=1pt}, label skeleton] { + & 1 & &[2mm]|[gray]|1\\ + & & 2 &|[gray]|2\\ + |[gray]|2 & & &|[gray]|2\\[4mm] + 3 & & & 3\\ +}; +\foreach \row in {1, ..., 4} { + \foreach \col in {1, ..., 4} { + \pgfmathparse{Mod(\row + \col, 2) ? "red!25" : "yellow!30"} + \colorlet{squarebg}{\pgfmathresult} + \fitandstyle[background]{(m-tiling-cell-\row-\col)}{fill = squarebg} + } +} +\end{tikzpicture} +\end{figure} + +\newpage + +\begin{verbatim} +\begin{tikzpicture} +\matrix (m) [draw, matrix of nodes, row sep=2mm, column sep=1mm, + nodes={draw, thick, circle, inner sep=1pt}, label skeleton] { + & 1 & &[2mm]|[gray]|1\\ + & & 2 &|[gray]|2\\ + |[gray]|2 & & &|[gray]|2\\[4mm] + 3 & & & 3\\ +}; +\foreach \row in {1, ..., 4} { + \foreach \col in {1, ..., 4} { + \pgfmathparse{Mod(\row + \col, 2) ? "red!25" : "yellow!30"} + \colorlet{squarebg}{\pgfmathresult} + \fitandstyle[background]{(m-tiling-cell-\row-\col)}{fill = squarebg} + } +} +\end{tikzpicture} +\end{verbatim} + +\section{Internals} + +\code{matrix.skeleton} was heavily inspired by \href{http://tex.stackexchange.com/users/86/andrew-stacey}{Andrew Stacey}'s \code{matrixcells} \LaTeX{} package. +It has three distinctive features. +First, it works with any \code{anchor}. +Second, it provides finer control with respect to \code{row sep}, \code{column sep}, and \code{inner sep}. +Third, the skeleton node positioning relies only on \TeX{} and PGF, not on \LaTeX{} or \TikZ. + +\code{matrixcells} properly aligns its \code{cells} when the node \code{anchor} is \code{base}. +However, when the alignment is different it runs into problems, as exposed in the following \href{http://tex.stackexchange.com}{\TeX{} - \LaTeX{} Stack Exchange} question: \href{http://tex.stackexchange.com/questions/128045/matrixcells-problem-with-the-y-axis-only}{Matrixcells problem with the y-axis only}. +This shortcoming is the result of some loss of information in \code{pgfmodulematrix.code.tex}. +A dimension used during the placement of nodes is overwritten. +Therefore, this information is not available to build the grid. +In \code{matrixcells}, this lost dimension is reconstructed as the average of two other dimensions. +This method only gives the right dimension when the nodes are anchored at \code{base}. +To always get proper alignment, the~\code{pgfmodulematrix.code.tex} macro erasing the dimension was rewritten. +Following \href{http://tex.stackexchange.com/users/3235/percusse}{\code{@percusse}}'s recommendation this change is transparent to the user and does not require updating PGF/\TikZ. + +\code{matrixcells} only provides \code{cells} corresponding the \code{tiling-cells} in \code{matrix.skeleton}. +This tiling behavior is sometimes desired. +However, it can result in unexpected behaviors when: using a non-base \code{anchor}, using \code{row sep} or \code{column sep}, or when working on boundary nodes. + +\section{Acknowledgments} + +Onur Tolga Şehitoğlu implemented support for multiple matrices. + +\end{document} diff --git a/graphics/pgf/contrib/matrix-skeleton/pgflibrarymatrix.skeleton.code.tex b/graphics/pgf/contrib/matrix-skeleton/pgflibrarymatrix.skeleton.code.tex index b031338eb3..4dd0462e8e 100644 --- a/graphics/pgf/contrib/matrix-skeleton/pgflibrarymatrix.skeleton.code.tex +++ b/graphics/pgf/contrib/matrix-skeleton/pgflibrarymatrix.skeleton.code.tex @@ -1,3 +1,7 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% matrix.skeleton, version 1.1 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + \usepgfmodule{matrix} \def\pgfmatrixlabelskeleton{ @@ -16,8 +20,10 @@ \xdef\pgf@matrix@skel@innerxsep{\pgfkeysvalueof{/pgf/inner xsep}}% \xdef\pgf@matrix@skel@innerysep{\pgfkeysvalueof{/pgf/inner ysep}}% \pgfscope% - \pgfgetlastxy\ck@shift@x\ck@shift@y - \pgftransformshift{\pgfpoint{\ck@shift@x}{\ck@shift@y}}% + \pgf@process{\pgfpointanchor{\tikz@fig@name}{south west}}% + \pgfmathsetlength\pgf@xa{\pgf@x + \pgf@matrix@skel@innerxsep}% + \pgfmathsetlength\pgf@ya{\pgf@y + \pgf@matrix@skel@innerysep - \csname pgf@matrix@miny\the\pgfmatrixcurrentrow\endcsname - \pgfmatrixrowsep}% + \pgftransformshift{\pgfpoint{\pgf@xa}{\pgf@ya}}% \pgfset{inner sep=0pt}% \pgf@matrix@skeleton@create@cells% \pgf@matrix@skeleton@create@tiling@cells% diff --git a/graphics/pgf/contrib/matrix-skeleton/tikzlibrarymatrix.skeleton.code.tex b/graphics/pgf/contrib/matrix-skeleton/tikzlibrarymatrix.skeleton.code.tex index 8f342e8ae7..25b9df6549 100644 --- a/graphics/pgf/contrib/matrix-skeleton/tikzlibrarymatrix.skeleton.code.tex +++ b/graphics/pgf/contrib/matrix-skeleton/tikzlibrarymatrix.skeleton.code.tex @@ -1,3 +1,7 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% matrix.skeleton, version 1.1 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + \usepgflibrary{matrix.skeleton} \usetikzlibrary{matrix} -- cgit v1.2.3