Graphics, Figures & TablesTikZ partway calculations

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Anicka
Posts: 13
Joined: Tue Oct 12, 2010 1:20 pm

TikZ partway calculations

Post by Anicka »

Hallo again!

I'm trying to make a picture with TikZ, but I have a problem with the partway coordinates. The example below is from the pgf-manual and should therefore work, but I get errors as seen further down.

Code: Select all

\usepackage{tikz}
\usetikzlibrary{calc}

\begin{tikzpicture}
\coordinate [label=left:$A$] (A) at (0,0);
\coordinate [label=right:$B$] (B) at (1.25,0.25);
\draw (A) -- (B);
\node [fill=red,inner sep=1pt,label=below:$X$] (X) at ($ (A)!.5!(B) $) {};
\end{tikzpicture}
! Package tikz Error: + or - expected.
l.121 ...r sep=1pt,label=below:$X$] (X) at ($ (A)!
.5!(B) $) {};

After forcing pdflatex to go further, I get further errors, but nothing helpful. I use TeXLive on Windows with all the latest updates.

Thanks in advance for any help you can supply.
Last edited by Anicka on Thu Feb 24, 2011 12:06 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

TikZ partway calculations

Post by localghost »

Please get used to always providing a minimal example [1]. Make sure that you have the latest version of pgf/tikZ. Completed to a full example, the code works flawlessly.

Code: Select all

\listfiles
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
  \begin{tikzpicture}
    \coordinate [label=left:$A$] (A) at (0,0);
    \coordinate [label=right:$B$] (B) at (1.25,0.25);
    \draw (A) -- (B);
    \node [fill=red,inner sep=1pt,label=below:$X$] (X) at ($ (A)!.5!(B) $) {};
  \end{tikzpicture}
\end{document}
Search the log file for the list of used files and compare.

Code: Select all

*File List*
 minimal.cls    2001/05/25 Standard LaTeX minimal class
    tikz.sty    2010/10/13 v2.10 (rcs-revision 1.76)
     pgf.sty    2008/01/15 v2.10 (rcs-revision 1.12)
  pgfrcs.sty    2010/10/25 v2.10 (rcs-revision 1.24)
everyshi.sty    2001/05/15 v3.00 EveryShipout Package (MS)
  pgfrcs.code.tex
 pgfcore.sty    2010/04/11 v2.10 (rcs-revision 1.7)
graphicx.sty    1999/02/16 v1.0f Enhanced LaTeX Graphics (DPC,SPQR)
  keyval.sty    1999/03/16 v1.13 key=value parser (DPC)
graphics.sty    2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR)
    trig.sty    1999/03/16 v1.09 sin cos tan (DPC)
graphics.cfg    2007/01/18 v1.5 graphics configuration of teTeX/TeXLive
  pdftex.def    2011/01/28 v0.05d Graphics/color for pdfTeX
  pgfsys.sty    2010/06/30 v2.10 (rcs-revision 1.37)
  pgfsys.code.tex
pgfsyssoftpath.code.tex    2008/07/18  (rcs-revision 1.7)
pgfsysprotocol.code.tex    2006/10/16  (rcs-revision 1.4)
  xcolor.sty    2007/01/21 v2.11 LaTeX color extensions (UK)
   color.cfg    2007/01/18 v1.5 color configuration of teTeX/TeXLive
 pgfcore.code.tex
pgfcomp-version-0-65.sty    2007/07/03 v2.10 (rcs-revision 1.7)
pgfcomp-version-1-18.sty    2007/07/23 v2.10 (rcs-revision 1.1)
  pgffor.sty    2010/03/23 v2.10 (rcs-revision 1.18)
 pgfkeys.sty    
 pgfkeys.code.tex
  pgffor.code.tex
    tikz.code.tex
supp-pdf.mkii
 ***********
[1] View topic: Avoidable mistakes


Thorsten
Anicka
Posts: 13
Joined: Tue Oct 12, 2010 1:20 pm

Re: TikZ partway calculations

Post by Anicka »

