3 張並排的 tikz 圖片並配有標題

3 張並排的 tikz 圖片並配有標題

我想像這樣並排獲得 3 張 tikz 圖片,但是每個下面都有標題:

\documentclass[a4paper,12pt]{article}
\usepackage[a4paper, margin=2cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[spanish,es-tabla]{babel}
\usepackage{tikz}
\usepackage{tkz-tab}
\usepackage{caption}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{subcaption} 
\usetikzlibrary{quotes,angles,babel}

\begin{document}
     \begin{tikzpicture}
        \coordinate (O) at (0,0);
        \draw [->,>=stealth,thick] (0,0) -- (3,0) coordinate (xpos) node[right, at end] {\large{x}};
        \draw [<-,>=stealth,thick] (0,3)coordinate (NM) node[right] {NM} node[left] {y}  -- (0,0) coordinate (SM);
        \draw [->,>=stealth,thick] (O)  -- (-2,-2) coordinate (rumbo);
        \path pic["HDG",draw=red,<-,>=stealth,thick,angle eccentricity=1.2,angle radius=2cm,pic text options={shift={(+.3cm,0)}}] {angle=rumbo--O--NM};
        \path pic["-$\alpha$",draw=blue,<-,>=stealth,thick,angle eccentricity=1.2,angle radius=1cm] {angle=rumbo--O--xpos};
    \end{tikzpicture}
    %\captionof{figure}{$\alpha$=BLA}
    \hspace{1cm}
    \begin{tikzpicture}
        \coordinate (O) at (0,0);
        \draw [->,>=stealth,thick] (0,0) -- (3,0) coordinate (xpos) node[right, at end] {\large{x}};
        \draw [<-,>=stealth,thick] (0,3)coordinate (NM) node[right] {NM} node[left] {y}  -- (0,0) coordinate (SM);
        \draw [->,>=stealth,thick] (O)  -- (-2,2) coordinate (rumbo);
        \path pic["HDG",draw=red,<-,>=stealth,thick,angle eccentricity=1.2,angle radius=2cm,pic text options={shift={(0,1.25cm)}}] {angle=rumbo--O--NM};
        \path pic["$\alpha$",draw=blue,->,>=stealth,thick,angle eccentricity=1.2,angle radius=1cm] {angle=xpos--O--rumbo};
    \end{tikzpicture}
    \hspace{1cm}
    \begin{tikzpicture}
        \coordinate (O) at (0,0);
        \draw [->,>=stealth,thick] (0,0) -- (3,0) coordinate (xpos) node[right, at end] {\large{x}};
        \draw [<-,>=stealth,thick] (0,3)coordinate (NM) node[right] {NM} node[left] {y}  -- (0,0) coordinate (SM);
        \draw [->,>=stealth,thick] (O)  -- (2,2) coordinate (rumbo);
        \draw [->,>=stealth,thick,white] (O)  -- (0,-2.2cm);
        \path pic["\small{HDG}",draw=red,<-,>=stealth,thick,angle eccentricity=1.2,angle radius=2cm] {angle=rumbo--O--NM};
        \path pic["$\alpha$",draw=blue,->,>=stealth,thick,angle eccentricity=1.2,angle radius=1cm] {angle=xpos--O--rumbo};
    \end{tikzpicture}
\end{document}

我也嘗試過以下這個答案,但我無法找到為什麼 \resizebox 不允許我的程式碼編譯,我嘗試使用 \graphicx 但沒有成功,還在 {.如果你嘗試在沒有 \resizebox 的情況下執行此操作,它不會垂直對齊,結束如下:

在此輸入影像描述

最後,正如您在程式碼 (%\captionof{figure}{$\alpha$=BLA}) 中看到的,我嘗試使用 \captionof 解決方案,但最終給出了一個完全奇怪的解決方案:

在此輸入影像描述

答案1

您已經在加載,subcaption因此您可能想要使用它。

\documentclass[a4paper,12pt]{article}
\usepackage[a4paper, margin=2cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[spanish,es-tabla]{babel}
\usepackage{tikz}
\usepackage{tkz-tab}
\usepackage{caption}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{subcaption} 
\usetikzlibrary{quotes,angles,babel}

\begin{document}
\begin{figure}
\centering
\begin{subfigure}{.34\textwidth}
    \centering
     \begin{tikzpicture}
        \coordinate (O) at (0,0);
        \draw [->,>=stealth,thick] (0,0) -- (3,0) coordinate (xpos) node[right, at end] {\large{x}};
        \draw [<-,>=stealth,thick] (0,3)coordinate (NM) node[right] {NM} node[left] {y}  -- (0,0) coordinate (SM);
        \draw [->,>=stealth,thick] (O)  -- (-2,-2) coordinate (rumbo);
        \path pic["HDG",draw=red,<-,>=stealth,thick,angle eccentricity=1.2,angle radius=2cm,pic text options={shift={(+.3cm,0)}}] {angle=rumbo--O--NM};
        \path pic["-$\alpha$",draw=blue,<-,>=stealth,thick,angle eccentricity=1.2,angle radius=1cm] {angle=rumbo--O--xpos};
    \end{tikzpicture}
    \caption{$\alpha$=BLA}
\end{subfigure}
\hfill
\begin{subfigure}{.34\textwidth}
    \centering
    \begin{tikzpicture}
        \coordinate (O) at (0,0);
        \draw [->,>=stealth,thick] (0,0) -- (3,0) coordinate (xpos) node[right, at end] {\large{x}};
        \draw [<-,>=stealth,thick] (0,3)coordinate (NM) node[right] {NM} node[left] {y}  -- (0,0) coordinate (SM);
        \draw [->,>=stealth,thick] (O)  -- (-2,2) coordinate (rumbo);
        \path pic["HDG",draw=red,<-,>=stealth,thick,angle eccentricity=1.2,angle radius=2cm,pic text options={shift={(0,1.25cm)}}] {angle=rumbo--O--NM};
        \path pic["$\alpha$",draw=blue,->,>=stealth,thick,angle eccentricity=1.2,angle radius=1cm] {angle=xpos--O--rumbo};
    \end{tikzpicture}
    \caption{$\alpha$=PFT}
\end{subfigure}
\hfill
\begin{subfigure}{.27\textwidth}
    \centering
    \begin{tikzpicture}
        \coordinate (O) at (0,0);
        \draw [->,>=stealth,thick] (0,0) -- (3,0) coordinate (xpos) node[right, at end] {\large{x}};
        \draw [<-,>=stealth,thick] (0,3)coordinate (NM) node[right] {NM} node[left] {y}  -- (0,0) coordinate (SM);
        \draw [->,>=stealth,thick] (O)  -- (2,2) coordinate (rumbo);
        \draw [->,>=stealth,thick,white] (O)  -- (0,-2.2cm);
        \path pic["\small{HDG}",draw=red,<-,>=stealth,thick,angle eccentricity=1.2,angle radius=2cm] {angle=rumbo--O--NM};
        \path pic["$\alpha$",draw=blue,->,>=stealth,thick,angle eccentricity=1.2,angle radius=1cm] {angle=xpos--O--rumbo};
    \end{tikzpicture}
    \caption{$\alpha$=BLUB}
\end{subfigure}
\caption{Meow.}
\end{figure}    
\end{document}

在此輸入影像描述

答案2

如果您希望將這些數字標記為數字(而不是子數字),您可以使用環境floatrow

    \documentclass[a4paper,12pt]{article}
    \usepackage[a4paper, margin=2cm]{geometry}
    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
    \usepackage[spanish,es-tabla, es-noshorthands]{babel}
    \usepackage{tikz}
    \usepackage{tkz-tab}
    \usepackage{caption}
    \usepackage{latexsym}
    \usepackage{amssymb}
    \usepackage{amsmath}
    \usepackage{subcaption}
    \usetikzlibrary{quotes,angles,babel}
    \usepackage{floatrow}

    \begin{document}

    \begin{figure}
    \begin{floatrow}[3]
    \ffigbox[\FBwidth]{\caption{$\alpha$=BLA}\label{bla}}{%
         \begin{tikzpicture}
            \coordinate (O) at (0,0);
            \draw [->,>=stealth,thick] (0,0) -- (3,0) coordinate (xpos) node[right, at end] {\large{x}};
            \draw [<-,>=stealth,thick] (0,3)coordinate (NM) node[right] {NM} node[left] {y} -- (0,0) coordinate (SM);
            \draw [->,>=stealth,thick] (O) -- (-2,-2) coordinate (rumbo);
            \path pic["HDG",draw=red,<-,>=stealth,thick,angle eccentricity=1.2,angle radius=2cm,pic text options={shift={(+.3cm,0)}}] {angle=rumbo--O--NM};
            \path pic["-$\alpha$",draw=blue,<-,>=stealth,thick,angle eccentricity=1.2,angle radius=1cm] {angle=rumbo--O--xpos};
        \end{tikzpicture}}%
    %
    \ffigbox[\FBwidth]{\caption{$\beta$=BLI}\label{bli}}{%
        \begin{tikzpicture}
            \coordinate (O) at (0,0);
            \draw [->,>=stealth,thick] (0,0) -- (3,0) coordinate (xpos) node[right, at end] {\large{x}};
            \draw [<-,>=stealth,thick] (0,3)coordinate (NM) node[right] {NM} node[left] {y} -- (0,0) coordinate (SM);
            \draw [->,>=stealth,thick] (O) -- (-2,2) coordinate (rumbo);
            \path pic["HDG",draw=red,<-,>=stealth,thick,angle eccentricity=1.2,angle radius=2cm,pic text options={shift={(0,1.25cm)}}] {angle=rumbo--O--NM};
            \path pic["$\alpha$",draw=blue,->,>=stealth,thick,angle eccentricity=1.2,angle radius=1cm] {angle=xpos--O--rumbo};
        \end{tikzpicture}}%
        %
    \ffigbox[\FBwidth]{\caption{$\gamma$=BLO}\label{blo}}{%
        \begin{tikzpicture}
            \coordinate (O) at (0,0);
            \draw [->,>=stealth,thick] (0,0) -- (3,0) coordinate (xpos) node[right, at end] {\large{x}};
            \draw [<-,>=stealth,thick] (0,3)coordinate (NM) node[right] {NM} node[left] {y} -- (0,0) coordinate (SM);
            \draw [->,>=stealth,thick] (O) -- (2,2) coordinate (rumbo);
            \draw [->,>=stealth,thick,white] (O) -- (0,-2.2cm);
            \path pic["\small{HDG}",draw=red,<-,>=stealth,thick,angle eccentricity=1.2,angle radius=2cm] {angle=rumbo--O--NM};
            \path pic["$\alpha$",draw=blue,->,>=stealth,thick,angle eccentricity=1.2,angle radius=1cm] {angle=xpos--O--rumbo};
        \end{tikzpicture}}%
       % \hspace{1cm}
    \end{floatrow}
    \end{figure}

    \end{document} 

在此輸入影像描述

相關內容