3

How do I modify the code to have the chart immediately below the table on the same page? Also, I want to make sure that the chart appears in section 1 only...in some other "runs" I made, the chart got "sent" to section 2 (instead of remaining in section 1)

\documentclass[11,fleqn]{article}
\usepackage{verbatim}
\usepackage{caption}
\usepackage{amsmath}
\usepackage{amstext}
\usepackage{mathtools}
\usepackage{hyperref,parskip}
\usepackage{booktabs,multicol,multirow,tabularx}
\usepackage{longtable}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\title{TEST}

\begin{document}
\noindent
\maketitle    

\section{Introduction}    
% Table generated by Excel2LaTeX from sheet 'latek'
\begin{table}[htbp]
  \centering
  \caption{Table1}
    \begin{tabular} {ccccccccccc}
    \multicolumn{1}{c}{hour} & P\_c  & P\_f  & Q\_h  & P\_h  & L\_h  & test1 & test2  & test3 & test4 & \multicolumn{1}{c}{test6} \\
    \multicolumn{1}{c}{0} & 1     & 2     & 3     & 4     & 5     & 6     & 7     & 8     & 9     & \multicolumn{1}{c}{10} \\
    \midrule
    1     &  \$ 120  &  \$ 100  & 100   &  \$   10  & 10    &  \$   1,200  &  \$      100  &  \$    1,100  &  \$   (9,000) &  \$   (7,900) \\
    2     &  \$ 120  &  \$ 100  & 100   &  \$   20  & 20    &  \$   2,400  &  \$      400  &  \$    2,000  &  \$   (8,000) &  \$   (6,000) \\
    3     &  \$ 120  &  \$ 100  & 100   &  \$   30  & 30    &  \$   3,600  &  \$      900  &  \$    2,700  &  \$   (7,000) &  \$   (4,300) \\
    4     &  \$ 120  &  \$ 100  & 100   &  \$   40  & 40    &  \$   4,800  &  \$   1,600  &  \$    3,200  &  \$   (6,000) &  \$   (2,800) \\
    5     &  \$ 120  &  \$ 100  & 100   &  \$   50  & 50    &  \$   6,000  &  \$   2,500  &  \$    3,500  &  \$   (5,000) &  \$   (1,500) \\
    6     &  \$ 120  &  \$ 100  & 100   &  \$   60  & 60    &  \$   7,200  &  \$   3,600  &  \$    3,600  &  \$   (4,000) &  \$      (400) \\
    7     &  \$ 120  &  \$ 100  & 100   &  \$   70  & 70    &  \$   8,400  &  \$   4,900  &  \$    3,500  &  \$   (3,000) &  \$       500  \\
    8     &  \$ 120  &  \$ 100  & 100   &  \$   80  & 80    &  \$   9,600  &  \$   6,400  &  \$    3,200  &  \$   (2,000) &  \$    1,200  \\
    9     &  \$ 120  &  \$ 100  & 100   &  \$   90  & 90    &  \$ 10,800  &  \$   8,100  &  \$    2,700  &  \$   (1,000) &  \$    1,700  \\
    10    &  \$ 120  &  \$ 100  & 100   &  \$ 100  & 100   &  \$ 12,000  &  \$ 10,000  &  \$    2,000  &  \$          -    &  \$    2,000  \\
    11    &  \$ 120  &  \$ 100  & 100   &  \$ 110  & 110   &  \$ 13,200  &  \$ 12,100  &  \$    1,100  &  \$     1,000  &  \$    2,100  \\
    12    &  \$ 120  &  \$ 100  & 100   &  \$ 120  & 120   &  \$ 14,400  &  \$ 14,400  &  \$          -    &  \$     2,000  &  \$    2,000  \\
    13    &  \$ 120  &  \$ 100  & 100   &  \$ 130  & 130   &  \$ 15,600  &  \$ 16,900  &  \$   (1,300) &  \$     3,000  &  \$    1,700  \\
    14    &  \$ 120  &  \$ 100  & 100   &  \$ 140  & 140   &  \$ 16,800  &  \$ 19,600  &  \$   (2,800) &  \$     4,000  &  \$    1,200  \\
    15    &  \$ 120  &  \$ 100  & 100   &  \$ 150  & 150   &  \$ 18,000  &  \$ 22,500  &  \$   (4,500) &  \$     5,000  &  \$       500  \\
    16    &  \$ 120  &  \$ 100  & 100   &  \$ 160  & 160   &  \$ 19,200  &  \$ 25,600  &  \$   (6,400) &  \$     6,000  &  \$      (400) \\
    17    &  \$ 120  &  \$ 100  & 100   &  \$ 170  & 170   &  \$ 20,400  &  \$ 28,900  &  \$   (8,500) &  \$     7,000  &  \$   (1,500) \\
    18    &  \$ 120  &  \$ 100  & 100   &  \$ 180  & 180   &  \$ 21,600  &  \$ 32,400  &  \$ (10,800) &  \$     8,000  &  \$   (2,800) \\
    19    &  \$ 120  &  \$ 100  & 100   &  \$ 190  & 190   &  \$ 22,800  &  \$ 36,100  &  \$ (13,300) &  \$     9,000  &  \$   (4,300) \\
    20    &  \$ 120  &  \$ 100  & 100   &  \$ 200  & 200   &  \$ 24,000  &  \$ 40,000  &  \$ (16,000) &  \$   10,000  &  \$   (6,000) \\
    21    &  \$ 120  &  \$ 100  & 100   &  \$ 210  & 210   &  \$ 25,200  &  \$ 44,100  &  \$ (18,900) &  \$   11,000  &  \$   (7,900) \\
    22    &  \$ 120  &  \$ 100  & 100   &  \$ 220  & 220   &  \$ 26,400  &  \$ 48,400  &  \$ (22,000) &  \$   12,000  &  \$ (10,000) \\
    23    &  \$ 120  &  \$ 100  & 100   &  \$ 230  & 230   &  \$ 27,600  &  \$ 52,900  &  \$ (25,300) &  \$   13,000  &  \$ (12,300) \\
    24    &  \$ 120  &  \$ 100  & 100   &  \$ 240  & 240   &  \$ 28,800  &  \$ 57,600  &  \$ (28,800) &  \$   14,000  &  \$ (14,800) \\
