TeXworkshow to format better when we have tables

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

how to format better when we have tables

Post by yaozhao »

Code: Select all

\subsection{Q11}
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?

\begin{table} 
\centering 
\caption{Q11} 
\scalebox{0.7}{
{
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{tabular}{l*{1}{cc}}
\hline\hline
            &\multicolumn{2}{c}{q11}  \\
            &           b&         pct\\
\hline
Correct Answer&         604&    72\\
Wrong Answer&          115&    14\\
Don't know&	122&	 	14\\
Total       &         841&         100\\
\hline
\(N\)       &         841&            \\
\hline\hline
\end{tabular}
}
}
\label{T2} 
\end{table}

\subsection{Q12}
If interest rates rise, what will typically happen to bond prices?

\begin{table} 
\centering 
\caption{Q12} 
\scalebox{0.7}{
{
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{tabular}{l*{1}{cc}}
\hline\hline
            &\multicolumn{2}{c}{q12}  \\
            &           b&         pct\\
\hline
Correct Answer&         220&    26\\
Wrong Answer&          316&    38\\
Don't know&	305&	 	36\\
Total       &         841&         100\\
\hline
\(N\)       &         841&            \\
\hline\hline
\end{tabular}
}
}
\label{T2} 
\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......

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
User avatar
Stefan Kottwitz
Site Admin
Posts: 10308
Joined: Mon Mar 10, 2008 9:44 pm

how to format better when we have tables

Post by Stefan Kottwitz »

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
LaTeX.org admin
Post Reply