Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm attempting to condense 4 tikzpictures into a smaller space in my document. The solution I have is as follows:

\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}

This produces:

My (ugly) solution to condensing 4 tikzpictures.

The solution involves creating columns and placing the tikzpictures within the columns and forcing them to separate with a \newline.

But this is, in my opinion, an ugly solution. I'd like to be able to place the 4 tikzpictures in a 2x2 grid, each tikzpicture horizontally and vertically centered within it's cell plus turning each node that currently acts as a label (e.g. "A is open.") into a caption for that tikzpicture.

I tried to do this before by placing each tikzpicture within a minipage, but then this can't be captioned (something about float and absolute figures?), also I tried putting \figures of minipages of tikzpictures which, obviously, didn't work and became messy quickly.

Is there a simple solution to this?

share|improve this question
1  
Put each of your drawings in a scope and use them in one TikZ picture. You can use [shift={(x,y)}] option to position the scopes relative to the others. Or use subcaption package which is quite handy. –  percusse Feb 27 '13 at 21:05
    
You're right, using shift is a possible solution. But I'd prefer one in which the placement of figures is determined by the document's compilation (and tikzpicture size, etc) as opposed to user input. –  geoff92 Feb 27 '13 at 21:09
1  
I would then really go with subcaption. You also might put your tikzpictures in a matrix node but that would not be as good in terms of caption placements. –  percusse Feb 27 '13 at 21:12
1  
Sounds like the tabular environment should do the job? –  Peter Grill Feb 27 '13 at 21:12
    
And what about the groupplots in pgfplots? I think that's what you need. –  m0nhawk Feb 27 '13 at 21:14

2 Answers 2

up vote 4 down vote accepted

While tabularx works, it's a bit overkill in this case.

\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}

Note the % after the first \end{minipage} in each row, to avoid a spurious space. The center environment is just to remove indentations and to give some room after "Examples".

Use a different vertical space command instead of \medskip, if you prefer.

The \label commands are useless, as you don't number the captions. In any case, the strings should be different from each other.

enter image description here

share|improve this answer

The solution I've settled on uses the tabularx package. I'm not sure why this allows captions when the tabular package gave me errors, but it does.

Here's the code:

\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}

And what it produces:

2x2 grid of tikzpictures with captions

Although the captions don't seem "centered" below each tikzpicture, I'm satisfied.

share|improve this answer
    
\begin{tabularx}{>{\centering}X>{\centering\arraybackslash}X} will do, but it's overkill. –  egreg Feb 27 '13 at 22:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.