22

How could I have a figure with 3 or 4 subfigures side-by-side in the same row? I've tried it once but the best I had was only 2 subfigures side-by-side in the same row.

My code so far is:

\documentclass[12pt,a4paper,titlepage,twoside,openright]{article}
\usepackage[english,greek]{babel}
\usepackage{ucs} 
\usepackage[utf8x]{inputenc}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz}
\usepackage{tkz-tab}
\usepackage{caption}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{subcaption} 

\begin{document}
\begin{figure}
     \begin{subfigure}[b]{0.30\textwidth}
\centering
        \begin{tikzpicture}
 \draw (0,3) node[left] {$\text{A}$} to[out=0,in=90] (3,0) node[below]{$\text{B}$};
    \draw[->, very thick] (-.1,0) -- (4,0) node[below] {$\text{αγαθό Α}$};
    \draw[->, very thick] (0,-.1) -- (0,4) node[left]{$\text{αγαθό Β}$};
\draw[ForestGreen] (0,2)  node[left] {$\text{Η}$} to [out=0, in=90] (2,0)node[below]{$\text{Θ}$};
\draw[<-, Cyan] (45:2.1) -- (45:2.9);
\end{tikzpicture}
    \label{fig:subfig8}
          \caption{}
       \end{subfigure}
     \begin{subfigure}[b]{0.30\textwidth}
\centering
           \begin{tikzpicture}
\draw (0,3) node[left] {$\text{A}$} to[out=0,in=90] (3,0) node[below]{$\text{B}$};
    \draw[->, very thick] (-.1,0) -- (4,0) node[below] {$\text{αγαθό Α}$};
    \draw[->, very thick] (0,-.1) -- (0,4) node[left]{$\text{αγαθό Β}$};
\draw[ForestGreen] (0,2.7)  node[left] {$\text{Γ}$} to [out=0, in=90] (1.5,0)node[below]{$\text{Δ}$};
\draw[<-, Cyan] (45:2.2) -- (45:2.9);
\end{tikzpicture}
    \label{fig:subfig9}
          \caption{}
          \end{subfigure}
     \begin{subfigure}[b]{0.35\textwidth}
\centering
        \begin{tikzpicture}
\draw (0,3) node[left] {$\text{A}$} to[out=0,in=90] (3,0) node[below]{$\text{B}$};
    \draw[->, very thick] (-.1,0) -- (4,0) node[below] {$\text{αγαθό Α}$};
    \draw[->, very thick] (0,-.1) -- (0,4) node[left]{$\text{αγαθό Β}$};
\draw[ForestGreen] (0,1.5)  node[left] {$\text{E}$} to [out=0, in=90] (2.5,0)node[below]{$\text{Z}$};
\draw[<-, Cyan] (45:2.1) -- (45:2.5);
\end{tikzpicture}
\label{fig:subfig10}
          \caption{}
     \end{subfigure}
\captionof{figure}{τεχνολογία και στα δυο αγαθά} \label{fig:subfig1.a.4}
 \end{figure}

\end{document}
1

1 Answer 1

32

The following code is used for 3, it requires the subcaption package. If have more than 3 change the 0.30\textwidth parameter of the subfigure to resize each of them accordingly

 \begin{figure}
     \begin{subfigure}[b]{0.30\textwidth}
          \centering
          \resizebox{\linewidth}{!}{\input{figures/a.tikz}}  
          \caption{Caption A}
          \label{fig:A}
     \end{subfigure}
     \begin{subfigure}[b]{0.30\textwidth}
          \centering
          \resizebox{\linewidth}{!}{\input{figures/b.tikz}}  
          \caption{Caption B}
          \label{fig:B}
     \end{subfigure}
     \begin{subfigure}[b]{0.30\textwidth}
          \centering
          \resizebox{\linewidth}{!}{\input{figures/c.tikz}}  
          \caption{Caption C}
          \label{fig:C}
     \end{subfigure}
 \end{figure}

EDIT: I've taken the time to fix your code. You were missing the \resizebox in order to properly locate your tikz figures. See code and results below

