I've been starting to generate my own diagrams for academic purposes using TikZ. I've been working with GeoGebra, to generate my figures, and exporting TikZ code.

In the diagram I'm working on I just want to draw a simple rectangle over the x-y axes:


\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=-10cm,y=40cm]

%Clip Region
\clip(-0.1,-0.025) rectangle (1.1,0.025);

\draw[->,color=black] (-0.1,0.) -- (1.1,0.);
\foreach \x in {,0.8}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-6pt) node[below] {\footnotesize $-\x$};
\draw[->,color=black] (0.,-0.1) -- (0.,1.1);
%\foreach \y in {,0.2,0.4,0.6,0.8,1.}
%\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
%\draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};

\draw (0.,-0.005)-- (1.,-0.005);
\draw (1.,-0.005)-- (1.,0.005);
\draw (1.,0.005)-- (0.,0.005);
\draw (0.,0.005)-- (0.,-0.005);


The above code produces the image below: Axes Test

What's up with the extra - below the left end of the rectangle, and how do I get rid of it? I can confirm that the extra dash is not present when I change $-\x$ to $\x$ in line 17, so it has something to do with that line, but I can't quite figure out why it would put a dash there. It appears at the same place regardless of which x values are in the \foreach list on line 16.

I am using Overleaf to test out the diagrams, but I ran the above example through pdflatex on my own machine (Windows 7 w/ MikTex) and observed the same behaviour. The dash shows up in both Adobe Acrobat Reader and SumatraPDF.

  • What is {,0.8} ? – percusse Aug 24 '16 at 18:13
  • @percusse That's the way the lists are exported from GeoGebra, always with a leading comma – NauticalMile Aug 24 '16 at 18:14
  • That's an empty entry hence -{empty} – percusse Aug 24 '16 at 18:15
  • I just tried deleting it and the dash dissapeared! – NauticalMile Aug 24 '16 at 18:15
  • @percusse sorry I answered my own question without thinking. Would you like to write the answer? I'm happy to delete mine. – NauticalMile Aug 25 '16 at 1:09

Ok so apparently the leading comma in the line:

\foreach \x in {,0.8}

means there is an empty element in the list. I'm guessing that the export method from Geogebra to TikZ is pretty simple, and they weren't really thinking I would use it as a template. In any case, the solution is to delete any leading commas:

\foreach \x in {0.8}

Thanks for the hint percusse

  • You should ask the person who helped to write an answer rather than taking the credit for it yourself. – cfr Aug 24 '16 at 23:58
  • @cfr good thought. I asked percusse. If they say so, I will delete my answer and accept theirs. – NauticalMile Aug 25 '16 at 1:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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