I need to draw a graph in a document built with \documentclass{book}
.
To do this I'm using the tikz
package, but when I run the .tex file the nodes are all one above the other, no matter the distance I set.
This is the code I'm using:
\begin{tikzpicture}[node distance={50mm}, thick, main/.style = {draw, circle}]
\node[main] (1) {$1$};
\node[main] (2) [right of=1] {$2$};
\node[main] (3) [right of=2] {$3$};
\node[main] (4) [below of=1] {$4$};
\node[main] (5) [right of=4] {$5$};
\node[main] (6) [right of=5] {$6$};
\end{tikzpicture}
With documentclass{article}
the code works fine, but I cannot use that documentclass.
Could you help me to understand why the package is not working? Do you know other solutions?
This is the code that I run:
\documentclass[a4paper, 12pt]{book}
\usepackage[italian]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{indentfirst}
\usepackage{fancyhdr}
\usepackage[dvips]{graphicx}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{latexsym}
\usepackage{amsthm}
\usepackage{eucal}
\usepackage{eufrak}
\usepackage{tikz}
\usetikzlibrary{graphs,graphs.standard,quotes,arrows.meta}
\title{My Title}
\author{Me}
\date{}
\begin{document}
\maketitle
\input{doc1.tex}
\input{doc2.tex}
\end{document}
doc2.tex
is the .tex file that contains the details of the graph I want to build.
Best Answer
This doesn't have anything to do with
book
vs.article
, the problem here is the use of thedvips
option forgraphicx
. Presumably you're not generating the PDF by first making a DVI-file, then usingdvips
to make a PostScript-file, and thenps2pdf
to make a PDF.In general, I think it's best to not specify the driver (such as
dvips
) forgraphicx
TikZ actually loads
graphicx
for you, so just removing the line\usepackage[dvips]{graphicx}
will do. Test the example below with and without the commented line to see.Unrelated: Note that the
right of=
syntax is considered deprecated, see e.g. Difference between "right of=" and "right=of" in PGF/TikZ