3

I'm trying to include two TikZ pictures in one figure:

\documentclass[12pt]{scrbook}
\usepackage{tikz}
\usepackage{amsmath,amssymb}
\usepackage{subfigure}

\begin{document}

\begin{figure}[h]
    \begin{subfigure}[b]{0.49\textwidth}
        \centering
        \resizebox{\linewidth}{!}{TikZ/QuadrateResiduenParabola}
     \caption{Text.}
    \end{subfigure}

    \begin{subfigure}[b]{0.49\textwidth}
        \centering
        \resizebox{\linewidth}{!}{TikZ/QuadrateResiduenParaboloid}
     \caption{More text.}
    \end{subfigure}
\end{figure}

\end{document}

Here I get the following error message:

Missing number, treated as zero. \begin{subfigure}[b]{0.49\textwidth}
Illegal unit of measure (pt inserted). \begin{subfigure}[b]{0.49\textwidth}

What is wrong?

ingenium
  • 117
  • The tikz images are both saved and in the folder TikZ? If yes, then you can use `\subfigure[width=0.5\textwidth][]{\includegraphics[width=0.49\textwidth,trim = 0mm 0mm 0mm 0mm, clip]{TikZ/filename}}´. – Bobyandbob Feb 13 '17 at 09:59
  • You may want to have a look at this question: http://tex.stackexchange.com/questions/337939/aligning-4-figures/337942#337942 . By the way, what is the point of using subfigure if you have only one ? It seems to me that you forgot to include the \includegraphics command. – DRi Feb 13 '17 at 10:03
  • @Bobyandbob Exactly. The program cannot find file: File `TikZ/QuadrateResiduenParabola' not found. ...mm, clip]{TikZ/QuadrateResiduenParabola}} – ingenium Feb 13 '17 at 10:08
  • @DRi Sure, for one figure it doesn't make any sense. Corrected. – ingenium Feb 13 '17 at 10:10
  • @ingenium. Is the saved image filetyp for example pdf? It should work if the .tex file is at the same level with the TikZ folder. – Bobyandbob Feb 13 '17 at 10:17
  • @Bobyandbob It is a .tex file. I can include this file in a single figure, so I think it is nothing wrong with the file. And if I add .tex extension, then I get following error message: Unknown graphics extension: .tex. ...clip]{TikZ/QuadrateResiduenParabola.tex}} – ingenium Feb 13 '17 at 10:21
  • @ingenium. You can try to save it as pdf like this: http://tex.stackexchange.com/questions/243935/error-using-tikz-externalize-cant-write-md5-file/352732#352732 (it works for me). You can replace \begin{tikz}... with your .tikz file. And then you can use the subfigures... – Bobyandbob Feb 13 '17 at 10:28
  • @Bobyandbob Thanks for the suggestion, but it should be possible with subfigure. – ingenium Feb 13 '17 at 10:31
  • You probably want \resizebox{\linewidth}{!}{\input{TikZ/QuadrateResiduenParabola}}. – Torbjørn T. Feb 13 '17 at 10:54
  • But the error is because you're loading the wrong package, you want \usepackage{subcaption}, not \usepackage{subfigure}. – Torbjørn T. Feb 13 '17 at 10:55

1 Answers1

1

There are a few problems with your code:

First, \resizebox just resizes what it is given, it doesn't look for files anywhere. Hence, if you do

\documentclass{article}
\usepackage{graphicx}
\begin{document}
TikZ/QuadrateResiduenParaboloid

\resizebox{\linewidth}{!}{TikZ/QuadrateResiduenParaboloid}
\end{document}

you get

enter image description here

To actually insert the contents of the .tex file, you need \input as well:

\resizebox{\linewidth}{!}{\input{TikZ/QuadrateResiduenParaboloid}}

The second is that you've loaded the wrong package for subfloats. The subfigure package that you've loaded does not define a subfigure environment, it defines a \subfigure macro, that is used as \subfigure[<list entry>][<subcaption>]{<figure>}. But that package is considered deprecated, so you shouldn't use it.

The syntax you have used is actually defined by the subcaption package, so you should replace \usepackage{subfigure} with \usepackage{subcaption}.

And finally, an empty line signifies a paragraph break, also inside a figure environment, so you need to remove the one between the subfigure environments, otherwise they will end up one above the other.

Complete code:

\documentclass[12pt]{scrbook}
\usepackage{tikz}
\usepackage{amsmath,amssymb}
\usepackage{subcaption}

\begin{document}

\begin{figure}[h]
    \begin{subfigure}[b]{0.49\textwidth}
        \centering
        \resizebox{\linewidth}{!}{\input{TikZ/QuadrateResiduenParabola}}
     \caption{Text.}
    \end{subfigure}\hfill
    \begin{subfigure}[b]{0.49\textwidth}
        \centering
        \resizebox{\linewidth}{!}{\input{TikZ/QuadrateResiduenParaboloid}}
     \caption{More text.}
    \end{subfigure}
\end{figure}

\end{document}
Torbjørn T.
  • 206,688
  • Thanks for your detailed answer, but I still get the error message: [link] (https://w18i.imgup.net/unknown15a9.png) – ingenium Feb 13 '17 at 12:29
  • @ingenium The first error tells you that you're loading both the subfigure and subcaption package, and you can't have both. Load only subcaption, as in my example. – Torbjørn T. Feb 13 '17 at 12:40
  • Oh, I overlooked that. It works. Thank you very much. – ingenium Feb 13 '17 at 12:45