1

I have 3 sub bar plots which placed vertically in line. But the 3rd one doesn´t show totally due to space limitation. Mico suggested me to use figure and subfigure environment. I have changed table subtable to figure subfigure. Now the problem is with \textwidth. I have already given a number to it, but TexMaker still tell me missing number, and it´s illegal unit of measure..

error msg: ! Missing number, treated as zero. } l.16 \begin{subfigure}{0.9\textwidth} A number should have been here; I inserted 0'. (If you can't figure out why I needed to see a number, look upweird error' in the index to The TeXbook.) ! Illegal unit of measure (pt inserted).

My script is under, here I present only one bar plot in order to shorten the script :

\documentclass{article}
\usepackage{subfigure}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage{xcolor}
\usepackage{caption}
\usepackage{pgfplots}
\usepackage{tikz}
\definecolor{bblue}{HTML}{4F81BD}
\definecolor{rred}{HTML}{C0504D}
\definecolor{ggreen}{HTML}{9BBB59}
\definecolor{ppurple}{HTML}{9F4C7C}

\begin{document}
\begin{figure}
\begin{subfigure}{1\textwidth}
\centering
\begin{tikzpicture}
    \begin{axis}[
        width  = 1*\textwidth,
        height = 8cm,
        enlarge y limits={upper, value=0.2},
        ymin=0,
        major x tick style = transparent,
        ybar=2*\pgflinewidth,
        bar width=20pt,
        ymajorgrids = true,
        ylabel = {Percentage Error in X Direction \%},
        symbolic x coords={FH,UT,LT},
        xtick = data,
        nodes near coords,
        scaled y ticks = false,
        enlarge x limits=0.25,
        ymin=0,
        legend cell align=left,
        legend style={
                at={(1,1.05)},
                anchor=south east,
                column sep=1ex
        }
    ]
        \addplot[style={bblue,fill=bblue,mark=none]}]
            coordinates {(FH, 100) (UT,100) (LT,100)};

        \addplot[style={rred,fill=rred,mark=none}]
             coordinates {(FH, 89) (UT,170) (LT,173)};
        \legend{M,V}
    \end{axis}
\end{tikzpicture}
\caption{In longitudinal Direction}
\end{subfigure}
\end{figure}
\end{document}

Thank you in advance!

1
  • I indeed recommended you use figure and subfigure environments. Just for the record: I did not recommend that you load the subfigure package...
    – Mico
    Commented Nov 22, 2016 at 15:48

1 Answer 1

3

Don't load the subfigure package -- it's deprecated. Instead, load the subcaption package. It's the same package as you loaded in your earlier query, which was about subtable environments.

Since the bar charts are sufficiently large so that all three can't fit on a page, I suggest you use the \ContinuedFloat macro (provided by the caption package). Place the first two subfigure environments in a figure on one page, and place one more subfigure, along with a \ContinuedFloat directive, in a second figure environment.

\documentclass{article}
%%\usepackage{subfigure} % Don't load this package -- it's deprecated!
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage{xcolor}
\usepackage{caption,subcaption} % <-- load the "subcaption" package instead
\usepackage{pgfplots}
\usepackage{tikz}
\definecolor{bblue}{HTML}{4F81BD}
\definecolor{rred}{HTML}{C0504D}
\definecolor{ggreen}{HTML}{9BBB59}
\definecolor{ppurple}{HTML}{9F4C7C}

\begin{document}

\begin{figure}[p] % start of the first "figure" environment
\caption{Three bar charts}
\begin{subfigure}{1\textwidth}
\centering
\begin{tikzpicture}
    \begin{axis}[
        width  = 1*\textwidth,
        height = 8cm,
        enlarge y limits={upper, value=0.2},
        ymin=0,
        major x tick style = transparent,
        ybar=2*\pgflinewidth,
        bar width=20pt,
        ymajorgrids = true,
        ylabel = {Percentage Error in X Direction \%},
        symbolic x coords={FH,UT,LT},
        xtick = data,
        nodes near coords,
        scaled y ticks = false,
        enlarge x limits=0.25,
        ymin=0,
        legend cell align=left,
        legend style={
                at={(1,1.05)},
                anchor=south east,
                column sep=1ex
        }
    ]
        \addplot[style={bblue,fill=bblue,mark=none]}]
            coordinates {(FH, 100) (UT,100) (LT,100)};

        \addplot[style={rred,fill=rred,mark=none}]
             coordinates {(FH, 89) (UT,170) (LT,173)};
        \legend{M,V}
    \end{axis}
\end{tikzpicture}
\caption{First}
\end{subfigure}

\begin{subfigure}{1\textwidth}
\centering
\begin{tikzpicture}
    \begin{axis}[
        width  = 1*\textwidth,
        height = 8cm,
        enlarge y limits={upper, value=0.2},
        ymin=0,
        major x tick style = transparent,
        ybar=2*\pgflinewidth,
        bar width=20pt,
        ymajorgrids = true,
        ylabel = {Percentage Error in X Direction \%},
        symbolic x coords={FH,UT,LT},
        xtick = data,
        nodes near coords,
        scaled y ticks = false,
        enlarge x limits=0.25,
        ymin=0,
        legend cell align=left,
        legend style={
                at={(1,1.05)},
                anchor=south east,
                column sep=1ex
        }
    ]
        \addplot[style={bblue,fill=bblue,mark=none]}]
            coordinates {(FH, 100) (UT,100) (LT,100)};

        \addplot[style={rred,fill=rred,mark=none}]
             coordinates {(FH, 89) (UT,170) (LT,173)};
        \legend{M,V}
    \end{axis}
\end{tikzpicture}
\caption{Second}
\end{subfigure}
\end{figure} % End of the first "figure" environment

\begin{figure}[t!] % Start of the second "figure" environment
\ContinuedFloat % to ensure that the next subfigure is labelled "(c)", not "(a)"
\begin{subfigure}{1\textwidth}
\centering
\begin{tikzpicture}
    \begin{axis}[
        width  = 1*\textwidth,
        height = 8cm,
        enlarge y limits={upper, value=0.2},
        ymin=0,
        major x tick style = transparent,
        ybar=2*\pgflinewidth,
        bar width=20pt,
        ymajorgrids = true,
        ylabel = {Percentage Error in X Direction \%},
        symbolic x coords={FH,UT,LT},
        xtick = data,
        nodes near coords,
        scaled y ticks = false,
        enlarge x limits=0.25,
        ymin=0,
        legend cell align=left,
        legend style={
                at={(1,1.05)},
                anchor=south east,
                column sep=1ex
        }
    ]
        \addplot[style={bblue,fill=bblue,mark=none]}]
            coordinates {(FH, 100) (UT,100) (LT,100)};

        \addplot[style={rred,fill=rred,mark=none}]
             coordinates {(FH, 89) (UT,170) (LT,173)};
        \legend{M,V}
    \end{axis}
\end{tikzpicture}
\caption{Third}
\end{subfigure}
\end{figure} % End of the second "figure" environment

\end{document} 
0

You must log in to answer this question.

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