tikzpicture 的標題錯位

tikzpicture 的標題錯位

\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[...]嚴重錯位:

氣象站的輸出

此時我完全迷失了,因為在投影機類別中使用完全相同的程式碼效果非常好。

我想避免使用包包subfiguresubcaption.我在某處讀到,將子浮點包裝在小型頁面中可能是個好主意,但它不起作用。

對此有什麼想法嗎?

編輯 我使用 @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 腳本文件:

請注意,\setcapwidthwidth立即設定為參數寬度的值,就像\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}

結果:

在此輸入影像描述

相關內容