When using every x tick label/.append style={font=\scriptsize}
in combination with \pgfplotsset
outside the tikzpicture environment, the pgfplotsset
command from the preamble will be ignored (respectivly overwritten) by every x tick label/.append style={font=\color{black}}
within the axis environment of the tikzpicture (note: the command within the axis environment is not related to the font size as the pgfplotset command in the preable and should therefore not overwrite information about the fontsize).
Example Code:
\documentclass[12pt,a4paper,tikz]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{tikz,pgfplots,grffile,amsmath}
\pgfplotsset{compat=newest}
\pgfplotsset{mytikzstyle/.style={
every axis/.append style={
legend style={
font=\tiny, % within the legend, fontsize changes work as there is no legend command in the axis environment that overwrites it...
},
},
every x tick label/.append style={font=\scriptsize}, % won't work as it seems to be deleted/overwritten by .append style in the axis environment
every y tick label/.append style={font=\scriptsize}, % will work, because there is no .append style command in the axis environment
%every tick label/.append style={font=\scriptsize}, % works neither ...
},}
\pgfplotsset{mytikzstyle}
\pgfplotsset{/pgfplots/width=8cm}
\pgfplotsset{/pgfplots/height=6cm}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
separate axis lines,
every x tick label/.append style={font=\color{black}},
%every x tick label/.append style={font=\scriptsize}, % if I'd uncomment this line, the x tick labels would be properly displayed in \scriptsize
%every y tick label/.append style={font=\color{black}}, % if I'd uncomment this line, the font change of the y-axis wouldn't work either
legend style={at={(0.99,0.01)}, anchor=south east, legend cell align=left, align=left, draw=gray},
]
\addplot [line width=0.8pt, color=black]
table[row sep=crcr]{%
1 1\\
100 100\\
};
\addlegendentry{Hello $U_{1}\frac{xyz}{xyz}$}
\end{axis}
\end{tikzpicture}%
\end{document}
As you can see: y tick label fontsize change works, as there is no command within the axis environment that will overwrite the pgfplots command (although I am only using append everywhere, anyway) x tick label fontsize change doesen't work as it seems to be overwritten by the x tick label command in the axis environment.
I really don't understand why this is like it is. Is it intended? My problem is actually that the axis code is generated by matlab2tikz in my case and I want to have an easy and convenient possibility to change styles from outside the tikzspicture environment with predefined pgplotsets/styles in LaTeX. But if the styles are overwritten by appended commands within the axis environment, it becomes useless...
Thanks in advance for any further explanation and how to avoid problems like this in future!
FINAL EDIT: The problem is a side effect of the font=\color{black}
command, which overwrites other font properties, such as \tiny
and therefore the pgfplotsset
command that should affect the fontsize won't be appended (respectivly is resetted to \normalsize
). Replacing the command by text=black
will solve this problem, as text=black
does not overwrite all other font settings. It was reported at github (matlab2tikz) and already fixed in the development branch of matlab2tikz, as the code with font=\color{black}
was generated from it. The solution can also be applied by find and replacing font=\color{yourcolor}
by text=yourcolor
or in the matlab2tikz.m
file as shown here by finding ['{font=\color{',col,'}}']);
and replacing by ['{text=',col,'}']);
in matlab2tikz.m, to prevent matlab2tikz from creating the side affected code again.
Unfortunately, I just realized that there are more such commands (exported by matlab2tikz), e.g. title style={font=\bfseries}
, which will overwrite all color or size settings of the title that were defined with pgfplotsset
before... Another example is ylabel style={font=\color{white!15!black}}
, which will reset all y label settings to the default value and then applies only the color change.
Ultimately, this particular problem can be considered solved, as it is understood why the pgfplotsset
commands are overwritten and not appended as expected and how this can be fixed, but with respect to matlab2tikz there is a lot more to do.
font=\color{black}
actually means: set normal font in black. To change only color, correct approach istext= <color>
.text= <color>
: Do you mean like this:every x tick label/.append style={text=\black},
? Can you give an example if I am wrong?every x tick label/.append style={font=\color{black}}
in preamble ofaxis
withevery x tick label/.append style={text=red},
the tick label will appear in red color and with font size as you declared in\pgfplotsset
.font=\color{black}
is the whole reason for the problem? I just realised, when replacing it withtext=black
, everything works as it should ... and theevery x tick label/.append style={text=black},
really appends instead of overwriting, what was one of my questions originally, when I asked if it is intended that the append command within the axis environment does actually not append but overwrite things... Where did you find thattext=black
is the right command for this purpose? I searched the pgfplots manual fortext=
and didn't find a single hit!