我看到之前有人问过这个问题,但似乎没有一个解决方案适用于我的文档。我试图设置一个 2x2 的子图网格,每个子图都填充了一个 tikz 图形。但是,无论我如何调整文本宽度或比例,它们总是一个在另一个下面显示。
\documentclass{article}
\usepackage{tikz}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}[b]{0.4\textwidth}
\centering
\begin{tikzpicture}[scale=0.4]
\node[circle,draw]{$x$}
;
\end{tikzpicture}
\caption[Ex2]%
{{\small Ex1}}
\end{subfigure}
\quad
\begin{subfigure}[b]{0.4\textwidth}
\centering
\begin{tikzpicture}[scale=0.4]
\node[circle,draw]{$x$}
;
\end{tikzpicture}
\caption[]%
{{\small Ex2}}
\end{subfigure}
\bigskip
\begin{subfigure}[b]{0.4\textwidth}
\centering
\begin{tikzpicture}[scale=0.4]
\node[circle,draw]{$x$}
;
\end{tikzpicture}
\caption[]%
{{\small Ex3}}
\end{subfigure}
\quad
\begin{subfigure}[b]{0.4\textwidth}
\centering
\begin{tikzpicture}[scale=0.4]
\node[circle,draw]{$x$}
;
\end{tikzpicture}
\caption[]%
{{\small Ex4}}
\end{subfigure}
\caption[ Ex ]
{\small A small Ex}
\end{figure}
\end{document}
答案1
该subcaption
包将subfigure
环境之间的空格解释figure
为新行。删除这些环境之间的空格(以及不必要的\quad
和bigskip
)可得到所需的 2x2
\documentclass{article}
\usepackage{tikz}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}[b]{0.4\textwidth}
\centering
\begin{tikzpicture}[scale=0.4]
\node[circle,draw]{$x$}
;
\end{tikzpicture}
\caption[Ex2]%
{{\small Ex1}}
\end{subfigure}
\begin{subfigure}[b]{0.4\textwidth}
\centering
\begin{tikzpicture}[scale=0.4]
\node[circle,draw]{$x$}
;
\end{tikzpicture}
\caption[]%
{{\small Ex2}}
\end{subfigure}
\begin{subfigure}[b]{0.4\textwidth}
\centering
\begin{tikzpicture}[scale=0.4]
\node[circle,draw]{$x$}
;
\end{tikzpicture}
\caption[]%
{{\small Ex3}}
\end{subfigure}
\begin{subfigure}[b]{0.4\textwidth}
\centering
\begin{tikzpicture}[scale=0.4]
\node[circle,draw]{$x$}
;
\end{tikzpicture}
\caption[]%
{{\small Ex4}}
\end{subfigure}
\caption[ Ex ]
{\small A small Ex}
\end{figure}
\end{document}