3

Probably got some obvious error

\documentclass{article}
\usepackage{tikz-qtree} % <- this wont work

\usepackage[utf8]{inputenc}
\usepackage[german]{babel}
\usepackage[margin=0.5in]{geometry}

\begin{document}
\end{document}

produces

Latex Error: Two \documentclass or \documentstyle commands.

on several editors whatsoever.

Got 2013.20140215-1 texlive-pictures installed. Adding \usepackage{tikz} doesn't help.

Probably I am missing something obvious. Do you have any suggestions?

5
  • 1
    Welcome. \usepackage{tikz-qtree}. It is a package not a class. Your document can have only one class but many packages!
    – cfr
    Jun 19, 2015 at 20:49
  • The posted document runs without error. If you get an error from that post the full log. Jun 19, 2015 at 20:57
  • @DavidCarlisle The original had \documentclass{tikz-qtree} but it is edited away within the 5 mins so no longer makes sense.
    – cfr
    Jun 19, 2015 at 20:59
  • 1
    @cfr my guess would be OP has while editing saved a document as tikz-qtree.sty so gets the error but would need to see the log... Jun 19, 2015 at 21:11
  • 1
    @DavidCarlisle This is almost certainly correct, since tikz-qtree is a wrapper for tikz-qtree.tex.
    – Alan Munn
    Jun 19, 2015 at 22:22

1 Answer 1

6

Originally, you had

\documentclass{article}
\documentclass{tikz-qtree}
...

A LaTeX document can only have one class as the error says. But you can also load packages to extend the functionality of the class. tikz-qtree is not a document class at all: it is a package. So, you want:

\documentclass{article}
\usepackage{tikz-qtree}
...

EDIT

After correcting the problem above, you continued to report the same error. This was somewhat puzzling but AlanMunn held the key to this mystery.

As explained by AlanMunn in comments, the package tikz-qtree loads a code file named tikz-qtree.tex. Because your document was itself called tikz-qtree.tex, LaTeX tried to read the document a second time when the package called the code file.

This happens because files in the current directory take precedence over those elsewhere, so LaTeX read your document tikz-qtree.tex rather than the code file tikz-qtree.tex.

Hence, it really did get two \documentclass commands as input - they just both happened to be from the single instance in your document.

I don't know if there is a moral to this story other than that AlanMunn knows everything there is to know about packages which draw trees, but at least it dispels the mystery.

10
  • Yes, I am just unsure why this produces that kind of error and how to fix this, because I'd like to use that package
    – sams2
    Jun 19, 2015 at 20:54
  • @sams2 Originally, you had 2 \documentclass commands. That caused that error. You shouldn't get that error now you've changed the second, tikz-qtree, one to \usepackage.
    – cfr
    Jun 19, 2015 at 20:57
  • Even <code> \documentclass{article} \usepackage{tikz-qtree} \begin{document} \end{document} </code> produces the same error
    – sams2
    Jun 19, 2015 at 21:00
  • @sams2 It shouldn't. It doesn't for me. As David says, if it does for you, we need the log.
    – cfr
    Jun 19, 2015 at 21:01
  • 3
    @sam2 The subsequent problem arose because your test file was named tikz-qtree.tex which is also the name of the code file that the tikz-qtree package uses. This is not something you could have easily forseen.
    – Alan Munn
    Jun 19, 2015 at 22:34

Not the answer you're looking for? Browse other questions tagged .