2

I have created a simple graph thanks to a tutorial. The graph itself works and compiles if I just use the packages the tutorial said and it compiles perfectly, but when I add the graph to my latex file it doesn't compile. I know it has to do with the packages... Can anyone help me adding/modifying the correct packages?

I know it works. The other code also works separately. What I need is the figure to work in the second file. As I say the other file also works.

Maybe I don't write the code as it is intended. Note that I have removed and created a simple file so that you can help me. It's not the final nor the code itself. Just the core of what I want to do. Both files work by themselves, and what I am asking for is for help to merge both in a compilable file. –

This is the graph file

\documentclass{article}

\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usepackage[latin1]{inputenc}
\begin{document}


\begin{tikzpicture}[->,>=stealth',shorten >=2pt,auto,node distance=2.8cm,
                    semithick]
  \tikzstyle{every state}=[fill=gray,draw=none,text=white]

  \node[state] (A)                    {$1$};
  \node[state]         (B) [above right of=A] {$2$};
  \node[state]         (C) [right of=B ] {$3$};


  \path 
    (A) edge            node {} (B)
          edge            node {} (C)      

    (B) edge            node {} (C)

    (C) edge            node {} (A);



\end{tikzpicture}

\end{document}

The problem comes when I want to add my graph to a Latex file I am creating that needs other packages:

    \documentclass{article}

    \usepackage{lmodern}
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}
    \usepackage[spanish,activeacute]{babel}
    \usepackage{amsmath, amssymb}
    \usepackage{graphicx}
    \graphicspath{ {F:\Espacio de trabajo/} }




    \title{Problema}
    \author{MNLR}


    \begin{document}



    \maketitle

    \chapter{\textit{\begin{flushleft}\normalsize{ Things I have to do... }\end{flushleft}}}

    \chapter{\begin{flushleft}\normalsize{  blah blah }\end{flushleft}}

    \chapter{\begin{flushleft}\normalsize{
    \begin{itemize}
      \item It's times like this ...

      \item \textbf{that make me say  } 

    \end{itemize}
    }\end{flushleft}}
\end{document}

I do know everything is working. I just need to combine both in one file. This is, to put the graph in the other code.

Thanks.

  • Welcome to TeX SX! Three problems, which have nothing to do with your graphic file. First, the article class defines no \chapter. Usereport or book for that. Second, you're not supposed to write formatting commands as an argument to \chapter. That's against the spirit of LaTeX, and here, flushleft and itemize won't work. What you can do is redefining chapters formatting in your preamble with a dedicated package such as titlesec. You should take a look at its documentation. – Bernard Oct 18 '14 at 22:27
  • Your figure code is not compilable. In the figure, the style inicio is not defined, If i remove it then the code runs perfectly. – skpblack Oct 18 '14 at 22:29
  • Note \chapter takes the heading as argument, not the entire chapter, so it should be something like \chapter{Introduction} also F:\Espacio de trabajo/} } is not goung to work the \ needs to be / or tex will see it as a tex command, and spaces in filenames are tricky, I'd use a folder without spaces initially. – David Carlisle Oct 18 '14 at 22:50
  • Sorry about the figure code, I removed some of it to leave the basic part. I know it works. The other code also works separately. What I need is the figure to work in the second file. As I say the other file also works. – D1X Oct 18 '14 at 22:59
  • Maybe I don't write the code as it is intended. Note that I have removed and created a simple file so that you can help me. It's not the final nor the code itself. Just the core of what I want to do. Both files work by themselves, and what I am asking for is for help to merge both in a compilable file. – D1X Oct 18 '14 at 23:17
0

Here is a cleaned up version of your code which combines the two documents. It relies on a solution explained by Gonzalo Medina here which requires PGF/TiKZ version 3.0. If you are using an older version, you will either need to use the workaround also explained in that answer or (preferably) update.

\documentclass[spanish]{book}% article has no chapters; pass language as class option so all language-sensitive packages know about it
\usepackage[activeacute]{babel}
\usepackage[utf8]{inputenc}% make sure everything uses the same encoding - save your files in the encoding you are using
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsmath, amssymb}
\usepackage{tikz}
\usetikzlibrary{arrows,automata,babel}% use the babel library to avoid problems due to the spanish localization: see https://tex.stackexchange.com/a/166775/ for details and for an alternative workaround for pre-3.0 versions of TiKZ/PGF

\title{Problema}
\author{MNLR}

\begin{document}

  \maketitle

  \chapter{Things I have to do\dots}% get rid of the markup in the arguments as formatting in the arguments here is just wrong and will definitely break stuff

  \begin{tikzpicture}
    [
      ->,
      >=stealth',
      shorten >=2pt,
      auto,
      node distance=2.8cm,
      semithick,
      every state/.style={fill=gray, draw=none, text=white},
    ]

    \node[state] (A)                    {$1$};
    \node[state]         (B) [above right of=A] {$2$};
    \node[state]         (C) [right of=B ] {$3$};

    \path
    (A) edge            node {} (B)
    edge            node {} (C)

    (B) edge            node {} (C)

    (C) edge            node {} (A);

  \end{tikzpicture}

  \chapter{blah blah}

  \chapter{It's times like this \dots that make me say}

\end{document}

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.