Two tikZ pictures side by side

  • LaTeX
  • Thread starter member 428835
  • Start date
  • Tags
    Pictures
In summary, the conversation revolves around the issue of placing two tikZ pictures side by side and adding a caption for both. The first suggestion was to use the \begin{minipage} command, but the user was unable to generate a single caption for both pictures. They then found a solution using the subfigure package and provided a working example. The conversation then shifted to a different issue with plotting in tikZ, where the user was experiencing unexpected results when changing the code.
  • #1
member 428835
Hi PF!

I have been trying to put two tikZ pictures next to each other but I can't figure out how to do it. I've used the \begin{minipage} command, which worked well, but was unable to generate a caption. Any ideas?
 
Physics news on Phys.org
  • #3
robphy said:
First Google entry for: tikz side by side
gives

http://tex.stackexchange.com/questions/213075/two-tikzpictures-side-by-side

Yea, I clicked on the first several google suggestions, but notice the one that you reference has the minipage, and for some reason I can't seem to add a single caption for both pictures underneath. Any suggestions?
 
  • #4
Can you post some code?
 
  • #5
Sure, and I actually just found a way to do it using the subfigure package. Below is a working example:

Code:
\documentclass{article}
\usepackage{tikz}
\usepackage{subcaption} 

\begin{document}
\begin{figure}
    \begin{subfigure}[b]{0.32\textwidth}
        \centering
        \resizebox{\linewidth}{!}{
            \begin{tikzpicture}
                \draw (2,2) circle (3cm);
            \end{tikzpicture}
        }
        \caption{Subfigure A}
        \label{fig:subfig8}
    \end{subfigure}
    \begin{subfigure}[b]{0.32\textwidth}
    \centering
        \resizebox{\linewidth}{!}{
            \begin{tikzpicture}
                \draw (2,2) circle (3cm);
            \end{tikzpicture}
        }
        \caption{Subfigure B}  
        \label{fig:subfig9}
    \end{subfigure}
    \begin{subfigure}[b]{0.32\textwidth}
        \centering
        \resizebox{\linewidth}{!}{
            \begin{tikzpicture}
                \draw (2,2) circle (3cm);
            \end{tikzpicture}
        }
        \caption{Subfigure C}
        \label{fig:subfig10}
    \end{subfigure}
\caption{big caption} 
\label{fig:subfig1.a.4}
\end{figure}

\end{document}
 
  • #6
Actually, while this is not the same question, perhaps you could help? For this line of code

Code:
\draw[domain=0.1:1,samples=100,color=blue,variable=\x] plot (\x,{(\x)^(1/2)});

tikZ is plotting ##y=x^{-1/2}## and when I change the code to

Code:
\draw[domain=0.1:1,samples=100,color=blue,variable=\x] plot (\x,{1/(\x)^(1/2)});

tikZ is plotting ##y=x^{1/2}##. Any idea as to why this is?
 

1. How do I create two tikZ pictures side by side?

To create two tikZ pictures side by side, you can use the minipage environment with the width set to half of the page width. Within each minipage, you can then include your tikZ code to create the desired pictures.

2. Can I adjust the spacing between the two pictures?

Yes, you can adjust the spacing between the two pictures by using the \hfill command between the two minipages. This will create a horizontal space that will push the two pictures apart.

3. How can I align the two pictures to the top or bottom of the page?

You can use the [t] or [b] options after the \begin{minipage} command to specify the vertical alignment of the pictures. [t] will align the pictures to the top, while [b] will align them to the bottom.

4. Is it possible to add captions to the two pictures?

Yes, you can add captions to the two pictures by using the \captionof{figure} command after the \begin{minipage} command. This will create a caption for each picture, which can be referenced using the \ref{label} command.

5. Can I resize the two pictures to fit on the page?

Yes, you can resize the two pictures to fit on the page by adjusting the width of the minipage environment. You can also use the \resizebox{width}{height}{content} command within each minipage to resize the content of the pictures.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
  • General Discussion
Replies
2
Views
1K
  • High Energy, Nuclear, Particle Physics
Replies
2
Views
1K
Replies
4
Views
965
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top