1

I am new on LaTeX and Overleaf, and trying to place bar charts side by side with the following code.

\documentclass{article}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,arrows}
\usepackage{pgfplots}
\usepackage[colorinlistoftodos,prependcaption,textsize=tiny
\begin{document}




\begin{figure}[!h]

\begin{centering}
%\begin{adjustwidth}{-1.5cm}{}
\begin{tikzpicture}  
\begin{axis}[
    %tiny,
    xbar, 
    width=5.6cm, height=7.0cm, 
    enlarge y limits=0.01,
    enlargelimits=0.07,  
    xlabel={(a)},
    symbolic y coords={F, E, D, C, B, A },
    ytick=data,
    nodes near coords, nodes near coords align={horizontal},
    %every node near coord/.append style={font=\tiny},
]
    \addplot coordinates {(35,A) (24,B) (23,C) (21,D) (19,E) (17,F)};
\end{axis}

\begin{axis}[
    %tiny,
    xbar, 
    width=5.6cm, height=7.0cm, 
    enlarge y limits=0.01,
    enlargelimits=0.07,  
    xlabel={(b)},
    symbolic y coords={A1, A2, A3, A4, A5, A6},
    ytick=data,
    nodes near coords, nodes near coords align={horizontal},
    %every node near coord/.append style={font=\tiny},
]
    \addplot coordinates {(63,A6) (53,A5) (16,A4) (14,A3) (9,A2) (8,A1)};
\end{axis}
\end{tikzpicture}  
\caption{An overview on of side by side bar charts}
%\end{adjustwidth}
\label{fig}
\end{centering}
\end{figure}

\end{document} 
  • Are the xlabels suposed to be subfigure numbers? If so, I would recommens using either the subfig or subcaption package in order to get automatic subfigure numbering. Why not place the two bar charts into two separate tikzpicture environments? – leandriis Jun 20 at 19:56
  • Thanks for your suggestion! but charts are still not side by side , its in top and down position now. – Waseem Jun 20 at 20:39
  • Is there an empty line between \end{tikzpicture} and \begin{tikzpicture}? If so, remove it. Also, did you decide to incorporate the subfig or subcaption package? – leandriis Jun 20 at 20:42
  • Thanks alot, problem is solved, I used with and without subfig or subcaption packages. and its work now . – Waseem Jun 20 at 21:10
0

I guess that you looking for something like this:

enter image description here

(red lines indicate page layout)

Unfortunately your question as well answer are not entirely clear and erroneous (misses are packages, closing braces, ...). Consequently the most of code in my MWE is written from scratch. See, if can help you:

\documentclass{article}
\usepackage[demo]{graphicx} 
\usepackage[strict]{changepage}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}

\usepackage{subcaption}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%


\begin{document}
    \begin{figure}[!ht]
    \centering
\pgfplotsset{
    width=5.6cm, height=7.0cm,
    xbar,
    enlarge y limits=0.1,
    enlarge x limits={0.3,upper},
    ytick=data,
    nodes near coords, nodes near coords align={horizontal},
    %every node near coord/.append style={font=\tiny},
            }
\begin{tikzpicture}
    \begin{axis}[
xlabel={(a)},
symbolic y coords={A, B, C, D, E, F},
                ]
\addplot coordinates {(35,A) (24,B) (23,C) (21,D) (19,E) (17,F)};
    \end{axis}
\end{tikzpicture}
    \hfil
\begin{tikzpicture}
    \begin{axis}[    
xlabel={(b)},
symbolic y coords={A1, A2, A3, A4, A5, A6},
                ]
\addplot coordinates {(63,A6) (53,A5) (16,A4) (14,A3) (9,A2) (8,A1)};
    \end{axis}
\end{tikzpicture}
    \caption{An overview on of side by side bar charts}
\label{fig}
    \end{figure}

    \begin{figure}[!ht]
\pgfplotsset{
    width=5.6cm, height=7.0cm,
    xbar,
    enlarge y limits=0.1,
    enlarge x limits={0.3,upper},
    ytick=data,
    nodes near coords, nodes near coords align={horizontal},
        xbar,
    enlarge y limits=0.1,
    enlarge x limits={0.3,upper},
    ytick=data,
    nodes near coords, nodes near coords align={horizontal},
            }
\begin{adjustwidth}{}{-\dimexpr\marginparwidth+\marginparsep}
    \begin{subfigure}{0.35\linewidth}
\begin{tikzpicture}
    \begin{axis}[
xlabel={(a)},
symbolic y coords={F, E, D, C, B, A },
                ]
\addplot coordinates {(35,A) (24,B) (23,C) (21,D) (19,E) (17,F)};
    \end{axis}
\end{tikzpicture}
    \caption{SubCaption1}
    \label{fig:subim1}
\end{subfigure}
    \hfill
\begin{subfigure}{0.28\linewidth}
\includegraphics[width=\linewidth, height=5.6cm]{mesh}
\vspace{\baselineskip}
    \caption{SubCaption2}
    \label{fig:subim2}
\end{subfigure}
    \hfill
\begin{subfigure}{0.35\linewidth}
\begin{tikzpicture}
    \begin{axis}[
xlabel={(b)},
symbolic y coords={A1, A2, A3, A4, A5, A6},
                ]
\addplot coordinates {(63,A6) (53,A5) (16,A4) (14,A3) (9,A2) (8,A1)};
    \end{axis}
\end{tikzpicture}
    \caption{SubCaption3}
    \label{fig:subim3}
\end{subfigure}
    \caption{Caption for this figure with two images}
    \label{fig:image2}
\end{adjustwidth}
    \end{figure}
\end{document}
| improve this answer | |
0
\documentclass{article}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,arrows}
\usepackage{pgfplots}
\usepackage[colorinlistoftodos,prependcaption,textsize=tiny
\begin{document}




\begin{figure}[!h]

\begin{centering}
%\begin{adjustwidth}{-1.5cm}{}
\begin{tikzpicture}  
\begin{axis}[
    %tiny,
    xbar, 
    width=5.6cm, height=7.0cm, 
    enlarge y limits=0.01,
    enlargelimits=0.07,  
    xlabel={(a)},
    symbolic y coords={F, E, D, C, B, A },
    ytick=data,
    nodes near coords, nodes near coords align={horizontal},
    %every node near coord/.append style={font=\tiny},
]
    \addplot coordinates {(35,A) (24,B) (23,C) (21,D) (19,E) (17,F)};
\end{axis}
\end{tikzpicture}  
\begin{tikzpicture}
\begin{axis}[
    %tiny,
    xbar, 
    width=5.6cm, height=7.0cm, 
    enlarge y limits=0.01,
    enlargelimits=0.07,  
    xlabel={(b)},
    symbolic y coords={A1, A2, A3, A4, A5, A6},
    ytick=data,
    nodes near coords, nodes near coords align={horizontal},
    %every node near coord/.append style={font=\tiny},
]
    \addplot coordinates {(63,A6) (53,A5) (16,A4) (14,A3) (9,A2) (8,A1)};
\end{axis}
\end{tikzpicture}  
\caption{An overview on of side by side bar charts}
%\end{adjustwidth}
\label{fig}
\end{centering}
\end{figure}

\begin{figure}[h]
\begin{subfigure}
\begin{tikzpicture}  
\begin{axis}[
    %tiny,
    xbar, 
    width=5.6cm, height=7.0cm, 
    enlarge y limits=0.01,
    enlargelimits=0.07,  
    xlabel={(a)},
    symbolic y coords={F, E, D, C, B, A },
    ytick=data,
    nodes near coords, nodes near coords align={horizontal},
    %every node near coord/.append style={font=\tiny},
]
\addplot coordinates {(35,A) (24,B) (23,C) (21,D) (19,E) (17,F)};
\end{axis}
\end{tikzpicture}   
%\caption{Caption1}
%\label{fig:subim1}
\end{subfigure}
\begin{subfigure}
\includegraphics[width=0.9\linewidth, height=5cm]{mesh}
\begin{tikzpicture}
\begin{axis}[
    %tiny,
    xbar, 
    width=5.6cm, height=7.0cm, 
    enlarge y limits=0.01,
    enlargelimits=0.07,  
    xlabel={(b)},
    symbolic y coords={A1, A2, A3, A4, A5, A6},
    ytick=data,
    nodes near coords, nodes near coords align={horizontal},
    %every node near coord/.append style={font=\tiny},
]
    \addplot coordinates {(63,A6) (53,A5) (16,A4) (14,A3) (9,A2) (8,A1)};
\end{axis}
\end{tikzpicture}  
%\caption{Caption 2}
%\label{fig:subim2}
\end{subfigure}
\caption{Caption for this figure with two images}
\label{fig:image2}
\end{figure}
\end{document}
| improve this answer | |
  • This code does not compile without errors. – TobiBS Jul 26 at 19:56
  • And could you please write something to explain what you changed and why? This actually improves the answer beyond a wall of code. – TobiBS Jul 26 at 19:57

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.