24

I'm trying to get these two tikzpictures to be shown side by side. This is what I have:

Not the most minimal example, but should be sufficient:

\documentclass[12pt,a4]{article}
\usepackage{tikz}

\begin{document}

\begin{center}
\begin{minipage}{.2\textwidth}

\begin{tikzpicture}[scale=0.33] %[x={10.0pt},y={10.0pt}]

\draw[line width=2pt] (0,0) -- (0,10);
\draw[line width=2pt] (0,0) -- (10,0);
\draw[line width=2pt] (0,10) -- (10,10);
\draw[line width=2pt] (0,10) -- (10,10);
\draw[line width=2pt] (10,0) -- (10,10);

\draw[line width=2pt] (0,0) -- (3,5);

\draw[line width=2pt] (10,0) -- (13,5);

\draw[line width=2pt] (0,10) -- (3,15);

\draw[line width=2pt] (10,10) -- (13,15);

\draw[line width=2pt] (3,5) -- (13,5);

\draw[line width=2pt] (3,5) -- (3,15);

\draw[line width=2pt] (13,5) -- (13,15);

\draw[line width=2pt] (3,15) -- (13,15);

\draw[line width=1pt] (5,0) -- (5,10);

\draw[line width=1pt] (5,10) -- (8,15);

\draw[line width=1pt] (5,0) -- (8,5);

\draw[line width=1pt] (8,5) -- (8,15);

\draw[black, fill=blue,fill opacity=0.5] (5,0) -- (5,10) -- (8,15) -- (8,5) -- cycle;

\end{tikzpicture} % pic 1

\end{minipage}

\begin{minipage}{.2\textwidth}

\begin{tikzpicture}[scale=0.33] %[x={10.0pt},y={10.0pt}]

\draw[line width=2pt] (0,0) -- (0,10);
\draw[line width=2pt] (0,0) -- (10,0);
\draw[line width=2pt] (0,10) -- (10,10);
\draw[line width=2pt] (0,10) -- (10,10);
\draw[line width=2pt] (10,0) -- (10,10);

\draw[line width=2pt] (0,0) -- (3,5);

\draw[line width=2pt] (10,0) -- (13,5);

\draw[line width=2pt] (0,10) -- (3,15);

\draw[line width=2pt] (10,10) -- (13,15);

\draw[line width=2pt] (3,5) -- (13,5);

\draw[line width=2pt] (3,5) -- (3,15);

\draw[line width=2pt] (13,5) -- (13,15);

\draw[line width=2pt] (3,15) -- (13,15);

\draw[line  width=1pt] (0,10) -- (10,0);

\draw[line  width=1pt] (0,10) -- (3,5);

\draw[line  width=1pt] (3,5) -- (10,0);

\draw[black, fill=blue,fill opacity=0.5] (0,10) -- (10,0) -- (3,5) -- cycle;

\draw[line  width=1pt] (3,15) -- (10,10);

\draw[line  width=1pt] (3,15) -- (13,5);

\draw[line  width=1pt] (10,10) -- (13,5);

\draw[black, fill=blue,fill opacity=0.5] (3,15) -- (10,10) -- (13,5) -- cycle;

\end{tikzpicture}

\end{minipage}

\end{center}

\end{document}

I've tried using minipage and subfigure/subcaption packages with no luck.

Edit: I'd like to have a caption below each tikzpicture (but I don't need to refer to it, so no external package is needed per se), hence why minipage is used, although now the spacing isn't consistent (too much space on the right):

enter image description here

24

Delete the empty line between the minipages. It is like the \par command. Use instead:

[...]
\end{minipage}
%  no empty line here 
\begin{minipage}{.2\textwidth}
[...]
  • 3
    When using minipages this way, my diagrams overlapped and chomped captions to their last couple words. Can anything be done about that? – rschwieb Aug 20 '15 at 13:05
  • The two figures overlap if I use minipage. Do you have a suggestion about that? – kalmanIsAGameChanger Aug 2 '17 at 8:19
  • then your figures are too big. Resize it with \scalebox or \resizebox – user2478 Aug 2 '17 at 8:35
29

Why the minipages?

\documentclass[12pt,a4paper]{article}
\usepackage{tikz}

\begin{document}