\documentclass[12pt,a4paper,titlepage,twoside,openright]{article}
\usepackage[english,greek]{babel}
\usepackage{ucs} 
\usepackage[utf8x]{inputenc}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz}
\usepackage{tkz-tab}
\usepackage{caption}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{subcaption} 

\begin{document}
\begin{figure}
    \begin{subfigure}[b]{0.32\textwidth}
        \centering
        \resizebox{\linewidth}{!}{
            \begin{tikzpicture}
                \draw (0,3) node[left] {$\text{A}$} to[out=0,in=90] (3,0) node[below]{$\text{B}$};
                \draw[->, very thick] (-.1,0) -- (4,0) node[below] {$\text{αγαθό Α}$};
                \draw[->, very thick] (0,-.1) -- (0,4) node[left]{$\text{αγαθό Β}$};
                \draw[ForestGreen] (0,2)  node[left] {$\text{Η}$} to [out=0, in=90] (2,0)node[below]{$\text{Θ}$};
                \draw[<-, Cyan] (45:2.1) -- (45:2.9);
            \end{tikzpicture}
        }
        \caption{Subfigure A}
        \label{fig:subfig8}
    \end{subfigure}
    \begin{subfigure}[b]{0.32\textwidth}
    \centering
        \resizebox{\linewidth}{!}{
            \begin{tikzpicture}
                \draw (0,3) node[left] {$\text{A}$} to[out=0,in=90] (3,0) node[below]{$\text{B}$};
                \draw[->, very thick] (-.1,0) -- (4,0) node[below] {$\text{αγαθό Α}$};
                \draw[->, very thick] (0,-.1) -- (0,4) node[left]{$\text{αγαθό Β}$};
                \draw[ForestGreen] (0,2.7)  node[left] {$\text{Γ}$} to [out=0, in=90] (1.5,0)node[below]{$\text{Δ}$};
                \draw[<-, Cyan] (45:2.2) -- (45:2.9);
            \end{tikzpicture}
        }
        \caption{Subfigure B}   
        \label{fig:subfig9}
    \end{subfigure}
    \begin{subfigure}[b]{0.32\textwidth}
        \centering
        \resizebox{\linewidth}{!}{
            \begin{tikzpicture}
                \draw (0,3) node[left] {$\text{A}$} to[out=0,in=90] (3,0) node[below]{$\text{B}$};
                \draw[->, very thick] (-.1,0) -- (4,0) node[below] {$\text{αγαθό Α}$};
                \draw[->, very thick] (0,-.1) -- (0,4) node[left]{$\text{αγαθό Β}$};
                \draw[ForestGreen] (0,1.5)  node[left] {$\text{E}$} to [out=0, in=90] (2.5,0)node[below]{$\text{Z}$};
                \draw[<-, Cyan] (45:2.1) -- (45:2.5);
            \end{tikzpicture}
        }
        \caption{Subfigure C}
        \label{fig:subfig10}
    \end{subfigure}
\caption{τεχνολογία και στα δυο αγαθά} 
\label{fig:subfig1.a.4}
\end{figure}

\end{document}

enter image description here

I hope this helps!

Update: Fixed missing { in resizeboxes.

9
  • 4
    Perhaps you should mention that your code requires the subcaption package. Commented Jun 25, 2013 at 15:11
  • If I use the subfigure package, does the code change?
    – Y_gr
    Commented Jun 26, 2013 at 11:14
  • 3
    @giannis Yes, it changes. You shouldn't use subfigure as it is deprecated. You are better off with subcaption
    – Dan
    Commented Jun 26, 2013 at 11:31
  • Thank you. That was helpful. I'd like to add, however, that the caption (a), (b), (c) of each subfigure is not centered below of figure. I've tried also \centering but still they aren't centered.
    – Y_gr
    Commented Jun 26, 2013 at 11:49
  • 1
    @giannis I've updated my answer, fixing your code.
    – Dan
    Commented Jun 28, 2013 at 9:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .