2

I want to plot two figures in the same line. I'm also using the llncs Springer class file found here for my document.

I have these two figures:

\begin{figure}
  \begin{tikzpicture}
\begin{axis}[
ybar,
  symbolic x coords={x1, x2, x3},
  xtick={x1, x2, x3},
ytick={5, 4, 10},
  xticklabel style={rotate=-90},
nodes near coords,
  ylabel={Accuracy (\%)},
width = 6.9cm,
  legend pos= north east]
\addplot [black] coordinates{(x1, 5) (x2, 4) (x3, 10)};
\end{axis}
\end{tikzpicture}
{\footnotesize $\bf Fig. 10.$  The results using gh algo}
\end{figure}



\begin{figure}
      \begin{tikzpicture}
    \begin{axis}[
    ybar,
      symbolic x coords={x1, x2, x3},
      xtick={x1, x2, x3},
    ytick={4, 7, 23},
      xticklabel style={rotate=-90},
    nodes near coords,
      ylabel={Accuracy (\%)},
    width = 6.9cm,
      legend pos= north east]
    \addplot [black] coordinates{(x1, 4) (x2, 7) (x3, 23)};
    \end{axis}
    \end{tikzpicture}
    {\footnotesize $\bf Fig. 10.$  The results using er algo}
    \end{figure}

When I am plotting these two figures like, I always get the second figure below the first figure. What I want is to plot side by side the two figures. How can I modify my code?

Any help will be very appreciated!

0

1 Answer 1

3

enter image description here

\documentclass{article}
\usepackage{pgfplots}
\usepackage{subcaption}
\pgfplotsset{compat=1.3} 
\usepackage[margin=1in]{geometry}
\captionsetup{compatibility=false}
\begin{document} 

\begin{figure}\small
\begin{minipage}[b]{.5\linewidth}
\centering
\begin{tikzpicture}
\begin{axis}[ybar, 
symbolic x coords={x1, x2, x3},
  xtick={x1, x2, x3},
ytick={5, 4, 10},
  xticklabel style={rotate=-90},
nodes near coords,
  ylabel={Accuracy (\%)},
width = 6.9cm,
  legend pos= north east]
\addplot [black] coordinates{(x1, 5) (x2, 4) (x3, 10)};
\end{axis}
\end{tikzpicture}
\subcaption{The results using gh algo}\label{fig:10a}
\end{minipage}%
%
\begin{minipage}[b]{.5\linewidth}
\centering
\begin{tikzpicture}
 \begin{axis}[ybar,
      symbolic x coords={x1, x2, x3},
      xtick={x1, x2, x3},
    ytick={4, 7, 23},
      xticklabel style={rotate=-90},
    nodes near coords,
      ylabel={Accuracy (\%)},
    width = 6.9cm,
      legend pos= north east]
    \addplot [black] coordinates{(x1, 4) (x2, 7) (x3, 23)};
  \end{axis}
\end{tikzpicture}
\subcaption{The results using er algo}\label{fig:10b}
\end{minipage}
\caption{Comparison of two alorithms}\label{fig:10}
\end{figure}

\end{document}

figure is a float environment, so you should use only one environment and put the two plots inside it. you don't need a footnote then , but, a caption for each plot and a caption for the whole figure. Using the subcaption package, this can be easy.

Actually, this question is similar and can help, but here, you need two plots in a single figure, so the subcaption package may be your choice.

Update

Since the llnc.cls has some incompatibilities with the caption package, one should add the option \captionsetup{compatibility=false} in the preamble. This was mentioned by the subcaption package author in an answer to this question.

9
  • Thank you for your answer! why I am getting error with the subcaption package ?
    – Christina
    Aug 15, 2015 at 20:43
  • @Christina Do you use other packages for captions? and what is the error message?
    – AboAmmar
    Aug 15, 2015 at 20:44
  • Package caption Warning: Unsupported document class (or package) detected, (caption) usage of the caption package is not recommended. See the caption package documentation for explanation. ) ! Package subcaption Error: This package can't be used in cooperation (subcaption) with the subfigure package.
    – Christina
    Aug 15, 2015 at 20:48
  • I am using these packages:\usepackage{amssymb} \setcounter{tocdepth}{3} \usepackage{graphicx} \usepackage{url} \usepackage{subfigure} \usepackage{calc} \usepackage{amssymb} \usepackage{amstext} \usepackage{amsmath} \usepackage{color} \usepackage{tikz} \usepackage{pgfplots} \usepackage{subcaption} \pgfplotsset{compat=1.3} \usepackage[margin=1in]{geometry}
    – Christina
    Aug 15, 2015 at 20:49
  • Furthermore I am using \documentclass[runningheads,a4paper]{llncs}
    – Christina
    Aug 15, 2015 at 20:54

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