18

I use tikz, and try draw a directed graph with

\begin{tikzpicture} \node[draw, circle] (1) {1}; \node[draw, circle] (2) [ right of=1] {2}; \path (1) edge (2); \end{tikzpicture} 

and get

ss

how I can get this ? (with arrow)

ss1

Edit

I try with

\path[->] (1) edge (2); 

but I get

! Argument of \language@active@arg> has an extra }. <inserted text> \par l.403 \path[->] ( 1) edge (2); 
3
  • 2
    Just add [->] after \path. See the manual for various arrow style options. Commented Mar 21, 2012 at 0:32
  • As @percusse said. Possible Duplicate: Graph into graph with arrows Commented Mar 21, 2012 at 0:35
  • Your code \path[->] (1) edge (2); works fine for me... Commented Mar 21, 2012 at 0:47

5 Answers 5

21

spanish babel's option declares < and > active characters to write something like <<Hello>> and obtain french quotes. This behavior clashes with TiKZ arrow form [->]. The way to deactivate <> is \usepackage[spanish,es-noquoting]{babel}, so

\documentclass{article} \usepackage{tikz} \usepackage[spanish,es-noquoting]{babel} \begin{document} \begin{tikzpicture} \node[draw, circle] (1) {1}; \node[draw, circle] (2) [ right of=1] {2}; \path[->] (1) edge (2); \end{tikzpicture} \end{document} 

works as expected. I've found this solution in CervanTeX (spanish TUG) forums:

Update for TiKZ 3.0

TiKZ 3.0 includes a new babel library (pgfmanual section 42) which avoid this kind of problems. Using it, is not necessary to use es-noquoting option any more. You can even have spanish quotes inside nodes.

\documentclass{article} \usepackage[spanish]{babel} \usepackage{tikz} \usetikzlibrary{babel,positioning} \begin{document} \begin{tikzpicture} \node[draw, circle] (1) {<<1>>}; \node[draw, circle] (2) [ right = of 1] {<<2>>}; \path[->] (1) edge (2); \end{tikzpicture} <<Hola>> \end{document} 

enter image description here

3
  • Do you know if babel-greek declares something which might cause problems even with 3.0? I'm having trouble reproducing in a MWE but in my real code, merely adding greek to the babel options causes compilation to fail and I've no idea why. Commented Aug 18, 2014 at 15:07
  • @cfr I've never used babel-greek. What problem do you have? Is it in a TiKZ graphic? Or in normal text but loading TiKZ3.0? What's shown in .log file? I'm sure you understand that with this kind of description is difficult to help you. Commented Aug 18, 2014 at 16:36
  • Sure. It was just a query in case you happened to know of any similar issue with babel-greek. (Yes, it is a TikZ graphic and it is something about that plus loading babel-greek, even if no Greek is included in the graphic or anywhere in the document.) But asking was rather a long shot. Thanks for taking the time to reply. Commented Aug 18, 2014 at 17:05
6

Maybe this old Mail from Till Tantau I found when googling your added error message is helpful somehow: tex.pgf.user list.

There seems to be an issue with the use of < and > as ative characters in some languages in TeX. The solution is supposedly (quoting Till)

[...] using \shorthandsoff (or something similar) inside a tikzpicture.

2
  • maybe this is my problem, I use spanish package Commented Mar 21, 2012 at 1:00
  • @JuanPablo This is to show you how important a minimal working example is. Commented Mar 21, 2013 at 6:05
3

A follow-up on the possible interference from {babel} language options.

I have experienced this issue with several punctuation marks that, in French, require a space after them, and are coded in the french option to babel to do so:

 : ; ? ! 

However, the colon (:) is also used in arydshln.sty. To circumvent this, I do indeed use the solution ascribed to Till Tantau:

\shorthandoff{:}

I also extend that to the semi-colon, question mark, and exclamation mark in French-lang. journals which do NOT want that trailing space:

\shorthandoff{;} \shorthandoff{?} \shorthandoff{!}

Currently, I'm learning to incorporate tikz code into the CJL macros (Cdn. Jrnl. of Ling.) and have found I can get around the shared use of > by adding this

\shorthandoff{>} 

not WITHIN the tikzpicture environment but just before -- but still within the outer figure environment.

1
1

I solved with

\begin{tikzpicture}[thick] \node[draw, circle] (1) {1}; \node[draw, circle] (2) [ right of=1] {2}; \begin{scope}[-stealth] \path (1) edge (2); \end{scope} \end{tikzpicture} 
1
  • 3
    Using \path [-stealth] (1) edge (2); works just fine without requiring the extra scope. I would recommend you upgrade your packages. Commented Mar 21, 2012 at 1:00
1

Good evening, I am using this approach which doesn't affect active characters outside the TikZ environment, if needed. I would add this command in the document body for Spanish.

\tikzset{every picture/.append style={execute at begin picture={\catcode`\>=12\catcode`\<=12}}} 

I usually don't use \shorthandoff command because it is unclear if babel package is loaded or not. If I need active characters, e.g. inside the TikZ nodes, I would use:

\node{\catcode`\<=13\catcode`\>=13 <<Hello>>}; 

Here is an example:

\documentclass{article} \usepackage{tikz} \usepackage[spanish]{babel} \pagestyle{empty} \begin{document} \tikzset{every picture/.append style={execute at begin picture={\catcode`\>=12\catcode`\<=12}}} \begin{tikzpicture} \node[draw,circle] (1) {1}; \node[draw,circle] (2) [right of=1] {2}; \node[draw,circle,xshift=1cm,inner sep=0pt](3)[right of=2]{\catcode`\<=13\catcode`\>=13 <<Hello>>}; \path[<->] (1) edge (2); \path[>-<] (2) edge (3); \end{tikzpicture}\par <<Hello, World!>> \end{document} 

A small example to test the mentioned approach

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.