\begin{center}
\begin{tikzpicture}[scale=0.33] %[x={10.0pt},y={10.0pt}]
\draw[line width=2pt] (0,0) -- (0,10);
\draw[line width=2pt] (0,0) -- (10,0);
\draw[line width=2pt] (0,10) -- (10,10);
\draw[line width=2pt] (0,10) -- (10,10);
\draw[line width=2pt] (10,0) -- (10,10);
\draw[line width=2pt] (0,0) -- (3,5);
\draw[line width=2pt] (10,0) -- (13,5);
\draw[line width=2pt] (0,10) -- (3,15);
\draw[line width=2pt] (10,10) -- (13,15);
\draw[line width=2pt] (3,5) -- (13,5);
\draw[line width=2pt] (3,5) -- (3,15);
\draw[line width=2pt] (13,5) -- (13,15);
\draw[line width=2pt] (3,15) -- (13,15);
\draw[line width=1pt] (5,0) -- (5,10);
\draw[line width=1pt] (5,10) -- (8,15);
\draw[line width=1pt] (5,0) -- (8,5);
\draw[line width=1pt] (8,5) -- (8,15);
\draw[black, fill=blue,fill opacity=0.5] (5,0) -- (5,10) -- (8,15) -- (8,5) -- cycle;
\end{tikzpicture}% pic 1
\qquad % <----------------- SPACE BETWEEN PICTURES
\begin{tikzpicture}[scale=0.33] %[x={10.0pt},y={10.0pt}]
\draw[line width=2pt] (0,0) -- (0,10);
\draw[line width=2pt] (0,0) -- (10,0);
\draw[line width=2pt] (0,10) -- (10,10);
\draw[line width=2pt] (0,10) -- (10,10);
\draw[line width=2pt] (10,0) -- (10,10);
\draw[line width=2pt] (0,0) -- (3,5);
\draw[line width=2pt] (10,0) -- (13,5);
\draw[line width=2pt] (0,10) -- (3,15);
\draw[line width=2pt] (10,10) -- (13,15);
\draw[line width=2pt] (3,5) -- (13,5);
\draw[line width=2pt] (3,5) -- (3,15);
\draw[line width=2pt] (13,5) -- (13,15);
\draw[line width=2pt] (3,15) -- (13,15);
\draw[line  width=1pt] (0,10) -- (10,0);
\draw[line  width=1pt] (0,10) -- (3,5);
\draw[line  width=1pt] (3,5) -- (10,0);
\draw[black, fill=blue,fill opacity=0.5] (0,10) -- (10,0) -- (3,5) -- cycle;
\draw[line  width=1pt] (3,15) -- (10,10);
\draw[line  width=1pt] (3,15) -- (13,5);
\draw[line  width=1pt] (10,10) -- (13,5);
\draw[black, fill=blue,fill opacity=0.5] (3,15) -- (10,10) -- (13,5) -- cycle;
\end{tikzpicture}% pic 2

\end{center}

\end{document}

Instead of \qquad you can have \hspace{<length>} (just remember the form

\end{tikzpicture}% NO SPACE!
\hspace{3cm}% NO SPACE!
\begin{tikzpicture}[...]

so you precisely control the horizontal space between the images. Vertical alignment can be obtained with TikZ methods (look for baseline in the manual).

Note also that the a4 option is invalid, it should be a4paper.

enter image description here

  • I'd like to have a caption below each tikzpicture, but not necessarily made by a package (I don't need to refer to it). – Argo Nov 20 '14 at 13:36
  • By adding \vrule{} I was able to introduce a line between the two pictures, but it was not centered. Do you know offhand how to fix this? – rschwieb Aug 20 '15 at 13:29
  • (I hacked it by adding an extra blank column to one of the diagrams) – rschwieb Aug 20 '15 at 13:35
  • @rschwieb \qquad\vrule\qquad should do – egreg Aug 20 '15 at 15:11
11

Here is another version:

\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\tikzset{mynode/.style={inner sep=2pt,fill,outer sep=0,circle}}

\begin{document}

\begin{center}
\begin{tikzpicture}[scale=3,line width=1pt]
 \coordinate (1) at (0,0,0);
 \coordinate (2) at (0,1,0);
 \coordinate (3) at (1,1,0);
 \coordinate (4) at (1,0,0);
 \coordinate (5) at (0,0,1);
 \coordinate (6) at (0,1,1);
 \coordinate (7) at (1,1,1);
 \coordinate (8) at (1,0,1);
 \foreach \x in {1,2,...,8}{
     \node[mynode] at (\x) {};
 }
 \draw (1) -- (2) -- (3) -- (4) -- cycle;
 \draw (5) -- (6) -- (7) -- (8) -- cycle;
 \draw (1) -- (5)  (2) -- (6) (3) -- (7) (4) -- (8);
 \draw[thin,fill=blue!50,opacity=0.5] (0.5,0,0) -- (0.5,0,1) -- (0.5,1,1) -- (0.5,1,0) --cycle;
 \node at (0.5,-0.2,1) {(\textit{h\,k\,l})};
\end{tikzpicture}
\hspace{1cm}
\begin{tikzpicture}[scale=3,line width=1pt]
 \coordinate (1) at (0,0,0);
 \coordinate (2) at (0,1,0);
 \coordinate (3) at (1,1,0);
 \coordinate (4) at (1,0,0);
 \coordinate (5) at (0,0,1);
 \coordinate (6) at (0,1,1);
 \coordinate (7) at (1,1,1);
 \coordinate (8) at (1,0,1);
 \foreach \x in {1,2,...,8}{
     \node[mynode] at (\x) {};
 }
 \draw (1) -- (2) -- (3) -- (4) -- cycle;
 \draw (5) -- (6) -- (7) -- (8) -- cycle;
 \draw (1) -- (5)  (2) -- (6) (3) -- (7) (4) -- (8);
 \draw[thin,fill=blue!50,opacity=0.5] (1) -- (8) -- (6) --cycle;
 \draw[thin,fill=blue!50,opacity=0.5] (2) -- (4) -- (7) --cycle;
 \node at (0.5,-0.2,1) {(\textit{h\,k\,l})};
\end{tikzpicture}

\end{center}

\end{document}

enter image description here

You can reduce the \coordinate definition bit by

 \foreach \x/\y/\z/\a in {0/0/0/1,0/1/0/2,1/1/0/3,1/0/0/4,0/0/1/5,0/1/1/6,1/1/1/7,1/0/1/8} {
    \coordinate (\a) at (\x,\y,\z);
    }

if you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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