Thank you for testing and in fact that works, so I probably have a problem with interfering packages. I will have to go through my rather extensive list of packages and see where the problem lies.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

TikZ partway calculations

Post by localghost »

Anicka wrote:[…] I probably have a problem with interfering packages. […]
There is no problem with interferences, but with outdated packages. Just update your TeX system.
Anicka
Posts: 13
Joined: Tue Oct 12, 2010 1:20 pm

TikZ partway calculations

Post by Anicka »

localghost wrote:
Anicka wrote:[…] I probably have a problem with interfering packages. […]
There is no problem with interferences, but with outdated packages. Just update your TeX system.
Then can you please explain to me why it works in a stand-alone minimal environment (on my computer), but not when used as a part of my thesis? (By the way, my system is updated with the latest packages from the TeXLive distribution, just as I stated in my first post.)

P.S. Yes, I'm a girl and yes, I'm a blond too and, on top of that, rather new to the more intricate parts of TeX, but I'm only asking because Google is not my friend on this.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

TikZ partway calculations

Post by localghost »

Anicka wrote:[…] Then can you please explain to me why it works in a stand-alone minimal environment (on my computer), but not when used as a part of my thesis? (By the way, my system is updated with the latest packages from the TeXLive distribution, just as I stated in my first post.) […]
Must have missed that. Indeed, then you have to reduce the problem to a minimal example that reproduces the error and present it here. Perhaps it's only a matter of the load sequence. I suggest to create a document with all used packages and only this single figure. Commenting out packages step by step should yield the culprit.
Anicka wrote:[…] P.S. Yes, I'm a girl and yes, I'm a blond too and, on top of that, rather new to the more intricate parts of TeX, but I'm only asking because Google is not my friend on this.
Such remarks are completely superfluous.
Anicka
Posts: 13
Joined: Tue Oct 12, 2010 1:20 pm

TikZ partway calculations

Post by Anicka »

Ok, I've been testing. If I load \usepackage[british,french]{babel}, I get this error. It doesn't matter if I put it before or after. Do you have any suggestion how to solve this problem? I am obliged to have one chapter in French even though the rest is in English.

Edit: This seam to be a known problem with French babel and how it treats active characters http://compgroups.net/comp.text.tex/Err ... bel-french. I will test further, but I'm a bit confused, since this is in a part of my thesis that is in English. Why does the French definitions of active characters influence the English parts?

Thanks for leading me in the good direction.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

TikZ partway calculations

Post by localghost »

If you only need one chapter in French, you should swap the language options for babel.

Code: Select all

\usepackage[french,english]{babel}
The latter one always determines the default language of the document. You can selectively switch to French later wherever needed and switch back again. But that doesn't solve the actual problem. You have to temporarily turn off some active characters like shown in the example below.

Code: Select all

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french,english]{babel}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{blindtext}

\begin{document}
    \blindtext

    \shorthandoff{:}\shorthandoff{!}
    \begin{tikzpicture}
      \coordinate [label=left:$A$] (A) at (0,0);
      \coordinate [label=right:$B$] (B) at (1.25,0.25);
      \draw (A) -- (B);
      \node [fill=red,inner sep=1pt,label=below:$X$] (X) at ($ (A)!.5!(B) $) {};
    \end{tikzpicture}
    \shorthandon{:}\shorthandon{!}
    
    \blindtext
\end{document}
This has to be done for every tikzpicture environment you declare in your source. The characters are made active globally through the language option regardless of the language actually used. So this affects also your text passages in English.
Anicka
Posts: 13
Joined: Tue Oct 12, 2010 1:20 pm

Re: TikZ partway calculations

Post by Anicka »

Thanks a bunch!

I had tried only with /shorthandoff{:}, but that didn't work, but with \shorthandoff{!} as well, it compiles as it should.

Thank you!
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

TikZ partway calculations

Post by localghost »

Anicka wrote:[…] I had tried only with /shorthandoff{:}, but that didn't work, but with \shorthandoff{!} as well, it compiles as it should. […]
Turning off »:« suffices for pgf/tikZ only. But it requires to turn off »!« as well when using the »calc« library.
Post Reply