\subfloat
在使用 tikzpicture 时,我无法放置子字幕。
这是我的 MWE:
\documentclass[a4paper,
11pt,
ngerman]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{caption}
\setkomafont{captionlabel}{\small\bfseries}
\setkomafont{caption}{\small}
\setcapindent{0em}
\setcapwidth{0.9\textwidth}
\captionsetup[subfigure]{font={footnotesize},labelfont={bf,footnotesize}}
\usepackage{tikz}
\usetikzlibrary{trees}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{patterns}
\usetikzlibrary{arrows}
\begin{document}
\tikzset{
momentum/.style={postaction={decorate},
decoration={markings, mark=at position 1 with {\arrow[scale=0.8]{>}}}},
}
\begin{figure}[tb]
\subfloat[Winkel zwischen 1 und 3 am kleinsten]{
\centering
\begin{tikzpicture}[font=\small,scale=0.3]
\centering
\draw[momentum](5,5)--(5,1);
\node[anchor=north]at(5,1){2};
\draw[momentum](5,5)--(4,9);
\node[anchor=east]at(4,9){1};
\draw[momentum](5,5)--(6,9);
\node[anchor=west]at(6,9){3};
\end{tikzpicture}
} \hspace{1cm}
\subfloat[Winkel zwischen 2 und 3 am kleinsten]{
\centering
\begin{tikzpicture}[font=\small,scale=0.3]
\centering
\draw[momentum](5,5)--(5,1);
\node[anchor=north]at(5,1){1};
\draw[momentum](5,5)--(4,9);
\node[anchor=east]at(4,9){2};
\draw[momentum](5,5)--(6,9);
\node[anchor=west]at(6,9){3};
\end{tikzpicture}
} \hspace{1cm}
\subfloat[Alle Winkel etwa gleich groß]{
\centering
\begin{tikzpicture}[font=\small,scale=0.3]
\centering
\draw[momentum](5,5)--(5,1);
\node[anchor=north]at(5,1){1};
\draw[momentum](5,5)--(1,8);
\node[anchor=east]at(1,8){2};
\draw[momentum](5,5)--(9,8);
\node[anchor=west]at(9,8){3};
\end{tikzpicture} }
\caption{Bildunterschrift}
\end{figure}
\end{document}
它可以编译,但是我设置的子标题\subfloat[...]
却放错了位置:
我现在完全迷失了,因为在 beamer 类中使用完全相同的代码可以完全正常工作。
我想避免使用软件包subfigure
或subcaption
。我读到过将子浮点数包装在迷你页面中可能是一个好主意,但它不起作用。
对此有什么想法吗?
编辑
我找到了一个对我有用的解决方案,使用了@Troy 和@John_Kormylo 的提示,我注释掉了它\setcapwidth{0.9\textwidth}
并将其添加到每个图形和表格中,除了我使用 tikzpicture 的图形和表格中……将其放入\setcapwidth{\textwidth}
有问题的子浮点数中并没有改变任何东西。
答案1
KOMA 类实际上与 不兼容subfig
。您可以改用subcaption
。
\documentclass[
a4paper,
11pt,
ngerman
]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{graphicx}
\usepackage{caption,subcaption}
\setkomafont{captionlabel}{\small\bfseries}
\setkomafont{caption}{\small}
\setcapindent{0em}
\setcapwidth{0.9\textwidth}
\captionsetup[subfigure]{font={footnotesize},labelfont={bf,footnotesize}}
\usepackage{tikz}
\usetikzlibrary{trees}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{patterns}
\usetikzlibrary{arrows}
\tikzset{
momentum/.style={
postaction={decorate},
decoration={
markings,
mark=at position 1 with {\arrow[scale=0.8]{>}},
},
},
}
\begin{document}
\begin{figure}[tb]
\begin{subfigure}[b]{.3\textwidth}
\centering
\begin{tikzpicture}[font=\small,scale=0.3]
\draw[momentum](5,5)--(5,1);
\node[anchor=north]at(5,1){2};
\draw[momentum](5,5)--(4,9);
\node[anchor=east]at(4,9){1};
\draw[momentum](5,5)--(6,9);
\node[anchor=west]at(6,9){3};
\end{tikzpicture}
\caption{Winkel zwischen 1 und 3 am kleinsten}
\end{subfigure}\hfill
\begin{subfigure}[b]{.3\textwidth}
\centering
\begin{tikzpicture}[font=\small,scale=0.3]
\draw[momentum](5,5)--(5,1);
\node[anchor=north]at(5,1){1};
\draw[momentum](5,5)--(4,9);
\node[anchor=east]at(4,9){2};
\draw[momentum](5,5)--(6,9);
\node[anchor=west]at(6,9){3};
\end{tikzpicture}
\caption{Winkel zwischen 2 und 3 am kleinsten}
\end{subfigure}\hfill
\begin{subfigure}[b]{.3\textwidth}
\centering
\begin{tikzpicture}[font=\small,scale=0.3]
\draw[momentum](5,5)--(5,1);
\node[anchor=north]at(5,1){1};
\draw[momentum](5,5)--(1,8);
\node[anchor=east]at(1,8){2};
\draw[momentum](5,5)--(9,8);
\node[anchor=west]at(9,8){3};
\end{tikzpicture}
\caption{Alle Winkel etwa gleich groß}
\end{subfigure}
\caption{Bildunterschrift}
\end{figure}
\end{document}
答案2
从 KOMA-Script 版本 3.20 开始,您可以改用\setcapdynwidth
。\setcapwidth
摘自 KOMA-Script 文档:
请注意,
\setcapwidth
将width
立即设置为参数宽度的值,就像\setlength
会做的那样。如果您想要width
在设置标题时使用的值,则可以使用。如果您使用长度或其他命令作为参数\setcapdynwidth
,结果可能会有所不同。\linewidth
width
\documentclass[a4paper,
11pt,
ngerman]{scrreprt}[2016/05/10]
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{caption}
\setkomafont{captionlabel}{\small\bfseries}
\setkomafont{caption}{\small}
\setcapindent{0em}
\setcapdynwidth{0.9\textwidth}% <- changed, needs KOMA-Script version 3.20
\captionsetup[subfigure]{font={footnotesize},labelfont={bf,footnotesize}}
\usepackage{tikz}
\usetikzlibrary{trees}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{patterns}
\usetikzlibrary{arrows}
\begin{document}
\tikzset{
momentum/.style={postaction={decorate},
decoration={markings, mark=at position 1 with {\arrow[scale=0.8]{>}}}},
}
\begin{figure}[tb]
\subfloat[Winkel zwischen 1 und 3 am kleinsten]{
\centering
\begin{tikzpicture}[font=\small,scale=0.3]
\centering
\draw[momentum](5,5)--(5,1);
\node[anchor=north]at(5,1){2};
\draw[momentum](5,5)--(4,9);
\node[anchor=east]at(4,9){1};
\draw[momentum](5,5)--(6,9);
\node[anchor=west]at(6,9){3};
\end{tikzpicture}
} \hspace{1cm}
\subfloat[Winkel zwischen 2 und 3 am kleinsten]{
\centering
\begin{tikzpicture}[font=\small,scale=0.3]
\centering
\draw[momentum](5,5)--(5,1);
\node[anchor=north]at(5,1){1};
\draw[momentum](5,5)--(4,9);
\node[anchor=east]at(4,9){2};
\draw[momentum](5,5)--(6,9);
\node[anchor=west]at(6,9){3};
\end{tikzpicture}
} \hspace{1cm}
\subfloat[Alle Winkel etwa gleich groß]{
\centering
\begin{tikzpicture}[font=\small,scale=0.3]
\centering
\draw[momentum](5,5)--(5,1);
\node[anchor=north]at(5,1){1};
\draw[momentum](5,5)--(1,8);
\node[anchor=east]at(1,8){2};
\draw[momentum](5,5)--(9,8);
\node[anchor=west]at(9,8){3};
\end{tikzpicture} }
\caption{Bildunterschrift}
\end{figure}
\end{document}
结果: