LaTeX forum ⇒ TeXworkshow to format better when we have tables

Information and discussion about TeXworks, an integrated LaTeX environment for several platforms
yaozhao
Posts: 27
Joined: Sat Oct 27, 2018 10:38 pm

how to format better when we have tables

Postby yaozhao » Fri Nov 09, 2018 5:44 am

  1. \subsection{Q11}
  2. Imagine that the interest rate on your savings account was 1\% per year and inflation was 2\%per year. After 1 year, how much would you be able to buy with the money in this account?
  3.  
  4. \begin{table}
  5. \centering
  6. \caption{Q11}
  7. \scalebox{0.7}{
  8. {
  9. \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
  10. \begin{tabular}{l*{1}{cc}}
  11. \hline\hline
  12. &\multicolumn{2}{c}{q11} \\
  13. & b& pct\\
  14. \hline
  15. Correct Answer& 604& 72\\
  16. Wrong Answer& 115& 14\\
  17. Don't know& 122& 14\\
  18. Total & 841& 100\\
  19. \hline
  20. \(N\) & 841& \\
  21. \hline\hline
  22. \end{tabular}
  23. }
  24. }
  25. \label{T2}
  26. \end{table}
  27.  
  28. \subsection{Q12}
  29. If interest rates rise, what will typically happen to bond prices?
  30.  
  31. \begin{table}
  32. \centering
  33. \caption{Q12}
  34. \scalebox{0.7}{
  35. {
  36. \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
  37. \begin{tabular}{l*{1}{cc}}
  38. \hline\hline
  39. &\multicolumn{2}{c}{q12} \\
  40. & b& pct\\
  41. \hline
  42. Correct Answer& 220& 26\\
  43. Wrong Answer& 316& 38\\
  44. Don't know& 305& 36\\
  45. Total & 841& 100\\
  46. \hline
  47. \(N\) & 841& \\
  48. \hline\hline
  49. \end{tabular}
  50. }
  51. }
  52. \label{T2}
  53. \end{table}


I want to each table below its corresponding section. In other words, each subsection has one table below. Then a new subsection, its table, a new subsection, its table......

User avatar
Stefan Kottwitz
Site Admin
Posts: 9203
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Sat Nov 10, 2018 1:38 am

You can load the placeins package:

\usepackage{placeins}

Then, use the command \FloatBarrier before a subsection so no table can float beyond the next subsection heading.

If you really want to fix table positions, then, instead of above, add

\usepackage{float}

and use the [H] option, such as

\begin{table}[H]

Stefan
Site admin


Return to “TeXworks”

Who is online

Users browsing this forum: No registered users and 2 guests