我试图将 3 个数字并排放置,但使用子图却将它们放在一列中。我做错了吗?这是我的代码:

我试图将 3 个数字并排放置,但使用子图却将它们放在一列中。我做错了吗?这是我的代码:
\documentclass[12pt]{article}

\usepackage{tikz}
\usepackage{amsmath} 
\usepackage{bm}
\usepackage{amssymb}
\usepackage{subcaption}
\usetikzlibrary{decorations.markings}

\usepackage[a4paper,textwidth=17cm,textheight=23cm]{geometry}

\begin{document}

\begin{figure} 
\begin{subfigure}[b]{0.30\textwidth}
\centering
\begin{tikzpicture}[decoration={markings,
  mark=between positions 0 and 1 step 25pt
  with { \draw [fill] (0,0) circle [radius=2pt];}}]
\path[postaction={decorate}] (0,4) to (4,4);
\path[postaction={decorate}] (0,3) to (4,3);
\path[postaction={decorate}] (0,2) to (4,2);
\path[postaction={decorate}] (0,1) to (4,1);
\path[postaction={decorate}] (0,0) to (4,0);
\draw [<->] (2.3,2) -- (1.75,2) -- (1.75,2.65);
\draw [dashed] (0, 1.5) -- (4,1.5);
\draw [dashed] (0, 2.5) -- (4,2.5);
\end{tikzpicture}
\label{lattice1}
\end{subfigure}

\begin{subfigure}[b]{0.30\textwidth}
\centering
\begin{tikzpicture}[decoration={markings,
  mark=between positions 0 and 1 step 25pt
  with { \draw [fill] (0,0) circle [radius=2pt];}}]
\path[postaction={decorate}] (0,4) to (4,4);
\path[postaction={decorate}] (0,3) to (4,3);
\path[postaction={decorate}] (0,2) to (4,2);
\path[postaction={decorate}] (0,1) to (4,1);
\path[postaction={decorate}] (0,0) to (4,0);
\draw [<->] (2.3,2) -- (1.75,2) -- (1.75,2.65);
\draw [dashed] (1.25,0) -- (1.25,4);
\draw [dashed] (2.25,0) -- (2.25,4);
\end{tikzpicture}
\label{lattice2}
\end{subfigure}

\begin{subfigure}[b]{0.30\textwidth}
\centering
\begin{tikzpicture}[decoration={markings,
  mark=between positions 0 and 1 step 25pt
  with { \draw [fill] (0,0) circle [radius=2pt];}}]
\path[postaction={decorate}] (0,4) to (4,4);
\path[postaction={decorate}] (0,3) to (4,3);
\path[postaction={decorate}] (0,2) to (4,2);
\path[postaction={decorate}] (0,1) to (4,1);
\path[postaction={decorate}] (0,0) to (4,0);
\draw [<->] (2.3,2) -- (1.75,2) -- (1.75,2.65);
\draw [dashed] (1.25,0) -- (1.25,4);
\draw [dashed] (2.25,0) -- (2.25,4);
\draw [dashed] (0, 1.5) -- (4,1.5);
\draw [dashed] (0, 2.5) -- (4,2.5);
\end{tikzpicture}
\label{lattice3}
\end{subfigure}
\end{figure}

\end{document}

答案1

您的问题是实例后的额外行/空格\end{subfigure},请尝试以下操作:

\documentclass[12pt]{article}
\usepackage{tikz} \usepackage{amsmath} \usepackage{bm} \usepackage{amssymb} \usepackage{subcaption} \usetikzlibrary{decorations.markings}
\usepackage[a4paper,textwidth=17cm,textheight=23cm]{geometry}
\begin{document}
    \begin{figure} %
        \begin{subfigure}[b]{0.30\textwidth} \centering \begin{tikzpicture}[decoration={markings, mark=between positions 0 and 1 step 25pt with { \draw [fill] (0,0) circle [radius=2pt];}}] \path[postaction={decorate}] (0,4) to (4,4); \path[postaction={decorate}] (0,3) to (4,3); \path[postaction={decorate}] (0,2) to (4,2); \path[postaction={decorate}] (0,1) to (4,1); \path[postaction={decorate}] (0,0) to (4,0); \draw [<->] (2.3,2) -- (1.75,2) -- (1.75,2.65); \draw [dashed] (0, 1.5) -- (4,1.5); \draw [dashed] (0, 2.5) -- (4,2.5); \end{tikzpicture} \label{lattice1} 
        \end{subfigure} %
        \begin{subfigure}[b]{0.30\textwidth} \centering \begin{tikzpicture}[decoration={markings, mark=between positions 0 and 1 step 25pt with { \draw [fill] (0,0) circle [radius=2pt];}}] \path[postaction={decorate}] (0,4) to (4,4); \path[postaction={decorate}] (0,3) to (4,3); \path[postaction={decorate}] (0,2) to (4,2); \path[postaction={decorate}] (0,1) to (4,1); \path[postaction={decorate}] (0,0) to (4,0); \draw [<->] (2.3,2) -- (1.75,2) -- (1.75,2.65); \draw [dashed] (1.25,0) -- (1.25,4); \draw [dashed] (2.25,0) -- (2.25,4); \end{tikzpicture} \label{lattice2} 
        \end{subfigure} %
        \begin{subfigure}[b]{0.30\textwidth} \centering \begin{tikzpicture}[decoration={markings, mark=between positions 0 and 1 step 25pt with { \draw [fill] (0,0) circle [radius=2pt];}}] \path[postaction={decorate}] (0,4) to (4,4); \path[postaction={decorate}] (0,3) to (4,3); \path[postaction={decorate}] (0,2) to (4,2); \path[postaction={decorate}] (0,1) to (4,1); \path[postaction={decorate}] (0,0) to (4,0); \draw [<->] (2.3,2) -- (1.75,2) -- (1.75,2.65); \draw [dashed] (1.25,0) -- (1.25,4); \draw [dashed] (2.25,0) -- (2.25,4); \draw [dashed] (0, 1.5) -- (4,1.5); \draw [dashed] (0, 2.5) -- (4,2.5); \end{tikzpicture} \label{lattice3} 
        \end{subfigure} %
    \end{figure}
\end{document}

通过用符号结束关键行(例如,小页面也需要这样做)%,任何后续的空格都会被忽略,直到下一行开始。

在此处输入图片描述

相关内容