\cmidrule{2-11}    \end{tabular}%
  \label{tab:addlabel}%
\end{table}%

\begin{figure}
\centering  
\caption{test}
\pgfplotstableread{
hour    test test   test
1   1100    -9000   -7900
2   2000    -8000   -6000
3   2700    -7000   -4300
4   3200    -6000   -2800
5   3500    -5000   -1500
6   3600    -4000   -400
7   3500    -3000   500
8   3200    -2000   1200
9   2700    -1000   1700
10  2000    0   2000
11  1100    1000    2100
12  0   2000    2000
13  -1300   3000    1700
14  -2800   4000    1200
15  -4500   5000    500
16  -6400   6000    -400
17  -8500   7000    -1500
18  -10800  8000    -2800
19  -13300  9000    -4300
20  -16000  10000   -6000
21  -18900  11000   -7900
22  -22000  12000   -10000
23  -25300  13000   -12300
24  -28800  14000   -14800
}\mytable

\begin{tikzpicture} [scale=0.75]
\begin{axis}
[
axis lines=middle,
scaled ticks=false,
xlabel=hour,
yticklabel={{\$\pgfmathprintnumber{\tick}}}
]
\addplot table [x index=0, y index=1,mark=none]{\mytable} node[right,pos=0.50] (endofplotsquare) {test};
\addplot table [x index=0, y index=2,mark=none]{\mytable} node[above,pos=0.75] at (endofplotsquare){test};
\addplot table [x index=0, y index=3,mark=none,color=green]{\mytable} node[above,pos=0.75] at (endofplotsquare){test};
\end{axis}
\end{tikzpicture}
\end{figure}  
\end{document}
1

1 Answer 1

1

It is just feasible to make the two floats fit on one page if nothing else -- in particular, no paper title and no sectioning commands -- is on the page.

You should also strive to reduce the width of the tabular material. E.g., get rid of those 192 \$ directives and reduce the value of \tabcolsep by 25% (from 6pt to 4.5pt).

enter image description here

\documentclass[11,fleqn]{article}
\usepackage[skip=0.5\baselineskip]{caption}
\usepackage{booktabs}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}

