6

I'm trying to place two TiKz pictures side by side in a two-column document (IEEEtrans style). I've looked at various solutions, but each one that claims to place figures side by side only manages to place the plots one above the other:

enter image description here

Currently I'm trying to use the subfigure environment:

\documentclass[letterpaper, 10 pt, conference]{ieeeconf} 

\IEEEoverridecommandlockouts                           
\overrideIEEEmargins 


\usepackage{graphicx} 
\usepackage{amssymb}
\usepackage{algorithm}
\usepackage{algorithmic}
\newcommand{\tsc}[1]{\textsuperscript{#1}}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{subcaption} 
\usepackage{pgfplots}
\usepackage{pgfplotstable}

\usepgfplotslibrary{groupplots}

\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,%
    decorations.pathreplacing,decorations.pathmorphing,shapes,%
    matrix,shapes.symbols}

\pgfplotsset{
tick label style={font=\tiny}, %axis numbers font size
label style={font=\small}, %axis labels font size
legend style={font=\tiny}
}


\begin{figure}
    \centering
    \begin{subfigure}[t]{0.48\textwidth}
        \centering
        %\input{figs/roc_curve.tikz}
        \resizebox{0.5\linewidth}{!}{\input{figs/roc.tikz}}  
        \caption{Caption A}
        \label{fig:A}
    \end{subfigure}
    \begin{subfigure}[b]{0.48\textwidth}
        \centering
        %\input{figs/roc_curve.tikz}
        \resizebox{0.5\linewidth}{!}{\input{figs/roc.tikz}}  
        \caption{Caption B}
        \label{fig:B}
    \end{subfigure}    
    \caption{ROC curve of failure detection;}
    \label{fig:roc_curve}
\end{figure}

(...)

\end{document}

What exactly is forcing the plots to become only vertically aligned?

13

You have to use \linewidth or \columnwidth instead of \textwidth in

\begin{subfigure}[b]{0.48\textwidth}

in both places. \textwidth is the width of entire text including both columns. For details on \linewidth and \textwidth please refer to this answer.

\documentclass[letterpaper,10 pt,conference]{ieeeconf}

\usepackage{graphicx,subcaption}

\begin{document}
\begin{figure}
    \centering
    \begin{subfigure}[b]{0.48\linewidth}        %% or \columnwidth
        \centering
        \includegraphics[width=\linewidth]{example-image-a}
        \caption{Caption A}
        \label{fig:A}
    \end{subfigure}
    \begin{subfigure}[b]{0.48\linewidth}        %% or \columnwidth
        \centering
        \includegraphics[width=\linewidth]{example-image-b}
        \caption{Caption B}
        \label{fig:B}
    \end{subfigure}
    \caption{ROC curve of failure detection;}
    \label{fig:roc_curve}
\end{figure}

(...)

\end{document}

enter image description here

I have used [b] for both the subfigures to align them properly.

|improve this answer|||||
  • 2
    @cmhughes Thanks! Courtesy latexindent.pl ;) – user11232 Feb 4 '14 at 4:41
  • sweet :) you're one of the number one users! belated congratulations on topping 50K- I see a gold tikz badge will be yours soon, too :) – cmhughes Feb 4 '14 at 5:05
  • @cmhughes You are very kind. Thank you very much. :) – user11232 Feb 4 '14 at 5:08
4

If you want to place two figures side by side over one column, Harish's solution is what you need. But if you want to place both figures over both columns, you have to use a figure* environment. When you use a twocolumn document, figure and table environments are as wide as a column, while figure* and table* use both columns.

Next example shows this differences. First one is taken from Harish's answer and the second one uses figure*.

\documentclass[letterpaper,10 pt,conference]{ieeeconf}

\usepackage{graphicx,subcaption}
\usepackage{lipsum}

\begin{document}
\begin{figure}
    \centering
    \begin{subfigure}[b]{0.48\linewidth}        %% or \columnwidth
        \centering
        \includegraphics[width=\linewidth]{example-image-a}
        \caption{Caption A}
        \label{fig:A}
    \end{subfigure}
    \begin{subfigure}[b]{0.48\linewidth}        %% or \columnwidth
        \centering
        \includegraphics[width=\linewidth]{example-image-b}
        \caption{Caption B}
        \label{fig:B}
    \end{subfigure}
    \caption{ROC curve of failure detection;}
    \label{fig:roc_curve}
\end{figure}

\lipsum

\begin{figure*}
    \centering
    \begin{subfigure}[b]{\columnwidth}        %% or \columnwidth
        \centering
        \includegraphics[width=\linewidth]{example-image-a}
        \caption{Caption A}
        \label{fig:A}
    \end{subfigure}
    \hfill
    \begin{subfigure}[b]{\columnwidth}        %% or \columnwidth
        \centering
        \includegraphics[width=\linewidth]{example-image-b}
        \caption{Caption B}
        \label{fig:B}
    \end{subfigure}
    \caption{ROC curve of failure detection;}
    \label{fig:roc_curve}
\end{figure*}

\lipsum
\end{document}

enter image description here

enter image description here

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.