2x2 tikzpictures 表格

2x2 tikzpictures 表格

我试图将 4 张 tikzpictures 压缩到文档中较小的空间中。我的解决方案如下:

\documentclass{article}
\usepackage[paperwidth=6in, paperheight=4in]{geometry}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage{multicol}

\begin{document}

Examples

\begin{multicols}{2}

\begin{tikzpicture}[xscale=.5, yscale=.5]
\draw [<->,thick] (0,5) |- (5,0);
\draw [thick] (4,1) --(4,4) node [right] {$A$ is not open in $\mathbb{R}^{2}$.};
\draw [thick, dashed] (4,1) -- (1,1) -- (1,4) -- (4,4);
\draw [fill] (4,1) circle [radius=0.1];
\draw [fill] (4,4) circle [radius=0.1];
\node at (2.5,2.5) {$A$};
\end{tikzpicture}

\begin{tikzpicture}[xscale=.5, yscale=.5]
\draw [<->,thick] (0,5) |- (5,0);
\draw [thick, dashed] (1,1) to [out=90, in=280] (1,4) to [out=30, in=150] (2,3.5) to [out=30, in=200] (4,4) to [out=40, in=90] (5,3) to [out=270, in=90] node [right] {$A$ is open.} (4,1) to [out=180, in=30] (1,1);
\node at (2.5,2.5) {$A$};
\end{tikzpicture}

\begin{tikzpicture}[xscale=.5, yscale=.5]
\draw [<->,thick] (0,5) |- (5,0);
\draw [fill] (4,1) circle [radius=0.1];
\draw [fill] (2,1) circle [radius=0.1];
\draw [fill] (3,5) circle [radius=0.1];
\draw [fill] (1,3) circle [radius=0.1];
\node at (5,3) {$A$ is not open.};
\end{tikzpicture}

$\newline$

\begin{tikzpicture}[xscale=.5, yscale=.5]
\draw [<->,thick] (0,2) |- (5,0);
\draw [ultra thick] (1,0) --(3,0) node [above] {$A$};
\node at (7,-1) {$A$ is not open in $\mathbb{R}^{2}$ but open in $\mathbb{R}$.};
\draw [fill=white] (1,0) circle [radius=0.1];
\draw [fill=white] (3,0) circle [radius=0.1];
\end{tikzpicture}

\end{multicols}

\end{document}

得出的结果为:

我对压缩 4 张 tikzpictures 的 (丑陋) 解决方案。

解决方案包括创建列并将 tikzpictures 放置在列内,并强制它们用 \newline 分隔。

但在我看来,这是一个丑陋的解决方案。我希望能够将 4 张 tikzpicture 放在一个 2x2 的网格中,每张 tikzpicture 在其单元格内水平和垂直居中,并将当前用作标签的每个节点(例如“A 已打开。”)转换为该 tikzpicture 的标题。

我之前尝试过将每个 tikzpicture 放在一个小页面中,但是这样就无法加标题(与浮动和绝对数字有关?),我也尝试过将 \figures 放在 tikzpictures 的小页面中,但显然没有起作用并且很快变得混乱。

有一个简单的解决办法吗?

答案1

虽然tabularx有效,但在这种情况下有点过度了。

\documentclass{article}
\usepackage[paperwidth=7in, paperheight=5in]{geometry}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage[labelformat=empty]{caption}
\usepackage{tabularx}

\begin{document}

Examples
\begin{center}
\begin{minipage}[b]{.5\textwidth}
\centering
\begin{tikzpicture}[xscale=.5, yscale=.5]
\draw [<->,thick] (0,5) |- (5,0);
\draw [thick] (4,1) --(4,4);
\draw [thick, dashed] (4,1) -- (1,1) -- (1,4) -- (4,4);
\draw [fill] (4,1) circle [radius=0.1];
\draw [fill] (4,4) circle [radius=0.1];
\node at (2.5,2.5) {$A$};
\end{tikzpicture}
\captionof{figure}{$A$ is not open in $\mathbb{R}^{2}$.}
\end{minipage}%
\begin{minipage}[b]{.5\textwidth}
\centering
\begin{tikzpicture}[xscale=.5, yscale=.5]
\draw [<->,thick] (0,5) |- (5,0);
\draw [thick, dashed] (1,1) to [out=90, in=280] (1,4) to [out=30, in=150] (2,3.5) to [out=30, in=200] (4,4) to [out=40, in=90] (5,3) to [out=270, in=90] (4,1) to [out=180, in=30] (1,1);
\node at (2.5,2.5) {$A$};
\end{tikzpicture}
\captionof{figure}{$A$ is open.}
\end{minipage}

