5

I try to place 2 by 2 figures in table with each having caption

I tried

\begin{table}[ht]
\begin{tabular}{cc}
\begin{subfigure}\centering\includegraphics[width=0.3\columnwidth]{./img/1.png}\caption{Figure A}\label{fig:taba}\end{subfigure}&
\begin{subfigure}\centering\includegraphics[width=0.3\columnwidth]{./img/1.png}\caption{Figure B}\label{fig:tabb}\end{subfigure}\\
\newline
\begin{subfigure}\centering\includegraphics[width=0.3\columnwidth]{./img/1.png}\caption{Figure C}\label{fig:tabc}\end{subfigure}&
\begin{subfigure}\centering\includegraphics[width=0.3\columnwidth]{./img/1.png}\caption{Figure A again}\label{fig:taba2}\end{subfigure}\\
\end{tabular}
\caption{A table with figures}
\label{tab:mytable}
\end{table}

but this gives error

[109] [110] <use ./img/1.png>
! You can't use `\hrule' here except with leaders.
\caption@hrule ->\hrule 
                        \@height \z@ 
l.888 ...nwidth]{./img/1.png}\caption{Figure A}
                                                  \label{fig:taba}\end{subfi...

Any help how to solve these? I checked many code blocks to place figures in table none works

3
  • 1
    why do you want them in a table so the outer caption is table: 2 not figure: 2 ? Jul 25, 2017 at 23:15
  • @David that also works. I can place subfigures in a big figure Jul 26, 2017 at 19:31
  • it isn't clear what you mean by "work" but if you put subfigures in a table environment then they will be kept in order with tables rather than figures, and the general caption is table rather than Figure, it's rather more normal to use a figure environment (you can still use atabular for layout of course. Jul 26, 2017 at 20:57

1 Answer 1

8

I guess that you like to obtain something like this:

enter image description here

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{tabularx}
\usepackage[skip=1ex]{caption}

\begin{document}
    \begin{table}[ht]
    \centering
\begin{tabularx}{\columnwidth}{XX}
\includegraphics[width=\linewidth]{./img/1.png}
\captionof{figure}{Figure A}\label{fig:taba}
    &   \includegraphics[width=\linewidth]{./img/1.png}   
        \captionof{figure}{Figure B}\label{fig:tabb}              \\
\includegraphics[width=0.45\columnwidth]{./img/1.png}
\captionof{figure}{Figure C}\label{fig:tabc}
    &   \includegraphics[width=\linewidth]{./img/1.png} 
        \captionof{figure}{Figure D}\label{fig:tabd}               
\end{tabularx}
\caption{A table with figures}
\label{tab:mytable}
    \end{table}%
\end{document} 

or figures as sub figures?

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage[skip=1ex]{caption}
\usepackage{subcaption}

\begin{document}
    \begin{table}[ht]
\begin{subfigure}{0.45\columnwidth}
\includegraphics[width=\linewidth]{./img/1.png}
    \caption{figure}\label{fig:taba}
\end{subfigure}\hfill
\begin{subfigure}{0.45\columnwidth}
\includegraphics[width=\linewidth]{./img/1.png}   
    \caption{Figure B}\label{fig:tabb}             
\end{subfigure}\\[1em]
%
\begin{subfigure}{0.45\columnwidth}
\includegraphics[width=\linewidth]{./img/1.png}
    \caption{Figure C}\label{fig:tabc}
\end{subfigure}\hfill
\begin{subfigure}{0.45\columnwidth}
\includegraphics[width=\linewidth]{./img/1.png} 
    \caption{Figure D}\label{fig:tabd}               
\end{subfigure}
\caption{A table with figures}
\label{tab:mytable}
    \end{table}%
\end{document} 

enter image description here

2
  • first one worked I was using environment tabular not tabularx was this the reason? Jul 26, 2017 at 19:47
  • No. If you have been used p{...} column type, my solution also would work with tabular too. Columns c doesn't allow broke lines in cells. However, notice difference in use of subfigures in my answer and your code. In my MWE are not in tabulr(x) environement.
    – Zarko
    Jul 26, 2017 at 19:55

You must log in to answer this question.

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