-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Let matrix styles for specific column overwrite styles for even/odd column #867
Comments
Sorry, rejected. Changing the order will silently break existing pictures. You'll have to live with the current situation. |
I know this is a breaking change but couldn't this be enabled through a boolean option to the matrix or implemented in a future breaking version? |
There will be no future breaking version. I have implemented a mechanism to configure the order of these styles, but I will not change the default. It looks pretty sketchy and definitely does not help with the cargo-cultyness of LaTeX, but I couldn't come up with a better configurable way for this. \documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix [
matrix of nodes,
matrix/inner style order={
every cell,
even odd column,
even odd row,
column,
row,
cell
},
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
nodes={draw, anchor=center, minimum size=.75cm},
every odd row/.style={nodes={fill=yellow!10}},
column 6/.style={column sep=5pt},
column 7/.style={nodes={fill=green!10, font=\bfseries}},
row 5/.style={row sep=5pt},
row 6/.style={nodes={fill=green!10, font=\bfseries}}
] {
1 & 1 & 1 & 0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 & 1 & 1 & 1 \\
0 & 1 & 0 & 1 & 1 & 0 & 1 \\
0 & 1 & 1 & 0 & 0 & 0 & 0 \\
1 & 0 & 1 & 1 & 0 & 1 & 0 \\
0 & 1 & 0 & 0 & 1 & 0 & \\
};
\end{tikzpicture}
\end{document} |
Okay thank you very much. This honestly seems like a great solution. Personally I wouldn't mind a breaking version but I can see why you choose to go this route. |
I've changed it a little bit so that you don't have to fully qualify the default styles. You can also install your own (which you then do have to fully quality). \tikzset{
my style/.code={%
\ifnum\pgfmatrixcurrentcolumn=2
\tikzset{font=\itshape}%
\fi
},
matrix/inner style order={
every cell,
even odd column,
even odd row,
column,
row,
cell,
/tikz/my style
}
} |
Would you consider this as fixed, even though I rejected your original request to change the default order? |
Yes I consider this as fixed. You may go ahead and close this |
Awesome. Thank you for that. But I agree with septatrix, that it would be even better to make this proposal the new default. I would consider the current default being a bug (and/or bad design decision). One could add a "Note" to the manual that this was changed in v3.x and also state the old order, so it would be quite easy to restore the old behavior if someone really relied on that "bug". If you still decide to stick to the current implementation I'll suggest to add a new label Two more notes to your additions:
|
Sorry, no way I'm breaking old documents. I'm trying to only break with default behaviour where it was previously an error, but that is not the case here. |
I agree that changing the default behaviour can't be classified as a bug fix and therefore shall not be done in a minor release. Instead I very much like the addition of an extra option which furthermore also allows one to let column styles overwrite row styles etc. However I would also like to support @Mo-Gul's suggestion that should there be a new major version changing the default order is something you may reconsider. I have yet to find a matrix drawing which would get broken by this change as the majority either does not need per column styles or uses the workaround to achieve the order I propose at that is what most people expect/want. Sadly however TeX does not allow package selection using semver though maybe an option similar to |
I am definitely not going to maintain a compatibility layer for PGF. That is way too much work. Also, unless Till returns, there will be no further major version of PGF. The current status is maintenance, not development. And furthermore I absolutely do not care whether your documents work fine with a breaking change, because after all I am not maintaining PGF specifically for you. |
@septatrix, you wrote
I am not sure if I have understood that right. But with the new implementation you can overwrite row styles by column styles with (e.g.) matrix/inner style order={
every cell,
even odd row,
even odd column,
row,
column,
this cell,
}, |
Yes I know. That is why I like this option :D |
@hmenke , I thought that will not change your mind, and that is totally fine. I also agree that a compatibility layer for PGF would be (let's call it positive) "challenging". But maybe you could consider my suggestions for the manual. So the only point left is the label for v4. One never knows what future brings. Not that far in the past I guess not many people were thinking any more that PGF will improve that much in the near future. But then you came around the corner and did all the great stuff !! So I'll try to be optimistic for the future as well and I guess the label will not hurt anybody. So I'll add it in a second ... |
GitHub has Milestones for this kind of stuff. I've opened a new, generic issue for that because this one is already closed. |
@Mo-Gul All these things can be trivially achieved already. You only need to add something along the lines of the first part of https://tex.stackexchange.com/a/546401/194703. It is way more powerful than the reordering of a handful of styles IHMO. If anything I'd add a key similarly to |
There is some logic to this actually. Suppose you want to generate tables via tikz matrices (as an example I wrote this some years ago https://tex.stackexchange.com/a/67736). To be able to override the striping pattern as the whole column the default order makes quite some sense (i'm doing some nested styles but nevermind that. Those were the crazy times). Otherwise you have to walk through every stripe to override the settings. Thus this actually takes us out of the latex table hell as you can perform fine surgery per column. Especially if you need funky styles per column. But I understand that this makes simple stripe override not-extremely-simple. Also notice that these are not content styles but cell styles. You can always override individual cells and much easily by appending to |
I haven't been TikZing for years now but for your particular example I'd go about it as the following for minimal low levelness and maximum lazyness. \documentclass[tikz]{standalone}
\usetikzlibrary{matrix}
\tikzset{
foreach col/.append style={
column #1/.style={every odd row/.style={nodes={fill=yellow!10}}}
}
}
\begin{document}
\begin{tikzpicture}
\matrix [
matrix of nodes,
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
nodes={draw, anchor=center, minimum size=.75cm},
foreach col/.list={1,2,3,4,5,6},
column 6/.append style={column sep=5pt},
column 7/.style={nodes={fill=green!10, font=\bfseries}},
row 5/.style={row sep=5pt},
row 6/.style={nodes={fill=green!10, font=\bfseries}}
] {
1 & 1 & 1 & 0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 & 1 & 1 & 1 \\
0 & 1 & 0 & 1 & 1 & 0 & 1 \\
0 & 1 & 1 & 0 & 0 & 0 & 0 \\
1 & 0 & 1 & 1 & 0 & 1 & 0 \\
0 & 1 & 0 & 0 & 1 & 0 & \\
};
\end{tikzpicture}
\end{document} |
@tallmarmot, "trivial" is very "subjective" I would say. What might be trivial to you can be impossible to come up with for me (as a lot of your TeX.SX answers are for me). And of there might be people who are even (way) below my level. So my point only is that it could be confusing to find examples in the manual which might offer new possibilities but could be done with the shown keys. Then I would expect a note that this is an alternative. And if it is not, I (personally) would see an example that shows me something new. Feel free to choose an example yourself and a way of showing this new feature. I would do it myself, but unfortunately currently my level is too low for that. Now coming back to your "wish". Also there I don't understand everything because it is above my level. But at least it sounds like a new feature. If I am right, then you should/could open a new issue for that. |
@ilayn, here I am not sure if this was for me or in general. But if you (still) have your TeX.SX account I suggest that you post your answer above there too. |
Ah sorry if it wasn't clear. I just wanted to emphasize how these keys can be viewed as "column-first" principle and how other keys can be subsumed into column specifications. Then why the defaults are the way they are becomes clearer (I hope since I'm putting words into Till's mouth). The example is to demonstrate that you don't need to modify any low-level code or defaults. If I was starting from scratch I would have drawn the separated column/row separate anyways. I guess I could have just said "don't build broken-up tables with TikZ matrices but use actual tables with tikzmark etc. embellishments" |
@Mo-Gul These TeX.SX and, IMHO even more https://topanswers.xyz/tex, which does not have all the flaws of TeX.SX, can be viewed as example data-bases. There are examples at various levels. All I can say is that (a) I can see how the pgfmanual is confusing when it comes to matrices, and (b) I do not understand how an |
Here a suggestion for a better example, for the documentation \documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[
my block by block style/.code={%
\pgfmathparse{isodd(int((\pgfmatrixcurrentcolumn+1)/2))}
% \pgfmathparse{isodd(int((\pgfmatrixcurrentcolumn-1+#1)/#1))}
\ifnum\pgfmathresult=1
\tikzset{nodes={fill=yellow!10}}%
\fi
},
matrix/inner style order={
every cell,
even odd column,
even odd row,
column,
row,
this cell,
/tikz/my block by block style,
% /tikz/my block by block style=3,
},
]
\matrix [
matrix of nodes,
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
nodes={draw, anchor=center, minimum size=.75cm},
] {
1 & 1 & 1 & 0 & 1 & 0 & 0 & 1 & 1 & 0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 & 1 & 1 & 1 & 0 & 1 & 0 & 1 & 1 & 1 \\
};
\end{tikzpicture}
\end{document} resulting in Of course even better would be a more generic solution as the commented parts of the code (instead of the lines above the commented ones). But unfortunately I couldn't make it work. Anybody an idea? If there are no dissenting votes I would otherwise exchange the code tomorrow morning in the manual. |
The pgf/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex Lines 4091 to 4094 in 65bcaaf
so anything fancy inside will not work. As I said before (and as I have documented) you have to perform any style definition outside of this list. Moreover, I am aware that the example in the manual can be achieved easily with the existing styles, but that is not the point. I wanted to show how to use the new feature without adding too much unnecessary complexity. |
The construct matrix/inner style order={
...
/tikz/my block by block style=3,
}, should work with hmenke@5c96618. I also used the opportunity to rename |
I have no dog in this race, hence please ignore it at will but I don't see how default order is causing problems. In fact I would recklessly claim that any problem that can be solved with this new addition was already possible with the old behavior Here is @Mo-Gul 's example + some other rule with zero modifications to the machinery: \documentclass[tikz]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\tikzset{
every column/.style={every odd column/.append style={#1},
every even column/.append style={#1}},
mo-guls rule/.code={%
\pgfmathparse{isodd(int((\pgfmatrixcurrentcolumn-1+#1)/#1))}%
\ifnum\pgfmathresult=1\tikzset{nodes={fill=yellow!10}}\fi%
},
another rule/.code={\pgfmathparse{int(Mod(\pgfmatrixcurrentcolumn, 4))}%
\ifnum\pgfmathresult=0\tikzset{nodes={fill=red!10}}\fi}
}
\begin{tikzpicture}[]
\matrix [
matrix of nodes,
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
nodes={draw, anchor=center, minimum size=.75cm},
every column={mo-guls rule=3,another rule}
] {
1 & 1 & 1 & 0 & 1 & 0 & 0 & 1 & 1 & 0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 & 1 & 1 & 1 & 0 & 1 & 0 & 1 & 1 & 1 \\
};
\end{tikzpicture}
\end{document} I would argue that the documentation should mention that these keys can be used inside each other as I showed in my previous example. Hence the order is not really an issue. This also gives another design issue from Till that I really appreciate. The absence of every row or every column style. If you spend 5 seconds over it, it becomes obvious; if you are setting something for every row/column that means it is valid for the whole matrix. So we could just skip all this and write directly to the Hence my bold claim. |
@ilayn You are very right with your assertion. In principle all these styles are not needed and not even the Nevertheless, for most users it is much more natural to think in terms of even and odd column or rows and they are generally not comfortable writing complicated TeX conditionals. This little convenience of the abstraction is the only reason that these styles exist. |
@hmenke, @ilayn that is great news. From that -- I think -- we can agree that the "problem" is, that there isn't any such example in the manual. And maybe that is the point why beginners (like me) can't come up with such solutions. Maybe a small section should be added, e.g. as section 20.3.4, should be added to the manual with the above examples and your explanations, i.e. almost none of the commands of the previous section are needed. Then I think way more people will have a chance to come up with good solutions themselves for their problems. @ilayn, would you be so kind to do so? I'll be very happy to prove-read it. And if I understand it, then hopefully a lot of others will as well ;) That would really be awesome. |
@Mo-Gul Ha! If anything the problem is that nobody reads the manual. |
@hmenke While it is true that users are almost perfect at ignoring the manual, certain techniques have more impact when they are documented there. That is, if someone writes an answer on one of these sites that works, users are less inclined that this is "the way this should be done" than if this is also written in the manual. So I agree with @Mo-Gul that one should at least make an effort. |
PR submitted. All feedback is appreciated. |
@ilayn (Nice to meet you here;-). I have a comment, if you don't mind. The example is great, but I feel that by far the biggest issue is that the pgfmanual discusses matrices in two separate sections, namely in 20 Matrices and Alignment and in 60 Matrix Library, where, as far as I can see, in section 60 section 20 does not even get mentioned. I actually do not even see a point in having section 60 separately since the matrix library gets loaded in the earlier examples, too. It could just become a subsection of 20. Then I would also add examples using the counts |
Yes @tallmarmot I agree but I guess it comes from the tikz/pgf layer distinction. 60 is more at the pgf layer manipulations and 20 is for tikz based straightforward key/value stuff. Years of usage proved that it is often required to mix them but I guess that's more of a lack of documentation issue. Section 20 can mention section 60 more maybe. Or include more examples. Or these counters can be converted into usable keys like |
@ilayn Naively I'd say the opposite. Section 20 deals also with examples that do not require the TikZ library matrix, but only the pgf module. Maybe for most users it is obvious, but one does not need the matrix library to make use of the matrix. I also have no strong opinion, personally I am more and more getting used to the mode "ignore the manual and read the library". 😉 |
Ah OK my bad by 60 I am apparently meaning 108. Then yes they can be combined but the 20-like sections were kind of introductory tutorials and the 60-like library sections were kind of a reference. So I guess there is not enough meat in 20 and can be populated. But I don't have a good solution. |
@tallmarmot are willing to make a proposal for a better documentation of the matrix command/library that than can be discussed/reviewed by us? If your answer is yes, I suggest to file a new issue for that referencing this issue. Because this is really another topic than this issue and also would (still) be open instead of closed like this issue ;) |
Currently the order in which column/row styles are applied seems to be the following:
I find this to be rather counterintuitive as I expect styles for a specific single column to overwrite styles for e.g. a general odd column. Instead I would like to propose changing the order to:
There are ways to achieve the wanted styles without this change but they require dwelling into the source code and using some more advanced commands. TeX.SE link of this exact problem: https://tex.stackexchange.com/questions/546396/tikz-matrix-overwrite-every-column-row-style-for-specific-column-row
The text was updated successfully, but these errors were encountered: