1

I'm using the tkz-fct package and I'd like to change the appereance of the grid issued with the command \tkzGrid , for example switch from solid to dotted lines. So far I managed only to change the color of the grid lines with the following MWE, (not minimal really, since I could drop the function plot).

\documentclass{scrartcl}
\usepackage{tkz-fct}
 \begin{document}
    \begin{tikzpicture}
       \tkzInit[xmin=-5,xmax=4,ymin=-4,ymax=5]
       \tkzGrid[color=yellow,style=dashed,line width=2pt]
       \tkzFct[color=red,ultra thick]{(-x**2-2*x+3)} 
       \tkzAxeXY 
    \end{tikzpicture} 
 \end{document}

I am aware that I can put \tkzGrid in a scope environment like suggested in the answer at link but I think that something like a \tikzset{grid style/.style={draw (or color) = yellow,line pattern=dotted}} would be more appropriate.

I couldn't find anything else searching through tex.stack exchange or in the tkz-fct tutorial.


Edit on 2024 january 4-th. A strange behaviour arises when I put \tkzAxeXY after \tkzFct; axes' graduations get red.


Tried to add some options to \tkzGrid, it doesn't occur any error but grid lines don't get dashed; line width and color are affected instead.

Antonio
  • 95
  • The scope idea seems to do the trick. However, it may be a good idea to contact the author, see link in the manual. Either grid options are largely ignored, or there's a hidden way to use them. All are reasons enough to talk about it and perhaps introduce changes, e.g. in the manual. – MS-SPO Jan 05 '24 at 20:31
  • The best method is to use scope. tkz-fct is a fairly rudimentary package. It allows users to create their own code with TikZ. Since the creation of this package, pgfplots has appeared, which is complete and perfect, so I don't think I'll be reviewing the code. – Alain Matthes Jan 05 '24 at 21:39
  • @Alain Thank you, after all scope environment is simple enough. – Antonio Jan 07 '24 at 09:48
  • @Antonio Perhaps when tkz-elements is well advanced, I'll make a more complete version but with lualatex and without gnuplot. – Alain Matthes Jan 07 '24 at 10:34
  • @Alain Matthes Dear Alain, I'd like to ask why running my code gives the number labels along the axes in red instead of default black color. I suspect that this behaviour is triggerd by putting \tkzAxeXY after tkzFct[color=red]. Unfortunately I cannot post images yet. – Antonio Jan 08 '24 at 11:45
  • you need to put \tkzAxeXY before tkzFct[color=red] but it is possible to put it after tkzFct if you put this line either in a scope or simply in a { ....} group. – Alain Matthes Jan 08 '24 at 13:36

1 Answers1

0

Be plain, be simple.

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[cyan,dotted] (-5,-2) grid (3,5);
\draw[->] (-5,0)--(3,0) node[below left]{$x$};
\draw[->] (0,-2)--(0,5) node[below left]{$y$};

\begin{scope} \clip (-5,-2) rectangle (3,5);
\draw[red,ultra thick,smooth] plot[domain=-4:3] (\x,-\x\x-2\x+3); \end{scope} \end{tikzpicture} \end{document}

Black Mild
  • 17,569
  • That’s exactly the way I did it until now. For simple/pedagogical graphs I find tkz-base/fct more convenient though. For example there is no need for clipping since \tikzinit suffices. Furthermore, things start to become messy if you need ticks and graduations on coordinate axes. Thanks a lot anyway. – Antonio Jan 08 '24 at 07:34