\begin{table}[t!]
\setlength\tabcolsep{4.5pt}
  \centering
  \caption{Table1} \label{tab:addlabel}
    \begin{tabular} {@{} *{11}{r} @{}}
    \toprule
    hour & P\_c  & P\_f  & Q\_h  & P\_h  & L\_h  & test1 & test2  & test3 & test4 & test6 \\
    0 & 1     & 2     & 3     & 4     & 5     & 6     & 7     & 8     & 9     & 10 \\
    \midrule
    1     &   120  &   100  & 100   &     10  & 10    &     1,200  &        100  &      1,100  &     (9,000) &     (7,900) \\
    2     &   120  &   100  & 100   &     20  & 20    &     2,400  &        400  &      2,000  &     (8,000) &     (6,000) \\
    3     &   120  &   100  & 100   &     30  & 30    &     3,600  &        900  &      2,700  &     (7,000) &     (4,300) \\
    4     &   120  &   100  & 100   &     40  & 40    &     4,800  &     1,600  &      3,200  &     (6,000) &     (2,800) \\
    5     &   120  &   100  & 100   &     50  & 50    &     6,000  &     2,500  &      3,500  &     (5,000) &     (1,500) \\
    6     &   120  &   100  & 100   &     60  & 60    &     7,200  &     3,600  &      3,600  &     (4,000) &        (400) \\
    7     &   120  &   100  & 100   &     70  & 70    &     8,400  &     4,900  &      3,500  &     (3,000) &         500  \\
    8     &   120  &   100  & 100   &     80  & 80    &     9,600  &     6,400  &      3,200  &     (2,000) &      1,200  \\
    9     &   120  &   100  & 100   &     90  & 90    &   10,800  &     8,100  &      2,700  &     (1,000) &      1,700  \\
    10    &   120  &   100  & 100   &   100  & 100   &   12,000  &   10,000  &      2,000  &            -    &      2,000  \\
    11    &   120  &   100  & 100   &   110  & 110   &   13,200  &   12,100  &      1,100  &       1,000  &      2,100  \\
    12    &   120  &   100  & 100   &   120  & 120   &   14,400  &   14,400  &            -    &       2,000  &      2,000  \\
    13    &   120  &   100  & 100   &   130  & 130   &   15,600  &   16,900  &     (1,300) &       3,000  &      1,700  \\
    14    &   120  &   100  & 100   &   140  & 140   &   16,800  &   19,600  &     (2,800) &       4,000  &      1,200  \\
    15    &   120  &   100  & 100   &   150  & 150   &   18,000  &   22,500  &     (4,500) &       5,000  &         500  \\
    16    &   120  &   100  & 100   &   160  & 160   &   19,200  &   25,600  &     (6,400) &       6,000  &        (400) \\
    17    &   120  &   100  & 100   &   170  & 170   &   20,400  &   28,900  &     (8,500) &       7,000  &     (1,500) \\
    18    &   120  &   100  & 100   &   180  & 180   &   21,600  &   32,400  &   (10,800) &       8,000  &     (2,800) \\
    19    &   120  &   100  & 100   &   190  & 190   &   22,800  &   36,100  &   (13,300) &       9,000  &     (4,300) \\
    20    &   120  &   100  & 100   &   200  & 200   &   24,000  &   40,000  &   (16,000) &     10,000  &     (6,000) \\
    21    &   120  &   100  & 100   &   210  & 210   &   25,200  &   44,100  &   (18,900) &     11,000  &     (7,900) \\
    22    &   120  &   100  & 100   &   220  & 220   &   26,400  &   48,400  &   (22,000) &     12,000  &   (10,000) \\
    23    &   120  &   100  & 100   &   230  & 230   &   27,600  &   52,900  &   (25,300) &     13,000  &   (12,300) \\
    24    &   120  &   100  & 100   &   240  & 240   &   28,800  &   57,600  &   (28,800) &     14,000  &   (14,800) \\
\bottomrule    
\end{tabular}
\end{table}

\begin{figure}[h!]
\centering  
\caption{test}
\pgfplotstableread{
hour    test test   test
1   1100    -9000   -7900
2   2000    -8000   -6000
3   2700    -7000   -4300
4   3200    -6000   -2800
5   3500    -5000   -1500
6   3600    -4000   -400
7   3500    -3000   500
8   3200    -2000   1200
9   2700    -1000   1700
10  2000    0   2000
11  1100    1000    2100
12  0   2000    2000
13  -1300   3000    1700
14  -2800   4000    1200
15  -4500   5000    500
16  -6400   6000    -400
17  -8500   7000    -1500
18  -10800  8000    -2800
19  -13300  9000    -4300
20  -16000  10000   -6000
21  -18900  11000   -7900
22  -22000  12000   -10000
23  -25300  13000   -12300
24  -28800  14000   -14800
}\mytable

\begin{tikzpicture} [scale=0.75]
\begin{axis}
[
axis lines=middle,
scaled ticks=false,
xlabel=hour,
yticklabel={{\$\pgfmathprintnumber{\tick}}}
]
\addplot table [x index=0, y index=1,mark=none]{\mytable} node[right,pos=0.50] (endofplotsquare) {test};
\addplot table [x index=0, y index=2,mark=none]{\mytable} node[above,pos=0.75] at (endofplotsquare){test};
\addplot table [x index=0, y index=3,mark=none,color=green]{\mytable} node[above,pos=0.75] at (endofplotsquare){test};
\end{axis}
\end{tikzpicture}
\end{figure}  

\end{document}
1
  • Thanks! The table is working better...but the chart is now going two pages above! I do have about 9 pages before the table and the chart...not sure why the chart isn't staying on the same page. This was definitely helpful though. If you have ideas about the chart acting strange, please do share. The code for the chart is exactly the same. When I use [h!]...it takes the chart to the first page...weird!!
    – Chet
    Nov 26, 2016 at 23:28

You must log in to answer this question.

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