子图不会并排显示

子图不会并排显示

我在将两张 tikzpicture 并排对齐时遇到了问题。似乎我尝试的所有方法都无法阻止它们堆叠在一起。

这是一个 MWE,第二个 tikzpicture 是一个圆圈,只是为了显示问题。

\documentclass[a4paper]{article}
\usepackage{geometry}
\geometry{left=20mm,right=20mm,top=20mm,bottom=20mm}

\usepackage[font=small, labelfont=bf, labelsep=space, justification=centering]{caption}
\usepackage[list=true]{subcaption}

\usepackage{tikz}
\usetikzlibrary{angles}
\usetikzlibrary{arrows}
\usetikzlibrary{quotes}
\usepackage{tkz-euclide}

\begin{document}

\begin{figure}[h]
    \centering
    \subcaptionbox{Sezione del cilindro, $h>d$.\label{fig:h>d}}{
        \centering
        \resizebox{0.45\textwidth}{!}{
            \begin{tikzpicture}%[scale=]
                \begin{scope}[rotate = 30]
                    \draw[black, thick] (0,0) rectangle (6,4);
                    \draw[black, thick, loosely dotted] (-0.5,2) -- (6.35,2);
                    \draw[black, thick, loosely dotted] (3,-0.5) -- (3,4.5);
                    \draw[black, loosely dashed] (3,2) -- (1.85,0);
                    \filldraw[black] (0,2) circle (2pt) node[anchor=east] {M \quad};
                    \filldraw[black] (1.85,0) circle (2pt) node[anchor=north] {\quad T};
                    \filldraw[black] (3,2) circle (2pt) node[anchor=west] {CDM};
                    \filldraw[black] (0,0) circle (2pt) coordinate(P) node[anchor=north] {P$=(0,0)$};
                    \filldraw[black] (0,4) circle (2pt) node[anchor=east] {A};
                    \filldraw[black] (6,0) circle (2pt) coordinate(B) node[anchor=north west] {B};
                    \filldraw[black] (6,4) circle (2pt) node[anchor=south] {C};
                    
                    \draw[|-|] (6.4, 0) -- (6.4,2) node[anchor=south west] {$d$} -- (6.4,4);
                    \draw[|-|] (0,4.7) -- (3,4.7) node[anchor = south east] {$h$} -- (6,4.7);
                \end{scope}
                \draw[black, loosely dashed, ->] (0,0) -- (0,5.3) node[anchor = north west] {$y$};
                \filldraw[black] (0,4.625) circle (2pt) node[anchor=south east] {Q};
                \draw[black, loosely dashed, ->] (-1.5,0) -- (2,0) coordinate(G) node[anchor = west] {$x$};
                \pic["$\alpha$",draw=black,thick,<->,angle eccentricity=1.2,angle radius=1.2cm] {angle=G--P--B};
            \end{tikzpicture}
        }
    }
    
    \hfill
    
    \subcaptionbox{Sezione del cilindro, $h<d$.\label{fig:h<d}}{
        \centering
        \resizebox{0.45\textwidth}{!}{
            \begin{tikzpicture}[scale=0.2]
                \filldraw[black] (0,0) circle (2pt);
            \end{tikzpicture}
        }
    }
\end{figure}

\end{document}

非常感谢您的帮助。我真的不知道问题出在哪里。 并列问题

答案1

让我解释一下我的评论:您需要删除subcaptionboxes 之间的空行。它会开始新的行。

一些题外话:

  • 我不会用\resizebox
  • 左图的代码也可以按照以下(简洁)的方式编写:
\documentclass[a4paper]{article}
\usepackage[margin=20mm]{geometry}

\usepackage[font=small, labelfont=bf, labelsep=space, justification=centering]{caption}
\usepackage[list=true]{subcaption}

\usepackage{tikz}
\usetikzlibrary{angles, arrows,
                quotes}
\usepackage{tkz-euclide} % not used in this image

\begin{document}
    \begin{figure}[h]
