PGFplots in Kombination mit subcaption Thema ist als GELÖST markiert

Tabellen und Grafiken erstellen und anordnen


Udo

PGFplots in Kombination mit subcaption

Beitrag von Udo »

Hallo,

ich möchte mit dem Paket "subcaption" zwei pgfplots nebeneinander setzen.

Wenn ich das mache:
\documentclass{article}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc} 
\usepackage{subcaption}
\usepackage{tikz} 
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{figure}[!htb]
	\centering
	\subcaptionbox{Bild1\label{bild1}}{%
	\begin{tikzpicture}
	\begin{axis}[enlargelimits=0.2]
		\addplot+[nodes near coords,only marks,point meta=explicit symbolic] table[meta=label] {
		x    y   label
		0.5  0.2 1
		0.2  0.1 t2
		0.7  0.6 3
		0.35 0.4 Y4
		0.65 0.1 5
		};
		\end{axis}
	\end{tikzpicture}
	}%
	\subcaptionbox{Bild2\label{bild2}}{%
	\begin{tikzpicture}
	\begin{axis}[enlargelimits=0.2]
		\addplot+[nodes near coords,only marks,point meta=explicit symbolic] table[meta=label] {
		x    y   label
		0.5  0.2 1
		0.2  0.1 t2
		0.7  0.6 3
		0.35 0.4 Y4
		0.65 0.1 5
		};
		\end{axis}
	\end{tikzpicture}
	}%
	\caption{TestCap}
\end{figure}
\end{document}
kommt der Fehler:
Package pgfplots Error: Could not read table file '" x y label 0 .5 0.2 1 0.2 0.1 t2 0.7 0.6 3 0.35 0.4 Y4 0.65 0.1 5 "' in 'search path=.'. In case you intended to provide inline data: maybe TeX screwed up your end-of-line s? Try `row sep=crcr' and terminate your lines with `\\' (refer to the pgfplots table manual for details). 
Das merkwürdige ist, dass die beiden pgfplots aus der Doku sind und ohne subcaption auch problemlos laufen. Kommentiert man also die zwei Zeilen mit subcaptionbox und der schließenden Klammer aus, funktioniert es:
\documentclass{article}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc} 
\usepackage{subcaption}
\usepackage{tikz} 
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{figure}[!htb]
	\centering
	%\subcaptionbox{Bild1\label{bild1}}{%
	\begin{tikzpicture}
	\begin{axis}[enlargelimits=0.2]
		\addplot+[nodes near coords,only marks,point meta=explicit symbolic] table[meta=label] {
		x    y   label
		0.5  0.2 1
		0.2  0.1 t2
		0.7  0.6 3
		0.35 0.4 Y4
		0.65 0.1 5
		};
		\end{axis}
	\end{tikzpicture}
	%}%
	%\subcaptionbox{Bild2\label{bild2}}{%
	\begin{tikzpicture}
	\begin{axis}[enlargelimits=0.2]
		\addplot+[nodes near coords,only marks,point meta=explicit symbolic] table[meta=label] {
		x    y   label
		0.5  0.2 1
		0.2  0.1 t2
		0.7  0.6 3
		0.35 0.4 Y4
		0.65 0.1 5
		};
		\end{axis}
	\end{tikzpicture}
	%}%
	\caption{TestCap}
\end{figure}
\end{document}
Weiß jemand, warum das so ist?

Gruß Udo

Bartman
Forum-Meister
Forum-Meister
Beiträge: 2456
Registriert: Do 16. Jul 2009, 21:41
Wohnort: Hessische Provinz

Beitrag von Bartman »

Mein Beispiel funktioniert bei Overleaf. Auf meinem aktuellen MiKTeX-System habe ich es nicht getestet.
\documentclass{article}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc} 
\usepackage{subcaption}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{figure}[!htb]
   \centering
   \subcaptionbox{Bild1\label{bild1}}{%
   \begin{tikzpicture}
   \begin{axis}[enlargelimits=0.2]
      \addplot+[nodes near coords,only marks,point meta=explicit symbolic,table/row sep=crcr] table[meta=label] {
      x    y   label\\
      0.5  0.2 1\\
      0.2  0.1 t2\\
      0.7  0.6 3\\
      0.35 0.4 Y4\\
      0.65 0.1 5\\
      };
      \end{axis}
   \end{tikzpicture}
   }%
   \subcaptionbox{Bild2\label{bild2}}{%
   \begin{tikzpicture}
   \begin{axis}[enlargelimits=0.2]
      \addplot+[nodes near coords,only marks,point meta=explicit symbolic,table/row sep=crcr] table[meta=label] {
      x    y   label\\
      0.5  0.2 1\\
      0.2  0.1 t2\\
      0.7  0.6 3\\
      0.35 0.4 Y4\\
      0.65 0.1 5\\
      };
      \end{axis}
   \end{tikzpicture}
   }%
   \caption{TestCap}
\end{figure}
\end{document}
Quelle: http://tex.stackexchange.com/questions/331275

Udo

Beitrag von Udo »

Hallo,

Danke, so funktioniert es zwar, aber ich habe mehrere tausend Messwerte und kann nicht überall händisch dieses \\ hinzufügen.

Ich habe jetzt subcaptionbox durch
\begin{subfigure}[b]{.49\linewidth}
\centering\large A
\caption{A subfigure}\label{fig:1a}
\end{subfigure}%
ersetzt. Damit tritt komischerweise kein Fehler auf.
Verglichen zu subcaptionbox dürfte das ja kein Unterschied machen, oder?

Gruß Udo

Antworten