\medskip

\begin{minipage}[b]{.5\textwidth}
\centering
\begin{tikzpicture}[xscale=.5, yscale=.5]
\draw [<->,thick] (0,5) |- (5,0);
\draw [fill] (4,1) circle [radius=0.1];
\draw [fill] (2,1) circle [radius=0.1];
\draw [fill] (3,5) circle [radius=0.1];
\draw [fill] (1,3) circle [radius=0.1];
\end{tikzpicture}
\captionof{figure}{$A$ is not open.}
\end{minipage}%
\begin{minipage}[b]{.5\textwidth}
\centering
\begin{tikzpicture}[xscale=.5, yscale=.5]
\draw [<->,thick] (0,2) |- (5,0);
\draw [ultra thick] (1,0) --(3,0) node [above] {$A$};
\draw [fill=white] (1,0) circle [radius=0.1];
\draw [fill=white] (3,0) circle [radius=0.1];
\end{tikzpicture}
\captionof{figure}{$A$ is not open in $\mathbb{R}^{2}$ but open in $\mathbb{R}$.}
\end{minipage}
\end{center}

\end{document}

注意每行%第一个后面的\end{minipage},以避免出现多余的空格。center环境只是为了删除缩进并在“示例”后留出一些空间。

\medskip如果愿意,可以使用其他垂直空间命令代替。

这些\label命令毫无用处,因为您没有对标题进行编号。无论如何,字符串应该彼此不同。

在此处输入图片描述

答案2

我选择的解决方案是使用 tabularx 包。我不确定为什么 tabular 包出错时这个包允许显示字幕,但它确实允许。

代码如下:

\documentclass{article}
\usepackage[paperwidth=7in, paperheight=5in]{geometry}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage[labelformat=empty]{caption}
\usepackage{tabularx}

\begin{document}

Examples

\begin{tabularx}{\textwidth}{ X X }
\begin{tikzpicture}[xscale=.5, yscale=.5]
\draw [<->,thick] (0,5) |- (5,0);
\draw [thick] (4,1) --(4,4);
\draw [thick, dashed] (4,1) -- (1,1) -- (1,4) -- (4,4);
\draw [fill] (4,1) circle [radius=0.1];
\draw [fill] (4,4) circle [radius=0.1];
\node at (2.5,2.5) {$A$};
\end{tikzpicture}
\captionof{figure}{$A$ is not open in $\mathbb{R}^{2}$.}
\label{tikz}

&

\begin{tikzpicture}[xscale=.5, yscale=.5]
\draw [<->,thick] (0,5) |- (5,0);
\draw [thick, dashed] (1,1) to [out=90, in=280] (1,4) to [out=30, in=150] (2,3.5) to [out=30, in=200] (4,4) to [out=40, in=90] (5,3) to [out=270, in=90] (4,1) to [out=180, in=30] (1,1);
\node at (2.5,2.5) {$A$};
\end{tikzpicture}
\captionof{figure}{$A$ is open.}
\label{tikz}

\\

\begin{tikzpicture}[xscale=.5, yscale=.5]
\draw [<->,thick] (0,5) |- (5,0);
\draw [fill] (4,1) circle [radius=0.1];
\draw [fill] (2,1) circle [radius=0.1];
\draw [fill] (3,5) circle [radius=0.1];
\draw [fill] (1,3) circle [radius=0.1];
\end{tikzpicture}
\captionof{figure}{$A$ is not open.}
\label{tikz}

&

\begin{tikzpicture}[xscale=.5, yscale=.5]
\draw [<->,thick] (0,2) |- (5,0);
\draw [ultra thick] (1,0) --(3,0) node [above] {$A$};
\draw [fill=white] (1,0) circle [radius=0.1];
\draw [fill=white] (3,0) circle [radius=0.1];
\end{tikzpicture}
\captionof{figure}{$A$ is not open in $\mathbb{R}^{2}$ but open in $\mathbb{R}$.}
\label{tikz}

\end{tabularx}

\end{document}

它能生产出什么呢:

带有标题的 2x2 tikzpictures 网格

尽管标题似乎没有在每个 tikzpicture 下方“居中”,但我很满意。

相关内容