\centering
    \subcaptionbox{Sezione del cilindro, $h>d$.\label{fig:h>d}}{
            \begin{tikzpicture}[
            dot/.style = {circle, fill=red, minimum size=5pt, inner sep=0pt}
                                ]
                \begin{scope}[rotate = 30]
                    \draw[thick] (0,0) rectangle (6,4);
                    \draw[thick, loosely dotted] (-0.5,2) -- (6.35,2);
                    \draw[thick, loosely dotted] (3,-0.5) -- (3,4.5);
                    \draw[loosely dashed] (3,2) -- (1.85,0);
                    \node[dot,label= left:N] at (0,2) {}; 
                    \node[dot,label=below:T] at (1.85,0) {};
                    \node[dot,label=right:CDM] at (3,2) {};
                    \node (P) [dot,label=below:{P$=(0,0)$}] at (0,0) {};
                    \node[dot,label= left:A] at (0,4) {};
                    \node (B) [dot,label=right:B] at (6,0) {};
                    \node[dot,label=above:C] at (6,4) {};

                    \draw[|-|] (6.4, 0) to ["$d$" '] (6.4,4);
                    \draw[|-|] (0,4.7)  to ["$h$"] (6,4.7);
                \end{scope}
                \draw[loosely dashed, ->] (0,0)  -- (0,5.3) node[anchor = north west] {$y$};
                \draw[loosely dashed, ->] (-1.5,0) -- (2,0) node (G)[anchor = west]  {$x$};               \node[dot,label=above left:Q] at (0,4.625) {};
                
                \pic["$\alpha$",draw,thick,<->,angle eccentricity=1.2,angle radius=1.2cm] {angle=G--P--B};
            \end{tikzpicture}
    }
    \hfil
    \subcaptionbox{Sezione del cilindro, $h<d$.\label{fig:h<d}}{
        %\resizebox{0.45\textwidth}{!}{
            \begin{tikzpicture}%[scale=10]
                \filldraw[black] (0,0) circle (20pt);
            \end{tikzpicture}
        %}
    }
    \end{figure}
\end{document}

在此处输入图片描述

答案2

正如扎科所说。

\documentclass[a4paper]{article}
\usepackage{geometry}
\geometry{left=20mm,right=20mm,top=20mm,bottom=20mm}

\usepackage[font=small, labelfont=bf, labelsep=space, justification=centering]{caption}
\usepackage[list=true]{subcaption}

\usepackage{tikz}
\usetikzlibrary{angles}
\usetikzlibrary{arrows}
\usetikzlibrary{quotes}
\usepackage{tkz-euclide}

\begin{document}

\begin{figure}[h]
    \centering
    \subcaptionbox{Sezione del cilindro, $h>d$.\label{fig:h>d}}{
        \centering
        \resizebox{0.45\textwidth}{!}{
            \begin{tikzpicture}%[scale=]
                \begin{scope}[rotate = 30]
                    \draw[black, thick] (0,0) rectangle (6,4);
                    \draw[black, thick, loosely dotted] (-0.5,2) -- (6.35,2);
                    \draw[black, thick, loosely dotted] (3,-0.5) -- (3,4.5);
                    \draw[black, loosely dashed] (3,2) -- (1.85,0);
                    \filldraw[black] (0,2) circle (2pt) node[anchor=east] {M \quad};
                    \filldraw[black] (1.85,0) circle (2pt) node[anchor=north] {\quad T};
                    \filldraw[black] (3,2) circle (2pt) node[anchor=west] {CDM};
                    \filldraw[black] (0,0) circle (2pt) coordinate(P) node[anchor=north] {P$=(0,0)$};
                    \filldraw[black] (0,4) circle (2pt) node[anchor=east] {A};
                    \filldraw[black] (6,0) circle (2pt) coordinate(B) node[anchor=north west] {B};
                    \filldraw[black] (6,4) circle (2pt) node[anchor=south] {C};
                    
                    \draw[|-|] (6.4, 0) -- (6.4,2) node[anchor=south west] {$d$} -- (6.4,4);
                    \draw[|-|] (0,4.7) -- (3,4.7) node[anchor = south east] {$h$} -- (6,4.7);
                \end{scope}
                \draw[black, loosely dashed, ->] (0,0) -- (0,5.3) node[anchor = north west] {$y$};
                \filldraw[black] (0,4.625) circle (2pt) node[anchor=south east] {Q};
                \draw[black, loosely dashed, ->] (-1.5,0) -- (2,0) coordinate(G) node[anchor = west] {$x$};
                \pic["$\alpha$",draw=black,thick,<->,angle eccentricity=1.2,angle radius=1.2cm] {angle=G--P--B};
            \end{tikzpicture}
        }%
    }%  
    \subcaptionbox{Sezione del cilindro, $h<d$.\label{fig:h<d}}{
        \centering
        \resizebox{0.45\textwidth}{!}{
            \begin{tikzpicture}[scale=0.2]
                \filldraw[black] (0,0) circle (2pt);
            \end{tikzpicture}
        }
    }
\end{figure}

\end{document}

在此处输入图片描述

相关内容