1

I need to put two images within a single column in a two-column page such that each subfigure will have a border around it. I have tried the following:

\begin{figure}[t!]
\centering
 \begin{subfigure}[t]{\textwidth}
 \tcbox[colback=white] {\includegraphics[width=0.1\textwidth]{img1}} 
 \caption{img1}
 \end{subfigure} 
\quad
 \begin{subfigure}[t]{\textwidth}
  \tcbox[colback=white]{\includegraphics[width=0.1\textwidth] 
   {img2}} 
  \caption{img2}
 \end{subfigure}
\caption{Comparison of images (a) img1 and (b) img2}

\end{figure}

However, I am not able to place the images properly. I want them to be placed side by side and both the images and the text should be center aligned. How can I do this?

Majis
  • 155

1 Answers1

2

Something like this? You need to be using \linewidth instead of \textwidth here. So for example, I've changed both your subfigure to have a width of 0.4\linewidth. This way they can both fit in the column. For more reading see Difference between \textwidth, \linewidth and \hsize.

To get the subfigure center aligned, use \centering within the subfigure.

enter image description here

\documentclass[twocolumn]{article}
\usepackage[a4paper,margin=25mm,showframe]{geometry} % <--- showframe used just as a visual aid.
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{tcolorbox}

\setlength{\columnseprule}{0.4pt} % <--- to draw a line between the columns, just as an aid to visualise the alignment in this MWE.

\begin{document}

\begin{figure}[h]
\centering
 \begin{subfigure}[t]{0.4\linewidth}
 \centering
 \tcbox[colback=white] {\includegraphics[width=0.5\linewidth] {example-image-a}}
 \caption{img1}
 \end{subfigure} 
 %
 \begin{subfigure}[t]{0.4\linewidth}
 \centering
  \tcbox[colback=white]{\includegraphics[width=0.5\linewidth] {example-image-b}} 
  \caption{img2}
 \end{subfigure}
\caption{Comparison of images (a) img1 and (b) img2}
\end{figure}

\end{document}
Milo
  • 9,440