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}
Y_gr
  • 3,322

1 Answers1

31

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.

learnerX
  • 149
  • 8
Dan
  • 1,802
  • 4
    Perhaps you should mention that your code requires the subcaption package. – Gonzalo Medina Jun 25 '13 at 15:11
  • If I use the subfigure package, does the code change? – Y_gr Jun 26 '13 at 11:14
  • 3
    @giannis Yes, it changes. You shouldn't use subfigure as it is deprecated. You are better off with subcaption – Dan Jun 26 '13 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 Jun 26 '13 at 11:49
  • @giannis I've updated the coude, the \centering in the example should do the work. A minimal working example of your code that let us see exactly what are you trying to do would help. – Dan Jun 26 '13 at 11:53
  • @Dan I've updated my question. – Y_gr Jun 26 '13 at 12:02
  • @Dan I'd like to know, if that's possible, how could we use the subfigure package having the same result... I think it gives a better result, but still I'm not sure... – Y_gr Jun 27 '13 at 21:18
  • 1
    @giannis I've updated my answer, fixing your code. – Dan Jun 28 '13 at 09:14
  • \resizebox{\linewidth}{!}\input{figures/a.tikz}} (and other resize boxes) have a missing {. It should be: \resizebox{\linewidth}{!}{\input{figures/a.tikz}}. Just trying to save others some time. – learnerX Aug 09 '20 at 20:51