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?

10
  • 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, 2017 at 9:59
  • You may want to have a look at this question: tex.stackexchange.com/questions/337939/aligning-4-figures/… . 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, 2017 at 10:03
  • @Bobyandbob Exactly. The program cannot find file: File `TikZ/QuadrateResiduenParabola' not found. ...mm, clip]{TikZ/QuadrateResiduenParabola}}
    – ingenium
    Feb 13, 2017 at 10:08
  • @DRi Sure, for one figure it doesn't make any sense. Corrected.
    – ingenium
    Feb 13, 2017 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, 2017 at 10:17

1 Answer 1

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}
3
  • Thanks for your detailed answer, but I still get the error message: [link] (w18i.imgup.net/unknown15a9.png)
    – ingenium
    Feb 13, 2017 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. Feb 13, 2017 at 12:40
  • Oh, I overlooked that. It works. Thank you very much.
    – ingenium
    Feb 13, 2017 at 12:45

You must log in to answer this question.

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