4

I did plot my graph with GeoGebra, but when I added it to Texmaker the graph isn't proper. That's why I'm trying to color the background of the graph with the same color as inside the other circle (grey). I'm trying to do this by adding the command

\addplot [draw=black, fill=grey] coordinates {(-3,-3) (-3,3) (3,-3) (3,3)};

Can someone solve my problem? Here is the full code for the tikzpicture:

\documentclass{article}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}


\begin{document}
\definecolor{uququq}{rgb}{0.25098039215686274,0.25098039215686274,0.25098039215686274}
\definecolor{ffqqqq}{rgb}{1,0,0}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1cm,y=1cm]
\draw[->,color=black] (-4,0) -- (4,0);
\foreach \x in {-4,-3,-2,-1,1,2,3,4}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt);
\draw[->,color=black] (0,-3.9627039627039613) -- (0,4);
\foreach \y in {-3,-2,-1,1,2,3}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt);
\clip(-8,-3.9627039627039613) rectangle (8,4);
\draw[line width=2pt,color=ffqqqq,smooth,samples=100,domain=-8:8] plot(\x,{(\x)});
 \draw [rotate around={0:(-1,0)},line width=2pt,color=uququq] (-1,0) ellipse (1cm and 1cm);
 \draw [rotate around={0:(0,0)},line width=2pt,fill=black,fill opacity=0.25] (0,0) ellipse (1.4142135623730951cm and 1.4142135623730951cm);
 \begin{scriptsize}\draw[color=ffqqqq] (-3.2950340798442066,-3.655011655011654) node {$f(x) = x$};\draw [fill=black] (0,0) circle (2.5pt);
 \draw[color=black] (0.6932814021421617,0.39160839160839206) node {$A = (0, 0)$};
 \draw [fill=black] (-1,-1) circle (2.5pt);
 \draw[color=black]  (-0.1947419668938657,-0.5967365967365961) node {$B = (-1, -1)$};
 \end{scriptsize}
 \end{tikzpicture}
\end{document}
3
  • Welcome to TeX.SX!
    – Bobyandbob
    Feb 25, 2018 at 9:06
  • 2
    Is [background rectangle/.style={fill=red}, show background rectangle] (replace red with your color), see How to change the paper color(background color) in tikz class an option? SO you want to change the background color right?
    – Bobyandbob
    Feb 25, 2018 at 9:32
  • You need to make a minimal example showing your problem. Is \usepackage[Swedish]{babel} needed to show your problem? -it does not compile on my system - I guess that a swedish language package needs to be installed. What color do you want? Which is "the other circle"? Feb 25, 2018 at 9:35

1 Answer 1

4

like this?

enter image description here

the solution for your wish is provided by Bobyandbob's comments. that the background rectangle will show up you need to add tikz library backgrounds.

off-topic: apparently geogebra generate a lot of clutter in code. i try to remove it and simplify code as much as possible:

\documentclass{article}
\usepackage{pgfplots} % it load also tikz
\usepackage[ansinew]{inputenc}
\usepackage[T1]{fontenc}
%\usepackage[Swedish]{babel}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amssymb}
%%\usepackage{pgfplots,mathrsfs}% loaded twice
\usepackage[shortlabels]{enumitem}
%%\usepackage{pgf,tikz} % loaded twice
\usepackage{mathrsfs}
\usetikzlibrary{arrows, backgrounds}
\usepackage{framed}

\begin{document}
\definecolor{uququq}{rgb}{0.25098039215686274,0.25098039215686274,0.25098039215686274}
\definecolor{ffqqqq}{rgb}{1,0,0}
    \begin{tikzpicture}[
    line cap = round, >=triangle 45,
    every node/.append style = {font=\footnotesize},
    background rectangle/.style={fill=yellow!20},
    show background rectangle
                        ]
\draw[->] (-4,0) -- (4,0);
\foreach \x in {-3,...,3}{\draw (\x,2pt) -- + (0,-4pt);}
\draw[->] (0,-4) -- (0,4);
\foreach \y in {-3,...,3}{\draw (2pt,\y) -- + (-4pt,0);}
%
\draw[line width=2pt,color=ffqqqq]
    (-4,-4) -- node[sloped,pos=0.1,above] {$f(x) = x$} (4,4);
\draw[line width=2pt,color=uququq] (-1,0) circle (1cm);
\draw[line width=2pt,fill=black,fill opacity=0.25] (0,0) circle (1.41cm);
\fill[black] ( 0, 0) circle (3pt) node[above right] {$A=(0,0)$};
\fill[black] (-1,-1) circle (3pt) node[above right] {$B=(-1,-1)$};
    \end{tikzpicture}
\end{document}
5
  • Thank you for this answer. This works when I am compiling a standalone tikzpicture. But when I include it another document using \includestandalone from standalone package, it does not work. Any solution for that? Jul 6, 2022 at 21:20
  • 1
    Please ask new question (with link to my answer), where you show (with MWE) what is your problem. From your comment is not entirely clear what you after or what you doing.
    – Zarko
    Jul 6, 2022 at 21:25
  • Zarko, I tried to replicate the issue so that I can put it up as a separate question. But in the process I figured out the solution. So I will just add it as a comment here. If you use the standalone package to include a tikz figure in some article as \includestandalone (not as \includegraphics), then you need to import the relevant tikz libraries in the main article. Without the required imports, TexStudio threw error, but Overleaf did not. Jul 7, 2022 at 16:02
  • @GautamSreekumar, than be so kind and delete your comments since they have nothing with OP question nor with provided answer nor help anyone on this site.
    – Zarko
    Jul 7, 2022 at 16:10
  • Friendly improvement: \usetikzlibrary{backgrounds} then \tikzset{background fill/.style={background rectangle/.style={fill=#1},show background rectangle}} in the preamble allows you to set background fill=yellow!20 (for example) after \begin{tikzpicture} Sep 7, 2022 at 14:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.